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 | 118 +++++++++--------- 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, 157 insertions(+), 128 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e321115cc..1f678d51a 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 841d73ba5..5635ec9e4 100644 --- a/flake.lock +++ b/flake.lock @@ -1,61 +1,61 @@ { - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1731676054, - "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 } diff --git a/server.code-workspace b/server.code-workspace index b10a35452..c3ffcffa7 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 27adc0bd2..b42749699 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 50c389e0a..dbe2dab44 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 521ab7a1b..4ba289275 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 90e781753..bb8d48977 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 b8c6a3867..781affe76 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 876780df3..3ac31680f 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 2f2351f38..63f403a13 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 f63ec37c4..8ec9fc7d8 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 eb1afe16a..4044b1116 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 7bc79d196..898308ac8 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 996c72ea5..5aae14c25 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[]) {