diff options
Diffstat (limited to 'api')
43 files changed, 108 insertions, 103 deletions
diff --git a/api/src/routes/auth/mfa/totp.ts b/api/src/routes/auth/mfa/totp.ts index cec6e5ee..255cf889 100644 --- a/api/src/routes/auth/mfa/totp.ts +++ b/api/src/routes/auth/mfa/totp.ts @@ -26,7 +26,7 @@ router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Respon ], }); - const backup = await BackupCode.findOne({ code: code, expired: false, consumed: false, user: { id: user.id }}); + const backup = await BackupCode.findOne({ where: { code: code, expired: false, consumed: false, user: { id: user.id } } }); if (!backup) { const ret = verifyToken(user.totp_secret!, code); diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts index 9816c5fd..2902c8dd 100644 --- a/api/src/routes/auth/register.ts +++ b/api/src/routes/auth/register.ts @@ -107,7 +107,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re } // check if there is already an account with this email - const exists = await User.findOne({ email: email }); + const exists = await User.findOne({ where: { email: email } }); if (exists) { throw FieldErrors({ diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts index f6f13017..a49081ef 100644 --- a/api/src/routes/channels/#channel_id/index.ts +++ b/api/src/routes/channels/#channel_id/index.ts @@ -18,7 +18,7 @@ const router: Router = Router(); router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); return res.send(channel); }); @@ -29,7 +29,7 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] }); if (channel.type === ChannelType.DM) { - const recipient = await Recipient.findOneOrFail({ where: { channel_id: channel_id, user_id: req.user_id } }); + const recipient = await Recipient.findOneOrFail({ where: { channel_id, user_id: req.user_id } }); recipient.closed = true; await Promise.all([ recipient.save(), @@ -77,7 +77,7 @@ router.patch("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANN const { channel_id } = req.params; if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); channel.assign(payload); await Promise.all([ diff --git a/api/src/routes/channels/#channel_id/invites.ts b/api/src/routes/channels/#channel_id/invites.ts index 788f7d6d..5fef136d 100644 --- a/api/src/routes/channels/#channel_id/invites.ts +++ b/api/src/routes/channels/#channel_id/invites.ts @@ -47,7 +47,7 @@ router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT }).save(); const data = invite.toJSON(); data.inviter = await User.getPublicUser(req.user_id); - data.guild = await Guild.findOne({ id: guild_id }); + data.guild = await Guild.findOne({ where: { id: guild_id } }); data.channel = channel; await emitEvent({ event: "INVITE_CREATE", data, guild_id } as InviteCreateEvent); @@ -57,7 +57,7 @@ router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT router.get("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { const { user_id } = req; const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) { throw new HTTPError("This channel doesn't exist", 404); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts b/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts index 885c5eca..c14addbe 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts @@ -19,8 +19,8 @@ router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Reques const permission = await getPermission(req.user_id, undefined, channel_id); permission.hasThrow("VIEW_CHANNEL"); - let read_state = await ReadState.findOne({ user_id: req.user_id, channel_id }); - if (!read_state) read_state = new ReadState({ user_id: req.user_id, channel_id }); + let read_state = await ReadState.findOne({ where: { user_id: req.user_id, channel_id } }); + if (!read_state) read_state = new ReadState({ where: { user_id: req.user_id, channel_id } }); read_state.last_message_id = message_id; await read_state.save(); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts index 0b228ed6..b3b310d3 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts @@ -169,8 +169,8 @@ router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: router.delete("/", route({}), async (req: Request, res: Response) => { const { message_id, channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); const rights = await getRights(req.user_id); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts b/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts index f56f18d3..d0ab35bb 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts @@ -39,7 +39,7 @@ function getEmoji(emoji: string): PartialEmoji { router.delete("/", route({ permission: "MANAGE_MESSAGES" }), async (req: Request, res: Response) => { const { message_id, channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); await Message.update({ id: message_id, channel_id }, { reactions: [] }); @@ -60,7 +60,7 @@ router.delete("/:emoji", route({ permission: "MANAGE_MESSAGES" }), async (req: R const { message_id, channel_id } = req.params; const emoji = getEmoji(req.params.emoji); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!already_added) throw new HTTPError("Reaction not found", 404); @@ -87,7 +87,7 @@ router.get("/:emoji", route({ permission: "VIEW_CHANNEL" }), async (req: Request const { message_id, channel_id } = req.params; const emoji = getEmoji(req.params.emoji); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const reaction = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!reaction) throw new HTTPError("Reaction not found", 404); @@ -106,14 +106,14 @@ router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right if (user_id !== "@me") throw new HTTPError("Invalid user"); const emoji = getEmoji(req.params.emoji); - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!already_added) req.permission!.hasThrow("ADD_REACTIONS"); if (emoji.id) { - const external_emoji = await Emoji.findOneOrFail({ id: emoji.id }); + const external_emoji = await Emoji.findOneOrFail({ where: { id: emoji.id } }); if (!already_added) req.permission!.hasThrow("USE_EXTERNAL_EMOJIS"); emoji.animated = external_emoji.animated; emoji.name = external_emoji.name; @@ -126,7 +126,7 @@ router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right await message.save(); - const member = channel.guild_id && (await Member.findOneOrFail({ id: req.user_id })); + const member = channel.guild_id && (await Member.findOneOrFail({ where: { id: req.user_id } })); await emitEvent({ event: "MESSAGE_REACTION_ADD", @@ -149,8 +149,8 @@ router.delete("/:emoji/:user_id", route({}), async (req: Request, res: Response) const emoji = getEmoji(req.params.emoji); - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); if (user_id === "@me") user_id = req.user_id; else { diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index f8e62d8c..2fce704b 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -85,7 +85,7 @@ export interface MessageCreateSchema { // get messages router.get("/", async (req: Request, res: Response) => { const channel_id = req.params.channel_id; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel) throw new HTTPError("Channel not found", 404); isTextChannel(channel.type); diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts index 798f7c8d..06a124bb 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/api/src/routes/channels/#channel_id/permissions.ts @@ -29,9 +29,9 @@ router.put( if (!channel.guild_id) throw new HTTPError("Channel not found", 404); if (body.type === 0) { - if (!(await Role.count({ id: overwrite_id }))) throw new HTTPError("role not found", 404); + if (!(await Role.count({ where: { id: overwrite_id } }))) throw new HTTPError("role not found", 404); } else if (body.type === 1) { - if (!(await Member.count({ id: overwrite_id }))) throw new HTTPError("user not found", 404); + if (!(await Member.count({ where: { id: overwrite_id } }))) throw new HTTPError("user not found", 404); } else throw new HTTPError("type not supported", 501); // @ts-ignore @@ -64,7 +64,7 @@ router.put( router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => { const { channel_id, overwrite_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) throw new HTTPError("Channel not found", 404); channel.permission_overwrites = channel.permission_overwrites!.filter((x) => x.id === overwrite_id); diff --git a/api/src/routes/channels/#channel_id/pins.ts b/api/src/routes/channels/#channel_id/pins.ts index 5c314f09..003638c5 100644 --- a/api/src/routes/channels/#channel_id/pins.ts +++ b/api/src/routes/channels/#channel_id/pins.ts @@ -17,12 +17,12 @@ const router: Router = Router(); router.put("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; - const message = await Message.findOneOrFail({ id: message_id }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); // * in dm channels anyone can pin messages -> only check for guilds if (message.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES"); - const pinned_count = await Message.count({ channel: { id: channel_id }, pinned: true }); + const pinned_count = await Message.count({ where: { channel: { id: channel_id }, pinned: true } }); const { maxPins } = Config.get().limits.channel; if (pinned_count >= maxPins) throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins); @@ -50,10 +50,10 @@ router.put("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Re router.delete("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (channel.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES"); - const message = await Message.findOneOrFail({ id: message_id }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); message.pinned = false; await Promise.all([ @@ -82,7 +82,7 @@ router.delete("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: router.get("/", route({ permission: ["READ_MESSAGE_HISTORY"] }), async (req: Request, res: Response) => { const { channel_id } = req.params; - let pins = await Message.find({ channel_id: channel_id, pinned: true }); + let pins = await Message.find({ where: { channel_id, pinned: true } }); res.send(pins); }); diff --git a/api/src/routes/channels/#channel_id/recipients.ts b/api/src/routes/channels/#channel_id/recipients.ts index e6466211..28d5607d 100644 --- a/api/src/routes/channels/#channel_id/recipients.ts +++ b/api/src/routes/channels/#channel_id/recipients.ts @@ -28,7 +28,7 @@ router.put("/:user_id", route({}), async (req: Request, res: Response) => { throw DiscordApiErrors.INVALID_RECIPIENT; //TODO is this the right error? } - channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id })); + channel.recipients!.push(new Recipient({ channel_id, user_id: user_id })); await channel.save(); await emitEvent({ diff --git a/api/src/routes/channels/#channel_id/typing.ts b/api/src/routes/channels/#channel_id/typing.ts index 56652368..99460f6e 100644 --- a/api/src/routes/channels/#channel_id/typing.ts +++ b/api/src/routes/channels/#channel_id/typing.ts @@ -8,7 +8,7 @@ router.post("/", route({ permission: "SEND_MESSAGES" }), async (req: Request, re const { channel_id } = req.params; const user_id = req.user_id; const timestamp = Date.now(); - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); const member = await Member.findOne({ where: { id: user_id, guild_id: channel.guild_id }, relations: ["roles", "user"] }); await emitEvent({ diff --git a/api/src/routes/channels/#channel_id/webhooks.ts b/api/src/routes/channels/#channel_id/webhooks.ts index 52f7ef7d..8f0e0a7f 100644 --- a/api/src/routes/channels/#channel_id/webhooks.ts +++ b/api/src/routes/channels/#channel_id/webhooks.ts @@ -22,12 +22,12 @@ router.get("/", route({}), async (req: Request, res: Response) => { // TODO: use Image Data Type for avatar instead of String router.post("/", route({ body: "WebhookCreateSchema", permission: "MANAGE_WEBHOOKS" }), async (req: Request, res: Response) => { const channel_id = req.params.channel_id; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); isTextChannel(channel.type); if (!channel.guild_id) throw new HTTPError("Not a guild channel", 400); - const webhook_count = await Webhook.count({ channel_id }); + const webhook_count = await Webhook.count({ where: { channel_id } }); const { maxWebhooks } = Config.get().limits.channel; if (webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks); diff --git a/api/src/routes/downloads.ts b/api/src/routes/downloads.ts index 03c73f44..44530353 100644 --- a/api/src/routes/downloads.ts +++ b/api/src/routes/downloads.ts @@ -12,7 +12,7 @@ router.get("/:branch", route({}), async (req: Request, res: Response) => { if(!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404) - const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion }); + const release = await Release.findOneOrFail({ where: { name: client.releases.upstreamVersion } }); res.redirect(release[`win_url`]); }); diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts index ee2c26f1..bd0140d6 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -17,7 +17,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) - : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || 24)) }); + : await Guild.find({ where: { features: Like('%DISCOVERABLE%') }, take: Math.abs(Number(limit || 24)) }); res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}`}).status(200); }); diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/api/src/routes/guilds/#guild_id/bans.ts index eb38de0d..128ff250 100644 --- a/api/src/routes/guilds/#guild_id/bans.ts +++ b/api/src/routes/guilds/#guild_id/bans.ts @@ -32,7 +32,7 @@ const router: Router = Router(); router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => { const { guild_id } = req.params; - let bans = await Ban.find({ guild_id: guild_id }); + let bans = await Ban.find({ where: { guild_id } }); let promisesToAwait: object[] = []; const bansObj: object[] = []; @@ -65,7 +65,7 @@ router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, const { guild_id } = req.params; const user_id = req.params.ban; - let ban = await Ban.findOneOrFail({ guild_id: guild_id, user_id: user_id }) as BanRegistrySchema; + let ban = await Ban.findOneOrFail({ where: { guild_id, user_id } }) as BanRegistrySchema; if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN; // pretend self-bans don't exist to prevent victim chasing @@ -149,7 +149,7 @@ router.put("/@me", route({ body: "BanCreateSchema"}), async (req: Request, res: router.delete("/:user_id", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => { const { guild_id, user_id } = req.params; - let ban = await Ban.findOneOrFail({ guild_id: guild_id, user_id: user_id }); + let ban = await Ban.findOneOrFail({ where: { guild_id, user_id } }); if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN; // make self-bans irreversible and hide them from view to avoid victim chasing diff --git a/api/src/routes/guilds/#guild_id/channels.ts b/api/src/routes/guilds/#guild_id/channels.ts index e3c6b8bd..b952b474 100644 --- a/api/src/routes/guilds/#guild_id/channels.ts +++ b/api/src/routes/guilds/#guild_id/channels.ts @@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const channels = await Channel.find({ guild_id }); + const channels = await Channel.find({ where: { guild_id } }); res.json(channels); }); @@ -48,7 +48,7 @@ router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHAN } await Channel.update({ guild_id, id: x.id }, opts); - const channel = await Channel.findOneOrFail({ guild_id, id: x.id }); + const channel = await Channel.findOneOrFail({ where: { guild_id, id: x.id } }); await emitEvent({ event: "CHANNEL_UPDATE", data: channel, channel_id: x.id, guild_id } as ChannelUpdateEvent); }) diff --git a/api/src/routes/guilds/#guild_id/emojis.ts b/api/src/routes/guilds/#guild_id/emojis.ts index 85d7ac05..c4bcadf7 100644 --- a/api/src/routes/guilds/#guild_id/emojis.ts +++ b/api/src/routes/guilds/#guild_id/emojis.ts @@ -41,13 +41,13 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A const body = req.body as EmojiCreateSchema; const id = Snowflake.generate(); - const emoji_count = await Emoji.count({ guild_id: guild_id }); + const emoji_count = await Emoji.count({ where: { guild_id } }); const { maxEmojis } = Config.get().limits.guild; if (emoji_count >= maxEmojis) throw DiscordApiErrors.MAXIMUM_NUMBER_OF_EMOJIS_REACHED.withParams(maxEmojis); if (body.require_colons == null) body.require_colons = true; - const user = await User.findOneOrFail({ id: req.user_id }); + const user = await User.findOneOrFail({ where: { id: req.user_id } }); body.image = (await handleFile(`/emojis/${id}`, body.image)) as string; const emoji = await new Emoji({ @@ -66,7 +66,7 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id } }) } } as GuildEmojisUpdateEvent); @@ -87,7 +87,7 @@ router.patch( guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id } }) } } as GuildEmojisUpdateEvent); @@ -108,7 +108,7 @@ router.delete("/:emoji_id", route({ permission: "MANAGE_EMOJIS_AND_STICKERS" }), guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id } }) } } as GuildEmojisUpdateEvent); diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts index d9c8f13b..2d748d61 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts @@ -26,8 +26,8 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; const [guild, member] = await Promise.all([ - Guild.findOneOrFail({ id: guild_id }), - Member.findOne({ guild_id: guild_id, id: req.user_id }) + Guild.findOneOrFail({ where: { id: guild_id } }), + Member.findOne({ where: { guild_id, id: req.user_id } }) ]); if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401); diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts index e4a060d6..2717ec2a 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts @@ -13,7 +13,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id, member_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const member = await Member.findOneOrFail({ id: member_id, guild_id }); + const member = await Member.findOneOrFail({ where: { id: member_id, guild_id } }); return res.json(member); }); @@ -25,7 +25,7 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] }); const permission = await getPermission(req.user_id, guild_id); - const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 }); + const everyone = await Role.findOneOrFail({ where: { guild_id: guild_id, name: "@everyone", position: 0 } }); if (body.roles) { permission.hasThrow("MANAGE_ROLES"); diff --git a/api/src/routes/guilds/#guild_id/prune.ts b/api/src/routes/guilds/#guild_id/prune.ts index efaad580..01f18ce4 100644 --- a/api/src/routes/guilds/#guild_id/prune.ts +++ b/api/src/routes/guilds/#guild_id/prune.ts @@ -33,7 +33,7 @@ export const inactiveMembers = async (guild_id: string, user_id: string, days: n //I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well. if (roles.length && members.length) members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id))); - const me = await Member.findOneOrFail({ id: user_id, guild_id }, { relations: ["roles"] }); + const me = await Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["roles"] }); const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || [])); const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); diff --git a/api/src/routes/guilds/#guild_id/regions.ts b/api/src/routes/guilds/#guild_id/regions.ts index 75d24fd1..308d5ee5 100644 --- a/api/src/routes/guilds/#guild_id/regions.ts +++ b/api/src/routes/guilds/#guild_id/regions.ts @@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); //TODO we should use an enum for guild's features and not hardcoded strings return res.json(await getVoiceRegions(getIpAdress(req), guild.features.includes("VIP_REGIONS"))); }); diff --git a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts b/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts index 7efc5382..af04fd06 100644 --- a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts +++ b/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts @@ -9,7 +9,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id, role_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const role = await Role.findOneOrFail({ guild_id, id: role_id }); + const role = await Role.findOneOrFail({ where: { guild_id, id: role_id } }); return res.json(role); }); diff --git a/api/src/routes/guilds/#guild_id/roles/index.ts b/api/src/routes/guilds/#guild_id/roles/index.ts index 2f5141b8..d2d14122 100644 --- a/api/src/routes/guilds/#guild_id/roles/index.ts +++ b/api/src/routes/guilds/#guild_id/roles/index.ts @@ -37,7 +37,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { await Member.IsInGuildOrFail(req.user_id, guild_id); - const roles = await Role.find({ guild_id: guild_id }); + const roles = await Role.find({ where: { guild_id } }); return res.json(roles); }); @@ -46,7 +46,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) const guild_id = req.params.guild_id; const body = req.body as RoleModifySchema; - const role_count = await Role.count({ guild_id }); + const role_count = await Role.count({ where: { guild_id } }); const { maxRoles } = Config.get().limits.guild; if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles); diff --git a/api/src/routes/guilds/#guild_id/stickers.ts b/api/src/routes/guilds/#guild_id/stickers.ts index bfc46291..7913539b 100644 --- a/api/src/routes/guilds/#guild_id/stickers.ts +++ b/api/src/routes/guilds/#guild_id/stickers.ts @@ -19,7 +19,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - res.json(await Sticker.find({ guild_id })); + res.json(await Sticker.find({ where: { guild_id } })); }); const bodyParser = multer({ @@ -79,7 +79,7 @@ router.get("/:sticker_id", route({}), async (req: Request, res: Response) => { const { guild_id, sticker_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - res.json(await Sticker.findOneOrFail({ guild_id, id: sticker_id })); + res.json(await Sticker.findOneOrFail({ where: { guild_id, id: sticker_id } })); }); export interface ModifyGuildStickerSchema { @@ -118,7 +118,7 @@ async function sendStickerUpdateEvent(guild_id: string) { guild_id: guild_id, data: { guild_id: guild_id, - stickers: await Sticker.find({ guild_id: guild_id }) + stickers: await Sticker.find({ where: { guild_id } }) } } as GuildStickersUpdateEvent); } diff --git a/api/src/routes/guilds/#guild_id/templates.ts b/api/src/routes/guilds/#guild_id/templates.ts index 7e411907..f2de46e4 100644 --- a/api/src/routes/guilds/#guild_id/templates.ts +++ b/api/src/routes/guilds/#guild_id/templates.ts @@ -44,7 +44,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { router.post("/", route({ body: "TemplateCreateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { const { guild_id } = req.params; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection }); - const exists = await Template.findOneOrFail({ id: guild_id }).catch((e) => {}); + const exists = await Template.findOneOrFail({ where: { id: guild_id } }).catch((e) => {}); if (exists) throw new HTTPError("Template already exists", 400); const template = await new Template({ diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/api/src/routes/guilds/#guild_id/vanity-url.ts index e841b8b3..b4d9f618 100644 --- a/api/src/routes/guilds/#guild_id/vanity-url.ts +++ b/api/src/routes/guilds/#guild_id/vanity-url.ts @@ -9,7 +9,7 @@ const InviteRegex = /\W/g; router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.features.includes("ALIASABLE_NAMES")) { const invite = await Invite.findOne({ where: { guild_id: guild_id, vanity_url: true } }); @@ -37,15 +37,15 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }) const body = req.body as VanityUrlSchema; const code = body.code?.replace(InviteRegex, ""); - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.features.includes("VANITY_URL")) throw new HTTPError("Your guild doesn't support vanity urls"); if (!code || code.length === 0) throw new HTTPError("Code cannot be null or empty"); - const invite = await Invite.findOne({ code }); + const invite = await Invite.findOne({ where: { code } }); if (invite) throw new HTTPError("Invite already exists"); - const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT }); + const { id } = await Channel.findOneOrFail({ where: { guild_id, type: ChannelType.GUILD_TEXT } }); await new Invite({ vanity_url: true, @@ -60,7 +60,7 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }) channel_id: id }).save(); - return res.json({ code: code }); + return res.json({ where: { code } }); }); export default router; diff --git a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts b/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts index 392b002f..37ea52b5 100644 --- a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts +++ b/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts @@ -34,14 +34,16 @@ router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request if (body.request_to_speak_timestamp) perms.hasThrow("REQUEST_TO_SPEAK"); const voice_state = await VoiceState.findOne({ - guild_id, - channel_id: body.channel_id, - user_id + where: { + guild_id, + channel_id: body.channel_id, + user_id + } }); if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE; voice_state.assign(body); - const channel = await Channel.findOneOrFail({ guild_id, id: body.channel_id }); + const channel = await Channel.findOneOrFail({ where: { guild_id, id: body.channel_id } }); if (channel.type !== ChannelType.GUILD_STAGE_VOICE) { throw DiscordApiErrors.CANNOT_EXECUTE_ON_THIS_CHANNEL_TYPE; } diff --git a/api/src/routes/guilds/#guild_id/welcome_screen.ts b/api/src/routes/guilds/#guild_id/welcome_screen.ts index ab125131..4093ec1d 100644 --- a/api/src/routes/guilds/#guild_id/welcome_screen.ts +++ b/api/src/routes/guilds/#guild_id/welcome_screen.ts @@ -19,7 +19,7 @@ export interface GuildUpdateWelcomeScreenSchema { router.get("/", route({}), async (req: Request, res: Response) => { const guild_id = req.params.guild_id; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); await Member.IsInGuildOrFail(req.user_id, guild_id); res.json(guild.welcome_screen); @@ -29,7 +29,7 @@ router.patch("/", route({ body: "GuildUpdateWelcomeScreenSchema", permission: "M const guild_id = req.params.guild_id; const body = req.body as GuildUpdateWelcomeScreenSchema; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.welcome_screen.enabled) throw new HTTPError("Welcome screen disabled", 400); if (body.welcome_channels) guild.welcome_screen.welcome_channels = body.welcome_channels; // TODO: check if they exist and are valid diff --git a/api/src/routes/guilds/#guild_id/widget.json.ts b/api/src/routes/guilds/#guild_id/widget.json.ts index 97f3c303..b7a93a46 100644 --- a/api/src/routes/guilds/#guild_id/widget.json.ts +++ b/api/src/routes/guilds/#guild_id/widget.json.ts @@ -17,7 +17,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.widget_enabled) throw new HTTPError("Widget Disabled", 404); // Fetch existing widget invite for widget channel @@ -63,7 +63,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { // Fetch members // TODO: Understand how Discord's max 100 random member sample works, and apply to here (see top of this file) - let members = await Member.find({ guild_id: guild_id }); + let members = await Member.find({ where: { guild_id } }); // Construct object to respond with const data = { diff --git a/api/src/routes/guilds/#guild_id/widget.png.ts b/api/src/routes/guilds/#guild_id/widget.png.ts index 4298d0fe..ec0ac85c 100644 --- a/api/src/routes/guilds/#guild_id/widget.png.ts +++ b/api/src/routes/guilds/#guild_id/widget.png.ts @@ -14,7 +14,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.widget_enabled) throw new HTTPError("Unknown Guild", 404); // Fetch guild information diff --git a/api/src/routes/guilds/#guild_id/widget.ts b/api/src/routes/guilds/#guild_id/widget.ts index 2640618d..103f84a3 100644 --- a/api/src/routes/guilds/#guild_id/widget.ts +++ b/api/src/routes/guilds/#guild_id/widget.ts @@ -13,7 +13,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); return res.json({ enabled: guild.widget_enabled || false, channel_id: guild.widget_channel_id || null }); }); diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index 10721413..64b9454b 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -24,7 +24,7 @@ router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), a const body = req.body as GuildCreateSchema; const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ id: req.user_id }); + const guild_count = await Member.count({ where: { id: req.user_id } }); const rights = await getRights(req.user_id); if ((guild_count >= maxGuilds)&&!rights.has("MANAGE_GUILDS")) { throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts index 3d922e85..e2242ebf 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/api/src/routes/guilds/templates/index.ts @@ -33,7 +33,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { return res.json(code.split("external:", 2)[1]); } - const template = await Template.findOneOrFail({ code: code }); + const template = await Template.findOneOrFail({ where: { code } }); res.json(template); }); @@ -47,12 +47,12 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ id: req.user_id }); + const guild_count = await Member.count({ where: { id: req.user_id } }); if (guild_count >= maxGuilds) { throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); } - const template = await Template.findOneOrFail({ code: code }); + const template = await Template.findOneOrFail({ where: { code } }); const guild_id = Snowflake.generate(); diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts index b0a34939..1b434505 100644 --- a/api/src/routes/invites/index.ts +++ b/api/src/routes/invites/index.ts @@ -15,9 +15,9 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { router.post("/:code", route({right: "USE_MASS_INVITES"}), async (req: Request, res: Response) => { const { code } = req.params; - const { guild_id } = await Invite.findOneOrFail({ code }) - const { features } = await Guild.findOneOrFail({ id: guild_id}); - const { public_flags } = await User.findOneOrFail({ id: req.user_id }); + const { guild_id } = await Invite.findOneOrFail({ where: { code } }) + const { features } = await Guild.findOneOrFail({ where: { id: guild_id} }); + const { public_flags } = await User.findOneOrFail({ where: { id: req.user_id } }); if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("Only intended for the staff of this server.", 401); if(features.includes("INVITES_CLOSED")) throw new HTTPError("Sorry, this guild has joins closed.", 403); @@ -30,7 +30,7 @@ router.post("/:code", route({right: "USE_MASS_INVITES"}), async (req: Request, r // * cant use permission of route() function because path doesn't have guild_id/channel_id router.delete("/:code", route({}), async (req: Request, res: Response) => { const { code } = req.params; - const invite = await Invite.findOneOrFail({ code }); + const invite = await Invite.findOneOrFail({ where: { code } }); const { guild_id, channel_id } = invite; const permission = await getPermission(req.user_id, guild_id, channel_id); diff --git a/api/src/routes/stickers/#sticker_id/index.ts b/api/src/routes/stickers/#sticker_id/index.ts index 293ca089..b484a7a1 100644 --- a/api/src/routes/stickers/#sticker_id/index.ts +++ b/api/src/routes/stickers/#sticker_id/index.ts @@ -6,7 +6,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { sticker_id } = req.params; - res.json(await Sticker.find({ id: sticker_id })); + res.json(await Sticker.find({ where: { id: sticker_id } })); }); export default router; diff --git a/api/src/routes/updates.ts b/api/src/routes/updates.ts index cb4577c8..a24e94c1 100644 --- a/api/src/routes/updates.ts +++ b/api/src/routes/updates.ts @@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { client } = Config.get(); - const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion}) + const release = await Release.findOneOrFail({ where: { name: client.releases.upstreamVersion } }) res.json({ name: release.name, diff --git a/api/src/routes/users/@me/mfa/codes.ts b/api/src/routes/users/@me/mfa/codes.ts index 6ddf32f0..75e3e964 100644 --- a/api/src/routes/users/@me/mfa/codes.ts +++ b/api/src/routes/users/@me/mfa/codes.ts @@ -15,7 +15,7 @@ export interface MfaCodesSchema { router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Response) => { const { password, regenerate } = req.body as MfaCodesSchema; - const user = await User.findOneOrFail({ id: req.user_id }, { select: ["data"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); if (!await bcrypt.compare(password, user.data.hash || "")) { throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } }); @@ -33,10 +33,12 @@ router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Re } else { codes = await BackupCode.find({ - user: { - id: req.user_id, - }, - expired: false, + where: { + user: { + id: req.user_id, + }, + expired: false + } }); } diff --git a/api/src/routes/users/@me/mfa/totp/disable.ts b/api/src/routes/users/@me/mfa/totp/disable.ts index 5e039ea3..2d385fda 100644 --- a/api/src/routes/users/@me/mfa/totp/disable.ts +++ b/api/src/routes/users/@me/mfa/totp/disable.ts @@ -13,9 +13,9 @@ export interface TotpDisableSchema { router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res: Response) => { const body = req.body as TotpDisableSchema; - const user = await User.findOneOrFail({ id: req.user_id }, { select: ["totp_secret"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["totp_secret"] }); - const backup = await BackupCode.findOne({ code: body.code }); + const backup = await BackupCode.findOne({ where: { code: body.code } }); if (!backup) { const ret = verifyToken(user.totp_secret!, body.code); if (!ret || ret.delta != 0) diff --git a/api/src/routes/users/@me/notes.ts b/api/src/routes/users/@me/notes.ts index 3c503942..f938f088 100644 --- a/api/src/routes/users/@me/notes.ts +++ b/api/src/routes/users/@me/notes.ts @@ -29,7 +29,7 @@ router.put("/:id", route({}), async (req: Request, res: Response) => { if (note && note.length) { // upsert a note - if (await Note.findOne({ owner: { id: owner.id }, target: { id: target.id } })) { + if (await Note.findOne({ where: { owner: { id: owner.id }, target: { id: target.id } } })) { Note.update( { owner: { id: owner.id }, target: { id: target.id } }, { owner, target, content: note } diff --git a/api/src/routes/users/@me/relationships.ts b/api/src/routes/users/@me/relationships.ts index b2e39d52..0509b0ac 100644 --- a/api/src/routes/users/@me/relationships.ts +++ b/api/src/routes/users/@me/relationships.ts @@ -45,7 +45,7 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request return await updateRelationship( req, res, - await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships", "relationships.to"], select: userProjection }), + await User.findOneOrFail({ where: { id: req.params.id }, relations: ["relationships", "relationships.to"], select: userProjection }), req.body.type ?? RelationshipType.friends ); }); @@ -75,8 +75,8 @@ router.delete("/:id", route({}), async (req: Request, res: Response) => { const { id } = req.params; if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend"); - const user = await User.findOneOrFail({ id: req.user_id }, { select: userProjection, relations: ["relationships"] }); - const friend = await User.findOneOrFail({ id: id }, { select: userProjection, relations: ["relationships"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: userProjection, relations: ["relationships"] }); + const friend = await User.findOneOrFail({ where: { id: id }, select: userProjection, relations: ["relationships"] }); const relationship = user.relationships.find((x) => x.to_id === id); const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id); @@ -124,10 +124,11 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ const id = friend.id; if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend"); - const user = await User.findOneOrFail( - { id: req.user_id }, - { relations: ["relationships", "relationships.to"], select: userProjection } - ); + const user = await User.findOneOrFail({ + where: { id: req.user_id }, + relations: ["relationships", "relationships.to"], + select: userProjection + }); let relationship = user.relationships.find((x) => x.to_id === id); const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id); diff --git a/api/src/routes/users/@me/settings.ts b/api/src/routes/users/@me/settings.ts index b22b72fb..70f8a218 100644 --- a/api/src/routes/users/@me/settings.ts +++ b/api/src/routes/users/@me/settings.ts @@ -10,7 +10,7 @@ router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, re const body = req.body as UserSettings; if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale - const user = await User.findOneOrFail({ id: req.user_id, bot: false }); + const user = await User.findOneOrFail({ where: { id: req.user_id, bot: false } }); user.settings = { ...user.settings, ...body }; await user.save(); diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index 0a74312e..80012260 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -68,10 +68,10 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { rights.hasThrow("SEND_MESSAGES"); } if (opts.application_id) { - message.application = await Application.findOneOrFail({ id: opts.application_id }); + message.application = await Application.findOneOrFail({ where: { id: opts.application_id } }); } if (opts.webhook_id) { - message.webhook = await Webhook.findOneOrFail({ id: opts.webhook_id }); + message.webhook = await Webhook.findOneOrFail({ where: { id: opts.webhook_id } }); } const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id); @@ -85,7 +85,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { permission.hasThrow("READ_MESSAGE_HISTORY"); // code below has to be redone when we add custom message routing if (message.guild_id !== null) { - const guild = await Guild.findOneOrFail({ id: channel.guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id } }); if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) { if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild"); if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel"); @@ -120,7 +120,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { await Promise.all( Array.from(content.matchAll(ROLE_MENTION)).map(async ([_, mention]) => { - const role = await Role.findOneOrFail({ id: mention, guild_id: channel.guild_id }); + const role = await Role.findOneOrFail({ where: { id: mention, guild_id: channel.guild_id } }); if (role.mentionable || permission.has("MANAGE_ROLES")) { mention_role_ids.push(mention); } |