mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-22 13:12:19 +00:00
Prettier 2
This commit is contained in:
1 parent
23ad44a440
commit
bd231c4d9d
44 files changed
+85
-190
No files matched your search
@@ -21,7 +21,7 @@ import { Request, Response, Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { ChannelPermissionOverwriteSchema, ChannelPermissionOverwrite, ChannelPermissionOverwriteType } from "@spacebar/schemas"
|
||||
import { ChannelPermissionOverwriteSchema, ChannelPermissionOverwrite, ChannelPermissionOverwriteType } from "@spacebar/schemas";
|
||||
const router: Router = Router({ mergeParams: true });
|
||||
|
||||
// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel)
|
||||
|
||||
@@ -17,16 +17,7 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import {
|
||||
ChannelPinsUpdateEvent,
|
||||
Config,
|
||||
DiscordApiErrors,
|
||||
emitEvent,
|
||||
Message,
|
||||
MessageCreateEvent,
|
||||
MessageUpdateEvent,
|
||||
User,
|
||||
} from "@spacebar/util";
|
||||
import { ChannelPinsUpdateEvent, Config, DiscordApiErrors, emitEvent, Message, MessageCreateEvent, MessageUpdateEvent, User } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
|
||||
@@ -62,8 +53,7 @@ router.put(
|
||||
});
|
||||
|
||||
const { maxPins } = Config.get().limits.channel;
|
||||
if (pinned_count >= maxPins)
|
||||
throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins);
|
||||
if (pinned_count >= maxPins) throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins);
|
||||
|
||||
message.pinned_at = new Date();
|
||||
|
||||
|
||||
@@ -17,14 +17,7 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import {
|
||||
Channel,
|
||||
Message,
|
||||
MessageDeleteBulkEvent,
|
||||
emitEvent,
|
||||
getPermission,
|
||||
getRights,
|
||||
} from "@spacebar/util";
|
||||
import { Channel, Message, MessageDeleteBulkEvent, emitEvent, getPermission, getRights } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { Between, FindManyOptions, FindOperator, Not } from "typeorm";
|
||||
@@ -56,17 +49,12 @@ router.post(
|
||||
where: { id: channel_id },
|
||||
});
|
||||
|
||||
if (!channel.guild_id)
|
||||
throw new HTTPError("Can't purge dm channels", 400);
|
||||
if (!channel.guild_id) throw new HTTPError("Can't purge dm channels", 400);
|
||||
isTextChannel(channel.type);
|
||||
|
||||
const rights = await getRights(req.user_id);
|
||||
if (!rights.has("MANAGE_MESSAGES")) {
|
||||
const permissions = await getPermission(
|
||||
req.user_id,
|
||||
channel.guild_id,
|
||||
channel_id,
|
||||
);
|
||||
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
permissions.hasThrow("MANAGE_MESSAGES");
|
||||
permissions.hasThrow("MANAGE_CHANNELS");
|
||||
}
|
||||
@@ -83,21 +71,10 @@ router.post(
|
||||
where: {
|
||||
channel_id,
|
||||
id: Between(after, before), // the right way around
|
||||
author_id: rights.has("SELF_DELETE_MESSAGES")
|
||||
? undefined
|
||||
: Not(req.user_id),
|
||||
author_id: rights.has("SELF_DELETE_MESSAGES") ? undefined : Not(req.user_id),
|
||||
// if you lack the right of self-deletion, you can't delete your own messages, even in purges
|
||||
},
|
||||
relations: [
|
||||
"author",
|
||||
"webhook",
|
||||
"application",
|
||||
"mentions",
|
||||
"mention_roles",
|
||||
"mention_channels",
|
||||
"sticker_items",
|
||||
"attachments",
|
||||
],
|
||||
relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"],
|
||||
};
|
||||
|
||||
const messages = await Message.find(query);
|
||||
|
||||
@@ -17,16 +17,7 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import {
|
||||
Channel,
|
||||
Config,
|
||||
DiscordApiErrors,
|
||||
User,
|
||||
Webhook,
|
||||
handleFile,
|
||||
trimSpecial,
|
||||
ValidateName,
|
||||
} from "@spacebar/util";
|
||||
import { Channel, Config, DiscordApiErrors, User, Webhook, handleFile, trimSpecial, ValidateName } from "@spacebar/util";
|
||||
import crypto from "crypto";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
@@ -37,8 +28,7 @@ const router: Router = Router({ mergeParams: true });
|
||||
router.get(
|
||||
"/",
|
||||
route({
|
||||
description:
|
||||
"Returns a list of channel webhook objects. Requires the MANAGE_WEBHOOKS permission.",
|
||||
description: "Returns a list of channel webhook objects. Requires the MANAGE_WEBHOOKS permission.",
|
||||
permission: "MANAGE_WEBHOOKS",
|
||||
responses: {
|
||||
200: {
|
||||
@@ -50,27 +40,14 @@ router.get(
|
||||
const { channel_id } = req.params;
|
||||
const webhooks = await Webhook.find({
|
||||
where: { channel_id },
|
||||
relations: [
|
||||
"user",
|
||||
"channel",
|
||||
"source_channel",
|
||||
"guild",
|
||||
"source_guild",
|
||||
"application",
|
||||
],
|
||||
relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"],
|
||||
});
|
||||
|
||||
const instanceUrl =
|
||||
Config.get().api.endpointPublic || "http://localhost:3001";
|
||||
const instanceUrl = Config.get().api.endpointPublic || "http://localhost:3001";
|
||||
return res.json(
|
||||
webhooks.map((webhook) => ({
|
||||
...webhook,
|
||||
url:
|
||||
instanceUrl +
|
||||
"/webhooks/" +
|
||||
webhook.id +
|
||||
"/" +
|
||||
webhook.token,
|
||||
url: instanceUrl + "/webhooks/" + webhook.id + "/" + webhook.token,
|
||||
})),
|
||||
);
|
||||
},
|
||||
@@ -103,8 +80,7 @@ router.post(
|
||||
|
||||
const webhook_count = await Webhook.count({ where: { channel_id } });
|
||||
const { maxWebhooks } = Config.get().limits.channel;
|
||||
if (maxWebhooks && webhook_count > maxWebhooks)
|
||||
throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks);
|
||||
if (maxWebhooks && webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks);
|
||||
|
||||
let { avatar, name } = req.body as WebhookCreateSchema;
|
||||
name = trimSpecial(name);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import { route } from "@spacebar/api";
|
||||
import { Config, Message } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { PreloadMessagesRequestSchema, PreloadMessagesResponseSchema } from "@spacebar/schemas"
|
||||
import { PreloadMessagesRequestSchema, PreloadMessagesResponseSchema } from "@spacebar/schemas";
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
router.post(
|
||||
|
||||
Reference in new issue
Block a user