Skip to content

Commit 170e86b

Browse files
MathMan05TheArcaneBrony
authored andcommitted
fix minor bug breaking bot invites
1 parent 2b18c1a commit 170e86b

1 file changed

Lines changed: 9 additions & 40 deletions

File tree

src/api/routes/oauth2/authorize.ts

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,9 @@
1717
*/
1818

1919
import { route } from "@spacebar/api";
20-
import {
21-
ApiError,
22-
Application,
23-
DiscordApiErrors,
24-
FieldErrors,
25-
Member,
26-
Permissions,
27-
User,
28-
getPermission,
29-
} from "@spacebar/util";
20+
import { ApiError, Application, DiscordApiErrors, FieldErrors, Member, Permissions, User, getPermission } from "@spacebar/util";
3021
import { Request, Response, Router } from "express";
31-
import { ApplicationAuthorizeSchema } from "@spacebar/schemas"
22+
import { ApplicationAuthorizeSchema } from "@spacebar/schemas";
3223
const router = Router({ mergeParams: true });
3324

3425
// TODO: scopes, other oauth types
@@ -84,26 +75,18 @@ router.get(
8475
id: req.user_id,
8576
bot: false,
8677
},
87-
select: [
88-
"id",
89-
"username",
90-
"avatar",
91-
"discriminator",
92-
"public_flags",
93-
],
78+
select: ["id", "username", "avatar", "discriminator", "public_flags"],
9479
});
9580

9681
const guilds = await Member.find({
9782
where: {
98-
user: {
99-
id: req.user_id,
100-
},
83+
id: req.user_id,
10184
},
10285
relations: ["guild", "roles", "user"],
10386
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
10487
//@ts-ignore
10588
// prettier-ignore
106-
select: ["guild.id", "guild.name", "guild.icon", "guild.mfa_level", "guild.owner_id", "roles.id", "communication_disabled_until", "user.flags"],
89+
select: ["guild.id", "guild.name", "guild.icon", "guild.mfa_level", "guild.owner_id", "roles.id", "user.flags","user.id"],
10790
});
10891

10992
const guildsWithPermissions = guilds.map((x) => {
@@ -112,7 +95,7 @@ router.get(
11295
id: user.id,
11396
roles: x.roles?.map((x) => x.id) || [],
11497
communication_disabled_until: x.communication_disabled_until,
115-
flags: x.user.flags
98+
flags: x.user.flags,
11699
},
117100
guild: {
118101
roles: x?.roles || [],
@@ -211,18 +194,9 @@ router.post(
211194
// TODO: captcha verification
212195
// TODO: MFA verification
213196

214-
const perms = await getPermission(
215-
req.user_id,
216-
body.guild_id,
217-
undefined,
218-
{ member_relations: ["user"] },
219-
);
197+
const perms = await getPermission(req.user_id, body.guild_id, undefined, { member_relations: ["user"] });
220198
// getPermission cache won't exist if we're owner
221-
if (
222-
Object.keys(perms.cache || {}).length > 0 &&
223-
perms.cache.member?.user.bot
224-
)
225-
throw DiscordApiErrors.UNAUTHORIZED;
199+
if (Object.keys(perms.cache || {}).length > 0 && perms.cache.member?.user.bot) throw DiscordApiErrors.UNAUTHORIZED;
226200
perms.hasThrow("MANAGE_GUILD");
227201

228202
const app = await Application.findOne({
@@ -235,12 +209,7 @@ router.post(
235209
// TODO: use DiscordApiErrors
236210
// findOneOrFail throws code 404
237211
if (!app) throw new ApiError("Unknown Application", 10002, 404);
238-
if (!app.bot)
239-
throw new ApiError(
240-
"OAuth2 application does not have a bot",
241-
50010,
242-
400,
243-
);
212+
if (!app.bot) throw new ApiError("OAuth2 application does not have a bot", 50010, 400);
244213

245214
await Member.addToGuild(app.id, body.guild_id);
246215

0 commit comments

Comments
 (0)