Resolve changes undone by rebasing from master

This commit is contained in:
TheArcaneBrony
2022-08-09 23:28:27 +02:00
parent 01da7dc4c2
commit cba3844c6f
55 changed files with 126 additions and 121 deletions
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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({
+3 -3
View File
@@ -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([
@@ -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);
@@ -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();
@@ -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);
@@ -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 {
@@ -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);
@@ -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);
+5 -5
View File
@@ -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);
});
@@ -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({
@@ -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({
@@ -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);
+1 -1
View File
@@ -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`]);
});
+1 -1
View File
@@ -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);
});
+3 -3
View File
@@ -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
+2 -2
View File
@@ -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);
})
+5 -5
View File
@@ -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);
+2 -2
View File
@@ -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);
@@ -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");
+1 -1
View File
@@ -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 } });
+1 -1
View File
@@ -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")));
});
@@ -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);
});
@@ -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);
+3 -3
View File
@@ -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);
}
+1 -1
View File
@@ -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({
@@ -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;
@@ -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;
}
@@ -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
@@ -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 = {
@@ -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
+1 -1
View File
@@ -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 });
});
+1 -1
View File
@@ -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);
+3 -3
View File
@@ -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();
+4 -4
View File
@@ -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);
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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,
+7 -5
View File
@@ -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
}
});
}
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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 }
+8 -7
View File
@@ -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);
+1 -1
View File
@@ -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();
+4 -4
View File
@@ -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);
}
BIN
View File
Binary file not shown.
+1
View File
@@ -7,6 +7,7 @@
"setup": "node scripts/install.js && npm install --omit optional && ts-patch install -s && patch-package --patch-dir ../api/patches/ && npm run build",
"depclean": "node scripts/depclean.js",
"depcheck": "node scripts/depcheck.js",
"syncdeps": "node scripts/install.js",
"build": "node scripts/build.js",
"start": "node scripts/build.js && node dist/bundle/src/start.js",
"start:bundle": "node dist/bundle/src/start.js",
+2 -2
View File
@@ -49,10 +49,10 @@ export async function setupListener(this: WebSocket) {
where: { user_id: this.user_id, closed: false },
relations: ["channel"],
}),
Relationship.find({
Relationship.find({ where: {
from_id: this.user_id,
type: RelationshipType.friends,
}),
} }),
]);
const guilds = members.map((x) => x.guild);
+2 -2
View File
@@ -58,7 +58,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
relations: ["relationships", "relationships.to"],
select: [...PrivateUserProjection, "relationships"],
}),
ReadState.find({ user_id: this.user_id }),
ReadState.find({ where: { user_id: this.user_id } }),
Member.find({
where: { id: this.user_id },
select: MemberPrivateProjection,
@@ -96,7 +96,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
},
activities: [],
}).save(),
Application.findOne({ id: this.user_id }),
Application.findOne({ where: { id: this.user_id } }),
]);
if (!user) return this.close(CLOSECODES.Authentication_failed);
+1 -1
View File
@@ -120,7 +120,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
const ranges = channels![channel_id];
if (!Array.isArray(ranges)) throw new Error("Not a valid Array");
const member_count = await Member.count({ guild_id });
const member_count = await Member.count({ where: { guild_id } });
const ops = await Promise.all(ranges.map((x) => getMembers(guild_id, x)));
// TODO: unsubscribe member_events that are not in op.members
+1 -1
View File
@@ -84,7 +84,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
//If it's null it means that we are leaving the channel and this event is not needed
if (voiceState.channel_id !== null) {
const guild = await Guild.findOne({ id: voiceState.guild_id });
const guild = await Guild.findOne({ where: { id: voiceState.guild_id } });
const regions = Config.get().regions;
let guildRegion: Region;
if (guild && guild.region) {
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -169,7 +169,7 @@ export class Channel extends BaseClass {
}
if (!opts?.skipNameChecks) {
const guild = await Guild.findOneOrFail({ id: channel.guild_id });
const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id } });
if (!guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") && channel.name) {
for (let character of InvisibleCharacters)
if (channel.name.includes(character))
@@ -194,7 +194,7 @@ export class Channel extends BaseClass {
case ChannelType.GUILD_NEWS:
case ChannelType.GUILD_VOICE:
if (channel.parent_id && !opts?.skipExistsCheck) {
const exists = await Channel.findOneOrFail({ id: channel.parent_id });
const exists = await Channel.findOneOrFail({ where: { id: channel.parent_id } });
if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400);
if (exists.guild_id !== channel.guild_id)
throw new HTTPError("The category channel needs to be in the guild");
+1 -1
View File
@@ -75,7 +75,7 @@ export class Invite extends BaseClassWithoutId {
vanity_url?: boolean;
static async joinGuild(user_id: string, code: string) {
const invite = await Invite.findOneOrFail({ code });
const invite = await Invite.findOneOrFail({ where: { code } });
if (invite.uses++ >= invite.max_uses && invite.max_uses !== 0) await Invite.delete({ code });
else await invite.save();
+4 -4
View File
@@ -117,7 +117,7 @@ export class Member extends BaseClassWithoutId {
// read_state: ReadState;
static async IsInGuildOrFail(user_id: string, guild_id: string) {
if (await Member.count({ id: user_id, guild: { id: guild_id } })) return true;
if (await Member.count({ where: { id: user_id, guild: { id: guild_id } } })) return true;
throw new HTTPError("You are not member of this guild", 403);
}
@@ -183,7 +183,7 @@ export class Member extends BaseClassWithoutId {
relations: ["user", "roles"], // we don't want to load the role objects just the ids
select: ["index"],
}),
await Role.findOneOrFail({ id: role_id, guild_id }),
await Role.findOneOrFail({ where: { id: role_id, guild_id } }),
]);
member.roles = member.roles.filter((x) => x.id == role_id);
@@ -233,7 +233,7 @@ export class Member extends BaseClassWithoutId {
throw DiscordApiErrors.USER_BANNED;
}
const { maxGuilds } = Config.get().limits.user;
const guild_count = await Member.count({ id: user_id });
const guild_count = await Member.count({ where: { id: user_id } });
if (guild_count >= maxGuilds) {
throw new HTTPError(`You are at the ${maxGuilds} server limit.`, 403);
}
@@ -245,7 +245,7 @@ export class Member extends BaseClassWithoutId {
relations: PublicGuildRelations,
});
if (await Member.count({ id: user.id, guild: { id: guild_id } }))
if (await Member.count({ where: { id: user.id, guild: { id: guild_id } } }))
throw new HTTPError("You are already a member of this guild", 400);
const member = {
-1
View File
@@ -8,7 +8,6 @@ import {
Column,
CreateDateColumn,
Entity,
FindConditions,
Index,
JoinColumn,
JoinTable,
+4 -4
View File
@@ -15,10 +15,10 @@ export function checkToken(token: string, jwtSecret: string): Promise<any> {
jwt.verify(token, jwtSecret, JWTOptions, async (err, decoded: any) => {
if (err || !decoded) return rej("Invalid Token");
const user = await User.findOne(
{ id: decoded.id },
{ select: ["data", "bot", "disabled", "deleted", "rights"] }
);
const user = await User.findOne({
where: { id: decoded.id },
select: ["data", "bot", "disabled", "deleted", "rights"]
});
if (!user) return rej("Invalid Token");
// we need to round it to seconds as it saved as seconds in jwt iat and valid_tokens_since is stored in milliseconds
if (decoded.iat * 1000 < new Date(user.data.valid_tokens_since).setSeconds(0, 0))