From f5d6394c38285161d35ba4fbece9b116bd33c700 Mon Sep 17 00:00:00 2001 From: dank074 Date: Tue, 19 Nov 2024 14:19:40 -0600 Subject: [PATCH] run prettier --- eslint.config.mjs | 69 ++++++++++-------- flake.lock | Bin 1497 -> 1305 bytes server.code-workspace | 16 ++-- src/api/Server.ts | 3 +- .../auth/generate-registration-tokens.ts | 2 +- .../channels/#channel_id/messages/index.ts | 2 +- src/api/routes/channels/#channel_id/typing.ts | 2 +- src/api/routes/discoverable-guilds.ts | 8 +- src/api/routes/guild-recommendations.ts | 2 +- src/api/routes/oauth2/authorize.ts | 2 +- src/gateway/events/Message.ts | 6 +- src/gateway/listener/listener.ts | 25 ++++++- src/util/entities/Channel.ts | 2 +- src/util/util/Permissions.ts | 28 ++++--- 14 files changed, 98 insertions(+), 69 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e321115c..1f678d51 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,39 +9,46 @@ import { FlatCompat } from "@eslint/eslintrc"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, }); -export default [{ - ignores: [ - "**/node_modules", - "**/dist", - "**/README.md", - "**/COPYING", - "src/webrtc", - "**/scripts/", - "**/assets", - ], -}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), { - plugins: { - "@typescript-eslint": typescriptEslint, - }, +export default [ + { + ignores: [ + "**/node_modules", + "**/dist", + "**/README.md", + "**/COPYING", + "src/webrtc", + "**/scripts/", + "**/assets", + ], + }, + ...compat.extends( + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + ), + { + plugins: { + "@typescript-eslint": typescriptEslint, + }, - languageOptions: { - globals: { - ...globals.node, - }, + languageOptions: { + globals: { + ...globals.node, + }, - parser: tsParser, - }, + parser: tsParser, + }, - rules: { - "no-mixed-spaces-and-tabs": "off", - "@typescript-eslint/no-inferrable-types": "off", // Required by typeorm - "@typescript-eslint/no-var-requires": "off", // Sometimes requred by typeorm to resolve circular deps - "@typescript-eslint/no-require-imports": "off", - "@typescript-eslint/no-unused-vars": "off", - }, -}]; \ No newline at end of file + rules: { + "no-mixed-spaces-and-tabs": "off", + "@typescript-eslint/no-inferrable-types": "off", // Required by typeorm + "@typescript-eslint/no-var-requires": "off", // Sometimes requred by typeorm to resolve circular deps + "@typescript-eslint/no-require-imports": "off", + "@typescript-eslint/no-unused-vars": "off", + }, + }, +]; diff --git a/flake.lock b/flake.lock index 841d73ba55622837bd7b7b1e7c60c54c4d9ad32b..5635ec9e410a6f7259c315ce668e9aa5ff78e534 100644 GIT binary patch literal 1305 zcmbVLU2mH(6n!SYV)E-2729CLq&+mz+H7kSDP1D9Z#K4x$7lFxlT`ih1p+Kx=@#t; z@HO|`bI-Z=X=H#n5i$p#KRk^L1E`P%a$FWV>_P_6aatDr(E#~AFJx2)`p+uWc>YvB zL6~@f6fItTW_dABgjTwVLW-e{F~X$zy(-VL8Ot{f+J+&Uj6?Ism2b~}Wx2{17vIzC zj~P|VY#Tuo9Ij^j)oeSPuG9IPfBOPjl;km%S&b2wQK5zG;+ag7I(*t!o07?g`UXO3 zQsE&*pd*BBdCZ~M<=AwkXDQD_mXJ1ec!yZ*Q(5Qvy4aK)oOGUK+Sf4)tJ_-3s`vk3 zH3VOQHR6I;@6y2UtvE+(LWyZx?`plc*Y`MbZl`m#!4tyO_4HyASv$P-V1#bhUoXR8 zP4peT^9QunyCm;)>6Gp`zE;_mmg0&Nj)jDbA%`MPiLhM7l;>KAAR-YHqC*>!p+N+H zQ~5O?Rohh2N%C`>KS{47a|&e}ISaXMeazGTbt=CIg#g%cmFpX4$0_p2p6+^nh@58P-nrNkLDcid6x zy*w_HkcyRI(RtM_l3;|IE@7CvT-k)VP(b3E5V=^|kTaWGE literal 1497 zcmbtTU2obj6n*cnKzZFzV>`B!NqZ=0E!&Ea=s;@U?AQ)oKFLQ5RQ>Nu0%?sP8q;2q z_&Pr4_?~lLuLc7vNrfz|FN4>5Q7=`*LOHBT9eot*vQDz9G%Izj*cPRXo8tRti!m6y zeLj3xQR;_Myu-H?5i81RDzwt=4xk8Ngdif_sYVscC#+bt*eeDx8AkTc+W=2~=Y=X} z*FUnmPdQcdd>sQA?rtaB#biAhFSF^CfB$M3Na;%=^9CoW;!+D~?&UH|n=SLw#?f3p zH@g5(n+hK)0$d@m<1?2ck0aZYzN35_IznRVaud1SX0kaO=yFwY>!dGft^=L0sQzc) z__j0up|yvwB|g|;C3=&Ef$8F<{t!xR>=>;%^=I~^pHS>RjHhaaMue-o@%1QnHfZgG z7(Oh&-9+J%=tue(^!TGUX<_!TbElJS&>x(^(otM-!jX`GG3ZjrDG`pRnDRXb5=bOu zLYSyMjq1Ryzd3WNQZ+``BGY16B}K`2bT(vXuF<3A$h167OCu#`C(+Drf1Eo3d$ny6 zx?CPHe#~_j&5L3}Twp`jg>Ki%vtzv6f_#l{*u1*m%{G4NCOhXBd5MDUVorDWi+ZX; zFCL94aeHGj>=YVIU08%vtcpt0@k3YyBh>Z?L)_yE6XpQ{h-U-nA&CKJm^&VW^vJs& ngF4;|!t#$=dkFXb)X#R5twSdE??#OEEb~IANgWh=^>+0Ky@!3_ diff --git a/server.code-workspace b/server.code-workspace index b10a3545..c3ffcffa 100644 --- a/server.code-workspace +++ b/server.code-workspace @@ -1,23 +1,23 @@ { "folders": [ { - "path": "src" + "path": "src", }, { - "path": "assets" + "path": "assets", }, { - "path": "scripts" + "path": "scripts", }, { - "path": "." - } + "path": ".", + }, ], "settings": { - "typescript.tsdk": "util\\node_modules\\typescript\\lib" + "typescript.tsdk": "util\\node_modules\\typescript\\lib", }, "launch": { "version": "0.2.0", - "configurations": [] - } + "configurations": [], + }, } diff --git a/src/api/Server.ts b/src/api/Server.ts index 27adc0bd..b4274969 100644 --- a/src/api/Server.ts +++ b/src/api/Server.ts @@ -100,8 +100,7 @@ export class SpacebarServer extends Server { this.app.set("json replacer", JSONReplacer); const trustedProxies = Config.get().security.trustedProxies; - if(trustedProxies) - this.app.set("trust proxy", trustedProxies); + if (trustedProxies) this.app.set("trust proxy", trustedProxies); this.app.use(CORS); this.app.use(BodyParser({ inflate: true, limit: "10mb" })); diff --git a/src/api/routes/auth/generate-registration-tokens.ts b/src/api/routes/auth/generate-registration-tokens.ts index 50c389e0..dbe2dab4 100644 --- a/src/api/routes/auth/generate-registration-tokens.ts +++ b/src/api/routes/auth/generate-registration-tokens.ts @@ -72,7 +72,7 @@ router.get( `${Config.get().general.frontPage}/register?token=${ x.token }`, - ) + ) : tokens.map((x) => x.token); if (req.query.plain) return res.send(ret.join("\n")); diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index 521ab7a1..4ba28927 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -417,7 +417,7 @@ router.post( ? Member.update( { id: req.user_id, guild_id: message.guild_id }, { last_message_id: message.id }, - ) + ) : null, channel.save(), ]); diff --git a/src/api/routes/channels/#channel_id/typing.ts b/src/api/routes/channels/#channel_id/typing.ts index 90e78175..bb8d4897 100644 --- a/src/api/routes/channels/#channel_id/typing.ts +++ b/src/api/routes/channels/#channel_id/typing.ts @@ -54,7 +54,7 @@ router.post( ...member, roles: member?.roles?.map((x) => x.id), }, - } + } : null), channel_id, timestamp, diff --git a/src/api/routes/discoverable-guilds.ts b/src/api/routes/discoverable-guilds.ts index b8c6a386..781affe7 100644 --- a/src/api/routes/discoverable-guilds.ts +++ b/src/api/routes/discoverable-guilds.ts @@ -42,24 +42,24 @@ router.get( guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || configLimit)), - }) + }) : await Guild.find({ where: { features: Like(`%DISCOVERABLE%`) }, take: Math.abs(Number(limit || configLimit)), - }); + }); } else { guilds = showAllGuilds ? await Guild.find({ where: { primary_category_id: categories.toString() }, take: Math.abs(Number(limit || configLimit)), - }) + }) : await Guild.find({ where: { primary_category_id: categories.toString(), features: Like("%DISCOVERABLE%"), }, take: Math.abs(Number(limit || configLimit)), - }); + }); } const total = guilds ? guilds.length : undefined; diff --git a/src/api/routes/guild-recommendations.ts b/src/api/routes/guild-recommendations.ts index 876780df..3ac31680 100644 --- a/src/api/routes/guild-recommendations.ts +++ b/src/api/routes/guild-recommendations.ts @@ -48,7 +48,7 @@ router.get( : await Guild.find({ where: { features: Like("%DISCOVERABLE%") }, take: Math.abs(Number(limit || 24)), - }); + }); res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}`, diff --git a/src/api/routes/oauth2/authorize.ts b/src/api/routes/oauth2/authorize.ts index 2f2351f3..63f403a1 100644 --- a/src/api/routes/oauth2/authorize.ts +++ b/src/api/routes/oauth2/authorize.ts @@ -118,7 +118,7 @@ router.get( guild: { roles: x?.roles || [], }, - }); + }); return { id: x.guild.id, diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts index f63ec37c..8ec9fc7d 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts @@ -89,11 +89,13 @@ export async function Message(this: WebSocket, buffer: WS.Data) { } try { - return await Sentry.startSpan( // Emma [it/its]@Rory&: is this the right function to migrate to in v8? + return await Sentry.startSpan( + // Emma [it/its]@Rory&: is this the right function to migrate to in v8? { op: "websocket.server", name: `GATEWAY ${OPCODES[data.op]}`, - attributes: { // this needs to be reworked :) + attributes: { + // this needs to be reworked :) ...data.d, token: data?.d?.token ? "[Redacted]" : undefined, }, diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts index eb1afe16..4044b111 100644 --- a/src/gateway/listener/listener.ts +++ b/src/gateway/listener/listener.ts @@ -82,7 +82,7 @@ export async function setupListener(this: WebSocket) { const opts: { acknowledge: boolean; - channel?: AMQChannel & { queues?: unknown, ch?: number }; + channel?: AMQChannel & { queues?: unknown; ch?: number }; } = { acknowledge: true, }; @@ -91,10 +91,20 @@ export async function setupListener(this: WebSocket) { console.log("[RabbitMQ] setupListener: open for ", this.user_id); if (RabbitMQ.connection) { - console.log("[RabbitMQ] setupListener: opts.channel = ", typeof opts.channel, "with channel id", opts.channel?.ch); + console.log( + "[RabbitMQ] setupListener: opts.channel = ", + typeof opts.channel, + "with channel id", + opts.channel?.ch, + ); opts.channel = await RabbitMQ.connection.createChannel(); opts.channel.queues = {}; - console.log("[RabbitMQ] channel created: ", typeof opts.channel, "with channel id", opts.channel?.ch); + console.log( + "[RabbitMQ] channel created: ", + typeof opts.channel, + "with channel id", + opts.channel?.ch, + ); } this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts); @@ -132,7 +142,14 @@ export async function setupListener(this: WebSocket) { }); this.once("close", () => { - console.log("[RabbitMQ] setupListener: close for", this.user_id, "=", typeof opts.channel, "with channel id", opts.channel?.ch); + console.log( + "[RabbitMQ] setupListener: close for", + this.user_id, + "=", + typeof opts.channel, + "with channel id", + opts.channel?.ch, + ); if (opts.channel) opts.channel.close(); else { Object.values(this.events).forEach((x) => x?.()); diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 7bc79d19..898308ac 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -323,7 +323,7 @@ export class Channel extends BaseClass { event: "CHANNEL_CREATE", data: channel, guild_id: channel.guild_id, - } as ChannelCreateEvent) + } as ChannelCreateEvent) : Promise.resolve(), Guild.insertChannelInOrder(guild.id, ret.id, position, guild), ]); diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts index 996c72ea..5aae14c2 100644 --- a/src/util/util/Permissions.ts +++ b/src/util/util/Permissions.ts @@ -132,18 +132,22 @@ export class Permissions extends BitField { init?: bigint, ) { // TODO: do not deny any permissions if admin - return overwrites.reduce((permission, overwrite) => { - // apply disallowed permission - // * permission: current calculated permission (e.g. 010) - // * deny contains all denied permissions (e.g. 011) - // * allow contains all explicitly allowed permisions (e.g. 100) - return ( - (permission & ~BigInt(overwrite.deny)) | BigInt(overwrite.allow) - ); - // ~ operator inverts deny (e.g. 011 -> 100) - // & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) - // | operators adds both together (e.g. 000 + 100 -> 100) - }, init || BigInt(0)); + return overwrites.reduce( + (permission, overwrite) => { + // apply disallowed permission + // * permission: current calculated permission (e.g. 010) + // * deny contains all denied permissions (e.g. 011) + // * allow contains all explicitly allowed permisions (e.g. 100) + return ( + (permission & ~BigInt(overwrite.deny)) | + BigInt(overwrite.allow) + ); + // ~ operator inverts deny (e.g. 011 -> 100) + // & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) + // | operators adds both together (e.g. 000 + 100 -> 100) + }, + init || BigInt(0), + ); } static rolePermission(roles: Role[]) {