summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-17 07:38:23 +0100
committerRory& <root@rory.gay>2025-12-17 07:38:23 +0100
commitbd231c4d9dc423ce7e9fa53cc432554803d3c293 (patch)
tree44ec9678ecbf57e0854dffdc03f19e0ac7f48f2e /src/api
parentPrettier 1 (diff)
downloadserver-ts-bd231c4d9dc423ce7e9fa53cc432554803d3c293.tar.xz
Prettier 2
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/permissions.ts2
-rw-r--r--src/api/routes/channels/#channel_id/pins.ts14
-rw-r--r--src/api/routes/channels/#channel_id/purge.ts33
-rw-r--r--src/api/routes/channels/#channel_id/webhooks.ts36
-rw-r--r--src/api/routes/channels/preload-messages.ts2
5 files changed, 15 insertions, 72 deletions
diff --git a/src/api/routes/channels/#channel_id/permissions.ts b/src/api/routes/channels/#channel_id/permissions.ts

index e0feb3f9..c80d9a12 100644 --- a/src/api/routes/channels/#channel_id/permissions.ts +++ b/src/api/routes/channels/#channel_id/permissions.ts
@@ -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) diff --git a/src/api/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts
index a5aecda7..4b62115f 100644 --- a/src/api/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts
@@ -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(); diff --git a/src/api/routes/channels/#channel_id/purge.ts b/src/api/routes/channels/#channel_id/purge.ts
index c8a2efab..9686bc20 100644 --- a/src/api/routes/channels/#channel_id/purge.ts +++ b/src/api/routes/channels/#channel_id/purge.ts
@@ -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); diff --git a/src/api/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index cddff713..106d8442 100644 --- a/src/api/routes/channels/#channel_id/webhooks.ts +++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -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); diff --git a/src/api/routes/channels/preload-messages.ts b/src/api/routes/channels/preload-messages.ts
index 47795703..cdfc58f0 100644 --- a/src/api/routes/channels/preload-messages.ts +++ b/src/api/routes/channels/preload-messages.ts
@@ -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(