diff --git a/.env.example b/.env.example deleted file mode 100644 index 7878e9be..00000000 --- a/.env.example +++ /dev/null @@ -1,84 +0,0 @@ -# ========================== -# GENERAL OPTIONS -# ========================== - -# 32 character encryption key -KEY= - -# Values from the Discord developer portal -CLIENT_ID= -CLIENT_SECRET= -BOT_TOKEN= - -# The defaults here automatically work for the development environment. -# For production, change localhost:3300 to your domain. -DASHBOARD_URL=https://localhost:3300 -API_URL=https://localhost:3300/api - -# Comma-separated list of user IDs who should have access to the bot's global commands -STAFF= - -# A comma-separated list of server IDs that should be allowed by default -DEFAULT_ALLOWED_SERVERS= - -# Only required if relevant feature is used -#PHISHERMAN_API_KEY= - - -# ========================== -# DEVELOPMENT -# NOTE: You only need to fill in these values for running the development environment -# ========================== - -DEVELOPMENT_WEB_PORT=3300 - -# The MySQL database running in the container is exposed to the host on this port, -# allowing access with database tools such as DBeaver -DEVELOPMENT_MYSQL_PORT=3356 -# Password for the Zeppelin database user -DEVELOPMENT_MYSQL_PASSWORD=password -# Password for the MySQL root user -DEVELOPMENT_MYSQL_ROOT_PASSWORD=password - -# The development environment container has an SSH server that you can connect to. -# This is the port that server is exposed to the host on. -DEVELOPMENT_SSH_PORT=3022 -DEVELOPMENT_SSH_PASSWORD=password - -# If your user has a different UID than 1000, you might have to fill that in here to avoid permission issues -#DEVELOPMENT_UID=1000 - - -# ========================== -# PRODUCTION - STANDALONE -# NOTE: You only need to fill in these values for running the standalone production environment -# ========================== - -STANDALONE_WEB_PORT=80 - -# The MySQL database running in the container is exposed to the host on this port, -# allowing access with database tools such as DBeaver -STANDALONE_MYSQL_PORT=3356 -# Password for the Zeppelin database user -STANDALONE_MYSQL_PASSWORD= -# Password for the MySQL root user -STANDALONE_MYSQL_ROOT_PASSWORD= - - -# ========================== -# PRODUCTION - LIGHTWEIGHT -# NOTE: You only need to fill in these values for running the lightweight production environment -# ========================== - -# Ports where the API/dashboard are exposed on the host -LIGHTWEIGHT_API_PORT=3001 -LIGHTWEIGHT_DASHBOARD_PORT=3002 - -LIGHTWEIGHT_DB_HOST= -LIGHTWEIGHT_DB_PORT= -LIGHTWEIGHT_DB_USER= -LIGHTWEIGHT_DB_PASSWORD= -LIGHTWEIGHT_DB_DATABASE= - -# If you want to add a prefix to API paths, such as /api, you can set that here -LIGHTWEIGHT_API_PATH_PREFIX= diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 4ba6dfe6..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = { - root: true, - env: { - node: true, - browser: true, - es6: true, - }, - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], - parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint"], - rules: { - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-non-null-assertion": 0, - "no-async-promise-executor": 0, - "@typescript-eslint/no-empty-interface": 0, - "no-constant-condition": ["error", { - checkLoops: false, - }], - "prefer-const": ["error", { - destructuring: "all", - ignoreReadBeforeAssign: true, - }], - "@typescript-eslint/no-namespace": ["error", { - allowDeclarations: true, - }], - }, -}; diff --git a/.github/workflows/codequality.yml b/.github/workflows/codequality.yml index 0d17dbc9..fa2790f2 100644 --- a/.github/workflows/codequality.yml +++ b/.github/workflows/codequality.yml @@ -8,16 +8,20 @@ jobs: strategy: matrix: - node-version: [18.16] + node-version: [23] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm install, lint, code style check + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: latest + - name: pnpm install, lint, code style check run: | - npm ci - npm run lint - npm run codestyle-check + pnpm i + pnpm run lint + pnpm run codestyle-check diff --git a/Dockerfile b/Dockerfile index 5015b021..3f750a0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM node:20 RUN mkdir /zeppelin +RUN corepack enable RUN chown node:node /zeppelin USER node @@ -8,27 +9,34 @@ USER node ARG API_URL # Install dependencies before copying over any other files -COPY --chown=node:node package.json package-lock.json /zeppelin +RUN corepack prepare --activate pnpm@latest +COPY --chown=node:node package.json pnpm-lock.yaml pnpm-workspace.yaml /zeppelin/ RUN mkdir /zeppelin/backend -COPY --chown=node:node backend/package.json /zeppelin/backend +COPY --chown=node:node backend/package.json /zeppelin/backend/ RUN mkdir /zeppelin/shared -COPY --chown=node:node shared/package.json /zeppelin/shared +COPY --chown=node:node shared/package.json /zeppelin/shared/ RUN mkdir /zeppelin/dashboard -COPY --chown=node:node dashboard/package.json /zeppelin/dashboard +COPY --chown=node:node dashboard/package.json /zeppelin/dashboard/ +RUN mkdir /zeppelin/revampdashboard +COPY --chown=node:node revampdashboard/package.json /zeppelin/revampdashboard/ WORKDIR /zeppelin -RUN npm ci +RUN pnpm i COPY --chown=node:node . /zeppelin # Build backend WORKDIR /zeppelin/backend -RUN npm run build +RUN pnpm run build # Build dashboard WORKDIR /zeppelin/dashboard -RUN npm run build +RUN pnpm run build + +WORKDIR /zeppelin/revampdashboard/ +RUN pnpm run check +RUN pnpm run build # Prune dev dependencies WORKDIR /zeppelin -RUN npm prune --omit=dev +RUN pnpm prune --prod diff --git a/backend/package.json b/backend/package.json index 744cc320..9e380a2a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,26 +18,28 @@ "start-api-prod-debug": "clinic heapprofiler --collect-only --dest .clinic-api -- node --enable-source-maps --stack-trace-limit=30 dist/api/index.js", "watch-api": "tsc-watch --build --onSuccess \"npm run start-api-dev\"", "typeorm": "node ../node_modules/typeorm/cli.js", - "migrate": "npm run typeorm -- migration:run -d dist/data/dataSource.js", - "migrate-prod": "npm run migrate", - "migrate-dev": "npm run build && npm run migrate", - "migrate-rollback": "npm run typeorm -- migration:revert -d dist/data/dataSource.js", - "migrate-rollback-prod": "npm run migrate-rollback", - "migrate-rollback-dev": "npm run build && npm run migrate-rollback", + "migrate": "pnpm run typeorm -- migration:run -d dist/data/dataSource.js", + "migrate-prod": "pnpm run migrate", + "migrate-dev": "pnpm run build && npm run migrate", + "migrate-rollback": "pnpm run typeorm -- migration:revert -d dist/data/dataSource.js", + "migrate-rollback-prod": "pnpm run migrate-rollback", + "migrate-rollback-dev": "pnpm run build && npm run migrate-rollback", "validate-active-configs": "node --enable-source-maps dist/validateActiveConfigs.js > ../config-errors.txt", "export-config-json-schema": "node --enable-source-maps dist/exportSchemas.js > ../config-schema.json", - "test": "npm run build && npm run run-tests", + "test": "pnpm run build && pnpm run run-tests", "run-tests": "ava", "test-watch": "tsc-watch --build --onSuccess \"npx ava\"" }, "dependencies": { "@silvia-odwyer/photon-node": "^0.3.1", + "@zeppelinbot/shared": "workspace:*", "bufferutil": "^4.0.3", "clinic": "^13.0.0", + "cookie-parser": "^1.4.7", "cors": "^2.8.5", "cross-env": "^7.0.3", "deep-diff": "^1.0.2", - "discord.js": "^14.14.1", + "discord.js": "^14.16.3", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", "escape-string-regexp": "^1.0.5", @@ -48,12 +50,14 @@ "knub": "^32.0.0-next.21", "knub-command-manager": "^9.1.0", "last-commit-log": "^2.1.0", + "lodash": "^4.17.21", "lodash.chunk": "^4.2.0", "lodash.clonedeep": "^4.5.0", "lodash.difference": "^4.5.0", "lodash.intersection": "^4.4.0", "lodash.isequal": "^4.5.0", "lodash.pick": "^4.4.0", + "moment": "^2.29.4", "moment-timezone": "^0.5.21", "multer": "^1.4.5-lts.1", "mysql2": "^3.9.3", @@ -72,18 +76,20 @@ "tmp": "0.0.33", "tsconfig-paths": "^3.9.0", "twemoji": "^12.1.4", - "typeorm": "^0.3.17", + "typeorm": "^0.3.20", "utf-8-validate": "^5.0.5", "uuid": "^9.0.0", "yawn-yaml": "github:dragory/yawn-yaml#string-number-fix-build", - "zlib-sync": "^0.1.7", + "zlib-sync": "^0.1.9", "zod": "^3.7.2" }, "devDependencies": { + "@types/cookie-parser": "^1.4.7", "@types/cors": "^2.8.5", "@types/express": "^4.16.1", "@types/jest": "^24.0.15", "@types/js-yaml": "^3.12.1", + "@types/lodash": "^4.17.13", "@types/lodash.at": "^4.6.3", "@types/moment-timezone": "^0.5.6", "@types/multer": "^1.4.7", @@ -96,7 +102,7 @@ "@types/twemoji": "^12.1.0", "@types/uuid": "^9.0.2", "ava": "^5.3.1", - "rimraf": "^2.6.2", + "rimraf": "^6.0.1", "source-map-support": "^0.5.16", "zod-to-json-schema": "^3.22.3" }, diff --git a/backend/src/SimpleCache.ts b/backend/src/SimpleCache.ts index 57a58bf7..ad3205b4 100644 --- a/backend/src/SimpleCache.ts +++ b/backend/src/SimpleCache.ts @@ -47,7 +47,7 @@ export class SimpleCache { if (this.maxItems && this.store.size > this.maxItems) { const keyToDelete = this.store.keys().next().value; - this.store.delete(keyToDelete); + this.store.delete(keyToDelete!); } } diff --git a/backend/src/api/auth.ts b/backend/src/api/auth.ts index 543dab0f..9cd5ad8a 100644 --- a/backend/src/api/auth.ts +++ b/backend/src/api/auth.ts @@ -1,4 +1,4 @@ -import express, { Request, Response } from "express"; +import express, { NextFunction, Request, Response } from "express"; import https from "https"; import pick from "lodash.pick"; import passport from "passport"; @@ -111,14 +111,32 @@ export function initAuth(router: express.Router) { ); router.get("/auth/login", passport.authenticate("oauth2")); + router.get( + "/auth/new-login", + (req: Request, res: Response, next: NextFunction) => { + res.cookie("redir", `/new/auth/login-callback/`, { httpOnly: true }); + + next(); + }, + passport.authenticate("oauth2"), + ); router.get( "/auth/oauth-callback", passport.authenticate("oauth2", { failureRedirect: "/", session: false }), (req: Request, res: Response) => { + res.clearCookie("redir"); if (req.user && req.user.apiKey) { - res.redirect(`${env.DASHBOARD_URL}/login-callback/?apiKey=${req.user.apiKey}`); + res.redirect( + req.cookies.redir + ? `${env.DASHBOARD_URL}${req.cookies.redir.toString()}?apiKey=${req.user.apiKey}` + : `${env.DASHBOARD_URL}/login-callback/?apiKey=${req.user.apiKey}`, + ); } else { - res.redirect(`${env.DASHBOARD_URL}/login-callback/?error=noAccess`); + res.redirect( + req.cookies.redir + ? `${env.DASHBOARD_URL}${req.cookies.redir.toString()}?error=noAccess` + : `${env.DASHBOARD_URL}/login-callback/?error=noAccess`, + ); } }, ); @@ -150,7 +168,6 @@ export function initAuth(router: express.Router) { export function apiTokenAuthHandlers() { return [ passport.authenticate("api-token", { failWithError: true, session: false }), - // eslint-disable-next-line @typescript-eslint/no-unused-vars (err, req: Request, res: Response, next) => { return res.status(401).json({ error: err.message }); }, diff --git a/backend/src/api/start.ts b/backend/src/api/start.ts index 088c8ba9..d6df62a7 100644 --- a/backend/src/api/start.ts +++ b/backend/src/api/start.ts @@ -1,6 +1,7 @@ import cors from "cors"; import express from "express"; import multer from "multer"; +import cookieParser from "cookie-parser"; import { TokenError } from "passport-oauth2"; import { env } from "../env"; import { initArchives } from "./archives"; @@ -25,13 +26,14 @@ app.use( }), ); app.use(multer().none()); +app.use(cookieParser()); const rootRouter = express.Router(); -initAuth(app); -initGuildsAPI(app); -initArchives(app); -initDocs(app); +initAuth(rootRouter); +initGuildsAPI(rootRouter); +initArchives(rootRouter); +initDocs(rootRouter); // Default route rootRouter.get("/", (req, res) => { diff --git a/backend/src/data/ApiLogins.ts b/backend/src/data/ApiLogins.ts index 94ffac7d..67b9d14c 100644 --- a/backend/src/data/ApiLogins.ts +++ b/backend/src/data/ApiLogins.ts @@ -7,6 +7,7 @@ import { DAYS, DBDateFormat } from "../utils"; import { BaseRepository } from "./BaseRepository"; import { dataSource } from "./dataSource"; import { ApiLogin } from "./entities/ApiLogin"; +import { randomBytes } from "node:crypto"; const LOGIN_EXPIRY_TIME = 1 * DAYS; @@ -48,7 +49,7 @@ export class ApiLogins extends BaseRepository { // Generate random login id let loginId; while (true) { - loginId = uuidv4(); + loginId = randomBytes(16).toString("hex"); const existing = await this.apiLogins.findOne({ where: { id: loginId, @@ -58,7 +59,7 @@ export class ApiLogins extends BaseRepository { } // Generate token - const token = uuidv4(); + const token = randomBytes(32).toString("hex"); const hash = crypto.createHash("sha256"); hash.update(loginId + token); // Use loginId as a salt const hashedToken = hash.digest("hex"); diff --git a/backend/src/data/ApiUserInfo.ts b/backend/src/data/ApiUserInfo.ts index 1dbc9d45..d2431217 100644 --- a/backend/src/data/ApiUserInfo.ts +++ b/backend/src/data/ApiUserInfo.ts @@ -3,7 +3,7 @@ import { Repository } from "typeorm"; import { DBDateFormat } from "../utils"; import { BaseRepository } from "./BaseRepository"; import { dataSource } from "./dataSource"; -import { ApiUserInfoData, ApiUserInfo as ApiUserInfoEntity } from "./entities/ApiUserInfo"; +import { ApiUserInfo as ApiUserInfoEntity, ApiUserInfoData } from "./entities/ApiUserInfo"; export class ApiUserInfo extends BaseRepository { private apiUserInfo: Repository; diff --git a/backend/src/data/GuildArchives.ts b/backend/src/data/GuildArchives.ts index 4d74ccef..bfeb22b4 100644 --- a/backend/src/data/GuildArchives.ts +++ b/backend/src/data/GuildArchives.ts @@ -1,7 +1,7 @@ import { Guild, Snowflake } from "discord.js"; import moment from "moment-timezone"; import { Repository } from "typeorm"; -import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter"; +import { renderTemplate, TemplateSafeValueContainer } from "../templateFormatter"; import { renderUsername, trimLines } from "../utils"; import { decrypt, encrypt } from "../utils/crypt"; import { isDefaultSticker } from "../utils/isDefaultSticker"; diff --git a/backend/src/data/GuildCounters.ts b/backend/src/data/GuildCounters.ts index 18c9b5e6..0f32e8d5 100644 --- a/backend/src/data/GuildCounters.ts +++ b/backend/src/data/GuildCounters.ts @@ -5,7 +5,7 @@ import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils"; import { BaseGuildRepository } from "./BaseGuildRepository"; import { dataSource } from "./dataSource"; import { Counter } from "./entities/Counter"; -import { CounterTrigger, TriggerComparisonOp, isValidCounterComparisonOp } from "./entities/CounterTrigger"; +import { CounterTrigger, isValidCounterComparisonOp, TriggerComparisonOp } from "./entities/CounterTrigger"; import { CounterTriggerState } from "./entities/CounterTriggerState"; import { CounterValue } from "./entities/CounterValue"; diff --git a/backend/src/index.ts b/backend/src/index.ts index 77d66cba..16867fbf 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -44,7 +44,7 @@ import { baseGuildPlugins, globalPlugins, guildPlugins } from "./plugins/availab import { setProfiler } from "./profiler"; import { logRateLimit } from "./rateLimitStats"; import { startUptimeCounter } from "./uptime"; -import { MINUTES, SECONDS, errorMessage, isDiscordAPIError, isDiscordHTTPError, sleep, successMessage } from "./utils"; +import { errorMessage, isDiscordAPIError, isDiscordHTTPError, MINUTES, SECONDS, sleep, successMessage } from "./utils"; import { DecayingCounter } from "./utils/DecayingCounter"; import { enableProfiling } from "./utils/easyProfiler"; import { loadYamlSafely } from "./utils/loadYamlSafely"; diff --git a/backend/src/migrations/1573248462469-MoveStarboardsToConfig.ts b/backend/src/migrations/1573248462469-MoveStarboardsToConfig.ts index e1f967b1..881fc3e7 100644 --- a/backend/src/migrations/1573248462469-MoveStarboardsToConfig.ts +++ b/backend/src/migrations/1573248462469-MoveStarboardsToConfig.ts @@ -3,18 +3,24 @@ import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm"; export class MoveStarboardsToConfig1573248462469 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { // Create a new column for the channel's id - await queryRunner.addColumn("starboard_messages", new TableColumn({ - name: "starboard_channel_id", - type: "bigint", - unsigned: true, - })); + await queryRunner.addColumn( + "starboard_messages", + new TableColumn({ + name: "starboard_channel_id", + type: "bigint", + unsigned: true, + }), + ); // Since we are removing the guild_id with the starboards table, we might want it here - await queryRunner.addColumn("starboard_messages", new TableColumn({ - name: "guild_id", - type: "bigint", - unsigned: true, - })); + await queryRunner.addColumn( + "starboard_messages", + new TableColumn({ + name: "guild_id", + type: "bigint", + unsigned: true, + }), + ); // Migrate the old starboard_id to the new starboard_channel_id await queryRunner.query(` @@ -43,11 +49,14 @@ export class MoveStarboardsToConfig1573248462469 implements MigrationInterface { await queryRunner.dropColumn("starboard_messages", "starboard_channel_id"); await queryRunner.dropColumn("starboard_messages", "guild_id"); - await queryRunner.addColumn("starboard_messages", new TableColumn({ - name: "starboard_id", - type: "int", - unsigned: true, - })); + await queryRunner.addColumn( + "starboard_messages", + new TableColumn({ + name: "starboard_id", + type: "int", + unsigned: true, + }), + ); await queryRunner.query(` ALTER TABLE starboard_messages diff --git a/backend/src/pluginUtils.ts b/backend/src/pluginUtils.ts index 05428bf7..fa29844b 100644 --- a/backend/src/pluginUtils.ts +++ b/backend/src/pluginUtils.ts @@ -3,12 +3,14 @@ */ import { + DMChannel, GuildMember, Message, MessageCreateOptions, MessageMentionOptions, PermissionsBitField, TextBasedChannel, + TextChannel, } from "discord.js"; import { AnyPluginData, BasePluginData, CommandContext, ExtendedMatchParams, GuildPluginData, helpers } from "knub"; import { logger } from "./logger"; @@ -61,7 +63,7 @@ export async function sendSuccessMessage( ? { content: formattedBody, allowedMentions } : { content: formattedBody }; - return channel + return ((channel as TextChannel) || DMChannel) .send({ ...content }) // Force line break .catch((err) => { const channelInfo = "guild" in channel ? `${channel.id} (${channel.guild.id})` : channel.id; @@ -82,7 +84,7 @@ export async function sendErrorMessage( ? { content: formattedBody, allowedMentions } : { content: formattedBody }; - return channel + return ((channel as TextChannel) || DMChannel) .send({ ...content }) // Force line break .catch((err) => { const channelInfo = "guild" in channel ? `${channel.id} (${channel.guild.id})` : channel.id; diff --git a/backend/src/plugins/AutoDelete/AutoDeletePlugin.ts b/backend/src/plugins/AutoDelete/AutoDeletePlugin.ts index 4c537bf0..f6eef876 100644 --- a/backend/src/plugins/AutoDelete/AutoDeletePlugin.ts +++ b/backend/src/plugins/AutoDelete/AutoDeletePlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { LogsPlugin } from "../Logs/LogsPlugin"; diff --git a/backend/src/plugins/AutoReactions/AutoReactionsPlugin.ts b/backend/src/plugins/AutoReactions/AutoReactionsPlugin.ts index 6c24b296..cde1434a 100644 --- a/backend/src/plugins/AutoReactions/AutoReactionsPlugin.ts +++ b/backend/src/plugins/AutoReactions/AutoReactionsPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildAutoReactions } from "../../data/GuildAutoReactions"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { LogsPlugin } from "../Logs/LogsPlugin"; diff --git a/backend/src/plugins/Automod/actions/changePerms.ts b/backend/src/plugins/Automod/actions/changePerms.ts index 351b1637..9cac723c 100644 --- a/backend/src/plugins/Automod/actions/changePerms.ts +++ b/backend/src/plugins/Automod/actions/changePerms.ts @@ -1,7 +1,7 @@ import { PermissionsBitField, PermissionsString } from "discord.js"; import { U } from "ts-toolbelt"; import z from "zod"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; import { isValidSnowflake, keys, noop, zBoundedCharacters } from "../../../utils"; import { guildToTemplateSafeGuild, diff --git a/backend/src/plugins/Automod/actions/reply.ts b/backend/src/plugins/Automod/actions/reply.ts index 0628e26f..f772feb2 100644 --- a/backend/src/plugins/Automod/actions/reply.ts +++ b/backend/src/plugins/Automod/actions/reply.ts @@ -1,6 +1,6 @@ import { GuildTextBasedChannel, MessageCreateOptions, PermissionsBitField, Snowflake, User } from "discord.js"; import z from "zod"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; import { convertDelayStringToMS, noop, diff --git a/backend/src/plugins/Automod/actions/startThread.ts b/backend/src/plugins/Automod/actions/startThread.ts index a521d72f..809f35ba 100644 --- a/backend/src/plugins/Automod/actions/startThread.ts +++ b/backend/src/plugins/Automod/actions/startThread.ts @@ -1,7 +1,7 @@ import { ChannelType, GuildTextThreadCreateOptions, ThreadAutoArchiveDuration, ThreadChannel } from "discord.js"; import z from "zod"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; -import { MINUTES, convertDelayStringToMS, noop, zBoundedCharacters, zDelayString } from "../../../utils"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; +import { convertDelayStringToMS, MINUTES, noop, zBoundedCharacters, zDelayString } from "../../../utils"; import { savedMessageToTemplateSafeSavedMessage, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { automodAction } from "../helpers"; diff --git a/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts b/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts index 24d3ac6a..d26c318b 100644 --- a/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts +++ b/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts @@ -1,7 +1,7 @@ import { Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; -import { UserNotificationMethod, disableUserNotificationStrings } from "../../../utils"; +import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils"; import { AutomodPluginType } from "../types"; export function resolveActionContactMethods( diff --git a/backend/src/plugins/Automod/triggers/matchInvites.ts b/backend/src/plugins/Automod/triggers/matchInvites.ts index 4ea7c3cd..013c2a47 100644 --- a/backend/src/plugins/Automod/triggers/matchInvites.ts +++ b/backend/src/plugins/Automod/triggers/matchInvites.ts @@ -51,10 +51,10 @@ export const MatchInvitesTrigger = automodTrigger()({ const invite = await resolveInvite(pluginData.client, code); if (!invite || !isGuildInvite(invite)) return { extra: { type, code } }; - if (trigger.include_guilds && trigger.include_guilds.includes(invite.guild.id)) { + if (trigger.include_guilds && trigger.include_guilds.includes(await zSnowflake.parseAsync(invite.guild.id))) { return { extra: { type, code, invite } }; } - if (trigger.exclude_guilds && !trigger.exclude_guilds.includes(invite.guild.id)) { + if (trigger.exclude_guilds && !trigger.exclude_guilds.includes(await zSnowflake.parseAsync(invite.guild.id))) { return { extra: { type, code, invite } }; } } diff --git a/backend/src/plugins/Automod/triggers/threadArchive.ts b/backend/src/plugins/Automod/triggers/threadArchive.ts index c9f7b75e..d95823ac 100644 --- a/backend/src/plugins/Automod/triggers/threadArchive.ts +++ b/backend/src/plugins/Automod/triggers/threadArchive.ts @@ -1,4 +1,4 @@ -import { User, escapeBold, type Snowflake } from "discord.js"; +import { escapeBold, type Snowflake, User } from "discord.js"; import z from "zod"; import { renderUsername } from "../../../utils"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/triggers/threadCreate.ts b/backend/src/plugins/Automod/triggers/threadCreate.ts index 1e8a23e6..827f151d 100644 --- a/backend/src/plugins/Automod/triggers/threadCreate.ts +++ b/backend/src/plugins/Automod/triggers/threadCreate.ts @@ -1,4 +1,4 @@ -import { User, escapeBold, type Snowflake } from "discord.js"; +import { escapeBold, type Snowflake, User } from "discord.js"; import z from "zod"; import { renderUsername } from "../../../utils.js"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/triggers/threadDelete.ts b/backend/src/plugins/Automod/triggers/threadDelete.ts index 8c6d07d7..f8b907e0 100644 --- a/backend/src/plugins/Automod/triggers/threadDelete.ts +++ b/backend/src/plugins/Automod/triggers/threadDelete.ts @@ -1,4 +1,4 @@ -import { User, escapeBold, type Snowflake } from "discord.js"; +import { escapeBold, type Snowflake, User } from "discord.js"; import z from "zod"; import { renderUsername } from "../../../utils.js"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/triggers/threadUnarchive.ts b/backend/src/plugins/Automod/triggers/threadUnarchive.ts index 7eb7bf07..9e12d50d 100644 --- a/backend/src/plugins/Automod/triggers/threadUnarchive.ts +++ b/backend/src/plugins/Automod/triggers/threadUnarchive.ts @@ -1,4 +1,4 @@ -import { User, escapeBold, type Snowflake } from "discord.js"; +import { escapeBold, type Snowflake, User } from "discord.js"; import z from "zod"; import { renderUsername } from "../../../utils"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/types.ts b/backend/src/plugins/Automod/types.ts index 6cf88ad6..5214b8bb 100644 --- a/backend/src/plugins/Automod/types.ts +++ b/backend/src/plugins/Automod/types.ts @@ -10,12 +10,11 @@ import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { SavedMessage } from "../../data/entities/SavedMessage"; import { entries, zBoundedRecord, zDelayString } from "../../utils"; import { CounterEvents } from "../Counters/types"; -import { ModActionType, ModActionsEvents } from "../ModActions/types"; +import { ModActionsEvents, ModActionType } from "../ModActions/types"; import { MutesEvents } from "../Mutes/types"; import { availableActions } from "./actions/availableActions"; import { RecentActionType } from "./constants"; import { availableTriggers } from "./triggers/availableTriggers"; - import Timeout = NodeJS.Timeout; export type ZTriggersMapHelper = { diff --git a/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts b/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts index 11d3a487..f4f6a016 100644 --- a/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts @@ -1,6 +1,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils"; import { botControlCmd } from "../types"; +import { TextBasedChannelFields } from "discord.js"; export const ChannelToServerCmd = botControlCmd({ trigger: ["channel_to_server", "channel2server"], @@ -16,7 +17,7 @@ export const ChannelToServerCmd = botControlCmd({ async run({ pluginData, message: msg, args }) { const channel = pluginData.client.channels.cache.get(args.channelId); if (!channel) { - sendErrorMessage(pluginData, msg.channel, "Channel not found in cache!"); + await sendErrorMessage(pluginData, msg.channel, "Channel not found in cache!"); return; } @@ -25,6 +26,8 @@ export const ChannelToServerCmd = botControlCmd({ const guild = "guild" in channel ? channel.guild : null; const guildInfo = guild ? `${guild.name} (\`${guild.id}\`)` : "Not a server"; - msg.channel.send(`**Channel:** ${channelName} (\`${channel.type}\`) (<#${channel.id}>)\n**Server:** ${guildInfo}`); + await (msg.channel as TextBasedChannelFields).send( + `**Channel:** ${channelName} (\`${channel.type}\`) (<#${channel.id}>)\n**Server:** ${guildInfo}`, + ); }, }); diff --git a/backend/src/plugins/BotControl/commands/ProfilerDataCmd.ts b/backend/src/plugins/BotControl/commands/ProfilerDataCmd.ts index 3b5a177f..be39d3c2 100644 --- a/backend/src/plugins/BotControl/commands/ProfilerDataCmd.ts +++ b/backend/src/plugins/BotControl/commands/ProfilerDataCmd.ts @@ -4,6 +4,7 @@ import { GuildArchives } from "../../../data/GuildArchives"; import { getBaseUrl } from "../../../pluginUtils"; import { sorter } from "../../../utils"; import { botControlCmd } from "../types"; +import { TextBasedChannelFields } from "discord.js"; const sortProps = { totalTime: "TOTAL TIME", @@ -51,6 +52,6 @@ export const ProfilerDataCmd = botControlCmd({ const archiveId = await archives.create(formatted, moment().add(1, "hour")); const archiveUrl = archives.getUrl(getBaseUrl(pluginData), archiveId); - msg.channel.send(`Link: ${archiveUrl}`); + await (msg.channel as TextBasedChannelFields).send(`Link: ${archiveUrl}`); }, }); diff --git a/backend/src/plugins/BotControl/commands/RateLimitPerformanceCmd.ts b/backend/src/plugins/BotControl/commands/RateLimitPerformanceCmd.ts index 46d2a0e0..0bb74c4f 100644 --- a/backend/src/plugins/BotControl/commands/RateLimitPerformanceCmd.ts +++ b/backend/src/plugins/BotControl/commands/RateLimitPerformanceCmd.ts @@ -3,6 +3,7 @@ import { GuildArchives } from "../../../data/GuildArchives"; import { getBaseUrl, sendSuccessMessage } from "../../../pluginUtils"; import { getRateLimitStats } from "../../../rateLimitStats"; import { botControlCmd } from "../types"; +import { TextBasedChannelFields } from "discord.js"; export const RateLimitPerformanceCmd = botControlCmd({ trigger: ["rate_limit_performance"], @@ -34,6 +35,6 @@ export const RateLimitPerformanceCmd = botControlCmd({ const archives = GuildArchives.getGuildInstance("0"); const archiveId = await archives.create(fullText, moment().add(1, "hour")); const archiveUrl = archives.getUrl(getBaseUrl(pluginData), archiveId); - msg.channel.send(`Link: ${archiveUrl}`); + await (msg.channel as TextBasedChannelFields).send(`Link: ${archiveUrl}`); }, }); diff --git a/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts b/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts index 4f59f8a2..2a548977 100644 --- a/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts +++ b/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts @@ -1,6 +1,7 @@ import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils"; import { getActiveReload, setActiveReload } from "../activeReload"; import { botControlCmd } from "../types"; +import { TextBasedChannelFields } from "discord.js"; export const ReloadGlobalPluginsCmd = botControlCmd({ trigger: "bot_reload_global_plugins", @@ -14,13 +15,13 @@ export const ReloadGlobalPluginsCmd = botControlCmd({ const guildId = "guild" in message.channel ? message.channel.guild.id : null; if (!guildId) { - sendErrorMessage(pluginData, message.channel, "This command can only be used in a server"); + await sendErrorMessage(pluginData, message.channel, "This command can only be used in a server"); return; } setActiveReload(guildId, message.channel.id); - await message.channel.send("Reloading global plugins..."); + await (message.channel as TextBasedChannelFields).send("Reloading global plugins..."); - pluginData.getKnubInstance().reloadGlobalContext(); + await pluginData.getKnubInstance().reloadGlobalContext(); }, }); diff --git a/backend/src/plugins/BotControl/commands/RestPerformanceCmd.ts b/backend/src/plugins/BotControl/commands/RestPerformanceCmd.ts index 0c8c6e8e..89967571 100644 --- a/backend/src/plugins/BotControl/commands/RestPerformanceCmd.ts +++ b/backend/src/plugins/BotControl/commands/RestPerformanceCmd.ts @@ -2,6 +2,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { getTopRestCallStats } from "../../../restCallStats"; import { createChunkedMessage } from "../../../utils"; import { botControlCmd } from "../types"; +import { TextChannel } from "discord.js"; const leadingPathRegex = /(?<=\().+\/backend\//g; @@ -20,6 +21,6 @@ export const RestPerformanceCmd = botControlCmd({ const cleanSource = callStats.source.replace(leadingPathRegex, ""); return `**${callStats.count} calls**\n${callStats.method.toUpperCase()} ${callStats.path}\n${cleanSource}`; }); - createChunkedMessage(msg.channel, `Top rest calls:\n\n${formatted.join("\n")}`); + await createChunkedMessage(msg.channel as TextChannel, `Top rest calls:\n\n${formatted.join("\n")}`); }, }); diff --git a/backend/src/plugins/BotControl/commands/ServersCmd.ts b/backend/src/plugins/BotControl/commands/ServersCmd.ts index 5b2cf9c7..b3f0de34 100644 --- a/backend/src/plugins/BotControl/commands/ServersCmd.ts +++ b/backend/src/plugins/BotControl/commands/ServersCmd.ts @@ -3,6 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { isStaffPreFilter } from "../../../pluginUtils"; import { createChunkedMessage, getUser, renderUsername, sorter } from "../../../utils"; import { botControlCmd } from "../types"; +import { TextBasedChannelFields, TextChannel } from "discord.js"; export const ServersCmd = botControlCmd({ trigger: ["servers", "guilds"], @@ -52,16 +53,16 @@ export const ServersCmd = botControlCmd({ owner.id }\`)`; }); - createChunkedMessage(msg.channel, lines.join("\n")); + await createChunkedMessage(msg.channel as TextChannel, lines.join("\n")); } else { - msg.channel.send("No servers matched the filters"); + await (msg.channel as TextBasedChannelFields).send("No servers matched the filters"); } } else { const total = joinedGuilds.length; const initialized = joinedGuilds.filter((g) => loadedGuildsMap.has(g.id)).length; const unInitialized = total - initialized; - msg.channel.send( + await (msg.channel as TextBasedChannelFields).send( `I am on **${total} total servers**, of which **${initialized} are initialized** and **${unInitialized} are not initialized**`, ); } diff --git a/backend/src/plugins/Cases/functions/createCaseNote.ts b/backend/src/plugins/Cases/functions/createCaseNote.ts index 71b11302..328a943b 100644 --- a/backend/src/plugins/Cases/functions/createCaseNote.ts +++ b/backend/src/plugins/Cases/functions/createCaseNote.ts @@ -1,6 +1,6 @@ import { GuildPluginData } from "knub"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; -import { UnknownUser, renderUsername, resolveUser } from "../../../utils"; +import { renderUsername, resolveUser, UnknownUser } from "../../../utils"; import { CaseNoteArgs, CasesPluginType } from "../types"; import { postCaseToCaseLogChannel } from "./postToCaseLogChannel"; import { resolveCaseId } from "./resolveCaseId"; diff --git a/backend/src/plugins/Censor/CensorPlugin.ts b/backend/src/plugins/Censor/CensorPlugin.ts index 45e7a52e..0b1d62cb 100644 --- a/backend/src/plugins/Censor/CensorPlugin.ts +++ b/backend/src/plugins/Censor/CensorPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners"; diff --git a/backend/src/plugins/Censor/util/applyFiltersToMsg.ts b/backend/src/plugins/Censor/util/applyFiltersToMsg.ts index 65ad62ed..28c826be 100644 --- a/backend/src/plugins/Censor/util/applyFiltersToMsg.ts +++ b/backend/src/plugins/Censor/util/applyFiltersToMsg.ts @@ -5,7 +5,14 @@ import cloneDeep from "lodash.clonedeep"; import { allowTimeout } from "../../../RegExpRunner"; import { ZalgoRegex } from "../../../data/Zalgo"; import { SavedMessage } from "../../../data/entities/SavedMessage"; -import { getInviteCodesInString, getUrlsInString, isGuildInvite, resolveInvite, resolveMember } from "../../../utils"; +import { + getInviteCodesInString, + getUrlsInString, + isGuildInvite, + resolveInvite, + resolveMember, + zSnowflake, +} from "../../../utils"; import { CensorPluginType } from "../types"; import { censorMessage } from "./censorMessage"; @@ -58,18 +65,18 @@ export async function applyFiltersToMsg( for (const invite of invites) { // Always filter unknown invites if invite filtering is enabled if (invite == null) { - censorMessage(pluginData, savedMessage, `unknown invite not found in whitelist`); + await censorMessage(pluginData, savedMessage, `unknown invite not found in whitelist`); return true; } if (!isGuildInvite(invite) && !allowGroupDMInvites) { - censorMessage(pluginData, savedMessage, `group dm invites are not allowed`); + await censorMessage(pluginData, savedMessage, `group dm invites are not allowed`); return true; } if (isGuildInvite(invite)) { - if (inviteGuildWhitelist && !inviteGuildWhitelist.includes(invite.guild!.id)) { - censorMessage( + if (inviteGuildWhitelist && !inviteGuildWhitelist.includes(await zSnowflake.parseAsync(invite.guild!.id))) { + await censorMessage( pluginData, savedMessage, `invite guild (**${invite.guild!.name}** \`${invite.guild!.id}\`) not found in whitelist`, @@ -77,8 +84,8 @@ export async function applyFiltersToMsg( return true; } - if (inviteGuildBlacklist && inviteGuildBlacklist.includes(invite.guild!.id)) { - censorMessage( + if (inviteGuildBlacklist && inviteGuildBlacklist.includes(await zSnowflake.parseAsync(invite.guild!.id))) { + await censorMessage( pluginData, savedMessage, `invite guild (**${invite.guild!.name}** \`${invite.guild!.id}\`) found in blacklist`, diff --git a/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts b/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts index e2a9a2a2..137bb6f0 100644 --- a/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts +++ b/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts @@ -2,7 +2,7 @@ import { Snowflake } from "discord.js"; import moment from "moment-timezone"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { isOwner, sendErrorMessage } from "../../../pluginUtils"; -import { SECONDS, confirm, noop, renderUsername } from "../../../utils"; +import { confirm, noop, renderUsername, SECONDS } from "../../../utils"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { rehostAttachment } from "../rehostAttachment"; import { channelArchiverCmd } from "../types"; diff --git a/backend/src/plugins/ChannelArchiver/rehostAttachment.ts b/backend/src/plugins/ChannelArchiver/rehostAttachment.ts index 8159ddb2..3c74c3af 100644 --- a/backend/src/plugins/ChannelArchiver/rehostAttachment.ts +++ b/backend/src/plugins/ChannelArchiver/rehostAttachment.ts @@ -1,6 +1,7 @@ import { Attachment, GuildTextBasedChannel, MessageCreateOptions } from "discord.js"; import fs from "fs"; import { downloadFile } from "../../utils"; + const fsp = fs.promises; const MAX_ATTACHMENT_REHOST_SIZE = 1024 * 1024 * 8; diff --git a/backend/src/plugins/CompanionChannels/functions/getCompanionChannelOptsForVoiceChannelId.ts b/backend/src/plugins/CompanionChannels/functions/getCompanionChannelOptsForVoiceChannelId.ts index 8ecde5e7..bb28cdfa 100644 --- a/backend/src/plugins/CompanionChannels/functions/getCompanionChannelOptsForVoiceChannelId.ts +++ b/backend/src/plugins/CompanionChannels/functions/getCompanionChannelOptsForVoiceChannelId.ts @@ -1,6 +1,7 @@ import { StageChannel, VoiceChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types"; +import { zSnowflake } from "../../../utils"; const defaultCompanionChannelOpts: Partial = { enabled: true, @@ -15,8 +16,8 @@ export async function getCompanionChannelOptsForVoiceChannelId( return Object.values(config.entries) .filter( (opts) => - opts.voice_channel_ids.includes(voiceChannel.id) || - (voiceChannel.parentId && opts.voice_channel_ids.includes(voiceChannel.parentId)), + opts.voice_channel_ids.includes(zSnowflake.parse(voiceChannel.id)) || + (voiceChannel.parentId && opts.voice_channel_ids.includes(zSnowflake.parse(voiceChannel.parentId))), ) .map((opts) => Object.assign({}, defaultCompanionChannelOpts, opts)); } diff --git a/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts b/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts index 6be8ffe1..f8738305 100644 --- a/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts +++ b/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts @@ -1,7 +1,7 @@ import { PermissionsBitField, Snowflake, StageChannel, TextChannel, VoiceChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { LogType } from "../../../data/LogType"; -import { MINUTES, isDiscordAPIError } from "../../../utils"; +import { isDiscordAPIError, MINUTES } from "../../../utils"; import { filterObject } from "../../../utils/filterObject"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types"; diff --git a/backend/src/plugins/ContextMenus/ContextMenuPlugin.ts b/backend/src/plugins/ContextMenus/ContextMenuPlugin.ts index 8c6cbdae..1f954d37 100644 --- a/backend/src/plugins/ContextMenus/ContextMenuPlugin.ts +++ b/backend/src/plugins/ContextMenus/ContextMenuPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks"; import { LogsPlugin } from "../Logs/LogsPlugin"; import { MutesPlugin } from "../Mutes/MutesPlugin"; diff --git a/backend/src/plugins/Counters/CountersPlugin.ts b/backend/src/plugins/Counters/CountersPlugin.ts index ed1b2d8a..f6f15def 100644 --- a/backend/src/plugins/Counters/CountersPlugin.ts +++ b/backend/src/plugins/Counters/CountersPlugin.ts @@ -1,9 +1,8 @@ -import { EventEmitter } from "events"; -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildCounters } from "../../data/GuildCounters"; import { CounterTrigger, parseCounterConditionString } from "../../data/entities/CounterTrigger"; import { makePublicFn } from "../../pluginUtils"; -import { MINUTES, convertDelayStringToMS, values } from "../../utils"; +import { convertDelayStringToMS, MINUTES, values } from "../../utils"; import { AddCounterCmd } from "./commands/AddCounterCmd"; import { CountersListCmd } from "./commands/CountersListCmd"; import { ResetAllCounterValuesCmd } from "./commands/ResetAllCounterValuesCmd"; @@ -19,6 +18,7 @@ import { offCounterEvent } from "./functions/offCounterEvent"; import { onCounterEvent } from "./functions/onCounterEvent"; import { setCounterValue } from "./functions/setCounterValue"; import { CountersPluginType, zCountersConfig } from "./types"; +import { EventEmitter } from "events"; const DECAY_APPLY_INTERVAL = 5 * MINUTES; diff --git a/backend/src/plugins/Counters/commands/AddCounterCmd.ts b/backend/src/plugins/Counters/commands/AddCounterCmd.ts index a71418df..ac8c3698 100644 --- a/backend/src/plugins/Counters/commands/AddCounterCmd.ts +++ b/backend/src/plugins/Counters/commands/AddCounterCmd.ts @@ -3,7 +3,7 @@ import { guildPluginMessageCommand } from "knub"; import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { changeCounterValue } from "../functions/changeCounterValue"; import { CountersPluginType } from "../types"; diff --git a/backend/src/plugins/Counters/commands/ResetCounterCmd.ts b/backend/src/plugins/Counters/commands/ResetCounterCmd.ts index 00c91eb7..21191abf 100644 --- a/backend/src/plugins/Counters/commands/ResetCounterCmd.ts +++ b/backend/src/plugins/Counters/commands/ResetCounterCmd.ts @@ -3,7 +3,7 @@ import { guildPluginMessageCommand } from "knub"; import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { setCounterValue } from "../functions/setCounterValue"; import { CountersPluginType } from "../types"; diff --git a/backend/src/plugins/Counters/commands/SetCounterCmd.ts b/backend/src/plugins/Counters/commands/SetCounterCmd.ts index ba6fbc3a..98ffcc9b 100644 --- a/backend/src/plugins/Counters/commands/SetCounterCmd.ts +++ b/backend/src/plugins/Counters/commands/SetCounterCmd.ts @@ -3,7 +3,7 @@ import { guildPluginMessageCommand } from "knub"; import { waitForReply } from "knub/helpers"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { setCounterValue } from "../functions/setCounterValue"; import { CountersPluginType } from "../types"; diff --git a/backend/src/plugins/Counters/types.ts b/backend/src/plugins/Counters/types.ts index ef322e7b..0176b33f 100644 --- a/backend/src/plugins/Counters/types.ts +++ b/backend/src/plugins/Counters/types.ts @@ -3,8 +3,8 @@ import { BasePluginType } from "knub"; import z from "zod"; import { GuildCounters, MAX_COUNTER_VALUE, MIN_COUNTER_VALUE } from "../../data/GuildCounters"; import { - CounterTrigger, buildCounterConditionString, + CounterTrigger, getReverseCounterComparisonOp, parseCounterConditionString, } from "../../data/entities/CounterTrigger"; diff --git a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts index f85036a1..ef3f387d 100644 --- a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts +++ b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts @@ -2,7 +2,7 @@ import { GuildChannel, GuildMember, User } from "discord.js"; import { guildPlugin, guildPluginMessageCommand, parseSignature } from "knub"; import { TSignature } from "knub-command-manager"; import { commandTypes } from "../../commandTypes"; -import { TemplateSafeValueContainer, createTypedTemplateSafeValueContainer } from "../../templateFormatter"; +import { createTypedTemplateSafeValueContainer, TemplateSafeValueContainer } from "../../templateFormatter"; import { UnknownUser } from "../../utils"; import { isScalar } from "../../utils/isScalar"; import { diff --git a/backend/src/plugins/CustomEvents/actions/messageAction.ts b/backend/src/plugins/CustomEvents/actions/messageAction.ts index 27780265..a7d6e839 100644 --- a/backend/src/plugins/CustomEvents/actions/messageAction.ts +++ b/backend/src/plugins/CustomEvents/actions/messageAction.ts @@ -1,7 +1,7 @@ import { Snowflake, TextChannel } from "discord.js"; import { GuildPluginData } from "knub"; import z from "zod"; -import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { zBoundedCharacters, zSnowflake } from "../../../utils"; import { ActionError } from "../ActionError"; import { catchTemplateError } from "../catchTemplateError"; diff --git a/backend/src/plugins/CustomEvents/actions/moveToVoiceChannelAction.ts b/backend/src/plugins/CustomEvents/actions/moveToVoiceChannelAction.ts index 40adcb58..08f74221 100644 --- a/backend/src/plugins/CustomEvents/actions/moveToVoiceChannelAction.ts +++ b/backend/src/plugins/CustomEvents/actions/moveToVoiceChannelAction.ts @@ -2,7 +2,7 @@ import { Snowflake, VoiceChannel } from "discord.js"; import { GuildPluginData } from "knub"; import z from "zod"; import { canActOn } from "../../../pluginUtils"; -import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { resolveMember, zSnowflake } from "../../../utils"; import { ActionError } from "../ActionError"; import { catchTemplateError } from "../catchTemplateError"; diff --git a/backend/src/plugins/GuildAccessMonitor/GuildAccessMonitorPlugin.ts b/backend/src/plugins/GuildAccessMonitor/GuildAccessMonitorPlugin.ts index c0319b55..a72aee26 100644 --- a/backend/src/plugins/GuildAccessMonitor/GuildAccessMonitorPlugin.ts +++ b/backend/src/plugins/GuildAccessMonitor/GuildAccessMonitorPlugin.ts @@ -1,5 +1,5 @@ import { Guild } from "discord.js"; -import { BasePluginType, GlobalPluginData, globalPlugin, globalPluginEventListener } from "knub"; +import { BasePluginType, globalPlugin, GlobalPluginData, globalPluginEventListener } from "knub"; import z from "zod"; import { AllowedGuilds } from "../../data/AllowedGuilds"; import { Configs } from "../../data/Configs"; diff --git a/backend/src/plugins/InternalPoster/InternalPosterPlugin.ts b/backend/src/plugins/InternalPoster/InternalPosterPlugin.ts index ae01bb64..8c9ddc2e 100644 --- a/backend/src/plugins/InternalPoster/InternalPosterPlugin.ts +++ b/backend/src/plugins/InternalPoster/InternalPosterPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import z from "zod"; import { Queue } from "../../Queue"; import { Webhooks } from "../../data/Webhooks"; diff --git a/backend/src/plugins/LocateUser/LocateUserPlugin.ts b/backend/src/plugins/LocateUser/LocateUserPlugin.ts index 3fb8f841..0b773bdb 100644 --- a/backend/src/plugins/LocateUser/LocateUserPlugin.ts +++ b/backend/src/plugins/LocateUser/LocateUserPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { onGuildEvent } from "../../data/GuildEvents"; import { GuildVCAlerts } from "../../data/GuildVCAlerts"; import { FollowCmd } from "./commands/FollowCmd"; diff --git a/backend/src/plugins/LocateUser/commands/ListFollowCmd.ts b/backend/src/plugins/LocateUser/commands/ListFollowCmd.ts index d598d8a9..c2654166 100644 --- a/backend/src/plugins/LocateUser/commands/ListFollowCmd.ts +++ b/backend/src/plugins/LocateUser/commands/ListFollowCmd.ts @@ -3,6 +3,7 @@ import { clearExpiringVCAlert } from "../../../data/loops/expiringVCAlertsLoop"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { createChunkedMessage, sorter } from "../../../utils"; import { locateUserCmd } from "../types"; +import { TextChannel } from "discord.js"; export const ListFollowCmd = locateUserCmd({ trigger: ["follows", "fs"], @@ -13,7 +14,7 @@ export const ListFollowCmd = locateUserCmd({ async run({ message: msg, pluginData }) { const alerts = await pluginData.state.alerts.getAlertsByRequestorId(msg.member.id); if (alerts.length === 0) { - sendErrorMessage(pluginData, msg.channel, "You have no active alerts!"); + await sendErrorMessage(pluginData, msg.channel, "You have no active alerts!"); return; } @@ -26,7 +27,7 @@ export const ListFollowCmd = locateUserCmd({ alert.body }\` **Active:** ${alert.active.valueOf()}`; }); - await createChunkedMessage(msg.channel, lines.join("\n")); + await createChunkedMessage(msg.channel as TextChannel, lines.join("\n")); }, }); diff --git a/backend/src/plugins/Logs/LogsPlugin.ts b/backend/src/plugins/Logs/LogsPlugin.ts index 62a6de4d..e3bd39aa 100644 --- a/backend/src/plugins/Logs/LogsPlugin.ts +++ b/backend/src/plugins/Logs/LogsPlugin.ts @@ -1,4 +1,4 @@ -import { CooldownManager, PluginOptions, guildPlugin } from "knub"; +import { CooldownManager, guildPlugin, PluginOptions } from "knub"; import DefaultLogMessages from "../../data/DefaultLogMessages.json"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildCases } from "../../data/GuildCases"; diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index 5a9259d6..40794928 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -3,7 +3,7 @@ import { GuildPluginData } from "knub"; import { allowTimeout } from "../../../RegExpRunner"; import { LogType } from "../../../data/LogType"; import { TypedTemplateSafeValueContainer } from "../../../templateFormatter"; -import { MINUTES, isDiscordAPIError } from "../../../utils"; +import { isDiscordAPIError, MINUTES, zSnowflake } from "../../../utils"; import { MessageBuffer } from "../../../utils/MessageBuffer"; import { InternalPosterPlugin } from "../../InternalPoster/InternalPosterPlugin"; import { ILogTypeData, LogsPluginType, TLogChannel, TLogChannelMap } from "../types"; @@ -28,7 +28,11 @@ async function shouldExclude( opts: TLogChannel, exclusionData: ExclusionData, ): Promise { - if (opts.excluded_users && exclusionData.userId && opts.excluded_users.includes(exclusionData.userId)) { + if ( + opts.excluded_users && + exclusionData.userId && + opts.excluded_users.includes(zSnowflake.parse(exclusionData.userId)) + ) { return true; } @@ -38,21 +42,33 @@ async function shouldExclude( if (opts.excluded_roles && exclusionData.roles) { for (const role of exclusionData.roles) { - if (opts.excluded_roles.includes(role)) { + if (opts.excluded_roles.includes(await zSnowflake.parseAsync(role))) { return true; } } } - if (opts.excluded_channels && exclusionData.channel && opts.excluded_channels.includes(exclusionData.channel)) { + if ( + opts.excluded_channels && + exclusionData.channel && + opts.excluded_channels.includes(await zSnowflake.parseAsync(exclusionData.channel)) + ) { return true; } - if (opts.excluded_categories && exclusionData.category && opts.excluded_categories.includes(exclusionData.category)) { + if ( + opts.excluded_categories && + exclusionData.category && + opts.excluded_categories.includes(await zSnowflake.parseAsync(exclusionData.category)) + ) { return true; } - if (opts.excluded_threads && exclusionData.thread && opts.excluded_threads.includes(exclusionData.thread)) { + if ( + opts.excluded_threads && + exclusionData.thread && + opts.excluded_threads.includes(await zSnowflake.parseAsync(exclusionData.thread)) + ) { return true; } @@ -83,20 +99,20 @@ export async function log( const channel = pluginData.guild.channels.cache.get(channelId as Snowflake); if (!channel?.isTextBased()) continue; if (pluginData.state.channelCooldowns.isOnCooldown(channelId)) continue; - if (opts.include?.length && !opts.include.includes(typeStr)) continue; - if (opts.exclude && opts.exclude.includes(typeStr)) continue; - if (await shouldExclude(pluginData, opts, exclusionData)) continue; + if (opts!.include?.length && !opts!.include.includes(typeStr)) continue; + if (opts!.exclude && opts!.exclude.includes(typeStr)) continue; + if (await shouldExclude(pluginData, opts!, exclusionData)) continue; const message = await getLogMessage(pluginData, type, data, { - format: opts.format, - include_embed_timestamp: opts.include_embed_timestamp, - timestamp_format: opts.timestamp_format, + format: opts!.format, + include_embed_timestamp: opts!.include_embed_timestamp, + timestamp_format: opts!.timestamp_format, }); if (!message) return; // Initialize message buffer for this channel if (!pluginData.state.buffers.has(channelId)) { - const batchTime = Math.min(Math.max(opts.batch_time ?? DEFAULT_BATCH_TIME, MIN_BATCH_TIME), MAX_BATCH_TIME); + const batchTime = Math.min(Math.max(opts!.batch_time ?? DEFAULT_BATCH_TIME, MIN_BATCH_TIME), MAX_BATCH_TIME); const internalPosterPlugin = pluginData.getPlugin(InternalPosterPlugin); pluginData.state.buffers.set( channelId, diff --git a/backend/src/plugins/MessageSaver/MessageSaverPlugin.ts b/backend/src/plugins/MessageSaver/MessageSaverPlugin.ts index 4c960904..e6b4e6d7 100644 --- a/backend/src/plugins/MessageSaver/MessageSaverPlugin.ts +++ b/backend/src/plugins/MessageSaver/MessageSaverPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB"; import { SavePinsToDBCmd } from "./commands/SavePinsToDB"; diff --git a/backend/src/plugins/ModActions/ModActionsPlugin.ts b/backend/src/plugins/ModActions/ModActionsPlugin.ts index 2e92961f..0f658bbc 100644 --- a/backend/src/plugins/ModActions/ModActionsPlugin.ts +++ b/backend/src/plugins/ModActions/ModActionsPlugin.ts @@ -1,5 +1,4 @@ import { Message } from "discord.js"; -import { EventEmitter } from "events"; import { guildPlugin } from "knub"; import { Queue } from "../../Queue"; import { GuildCases } from "../../data/GuildCases"; @@ -48,6 +47,7 @@ import { onModActionsEvent } from "./functions/onModActionsEvent"; import { updateCase } from "./functions/updateCase"; import { warnMember } from "./functions/warnMember"; import { ModActionsPluginType, zModActionsConfig } from "./types"; +import { EventEmitter } from "events"; const defaultOptions = { config: { diff --git a/backend/src/plugins/ModActions/commands/CasesModCmd.ts b/backend/src/plugins/ModActions/commands/CasesModCmd.ts index 306c1ad1..aab30ba2 100644 --- a/backend/src/plugins/ModActions/commands/CasesModCmd.ts +++ b/backend/src/plugins/ModActions/commands/CasesModCmd.ts @@ -1,7 +1,7 @@ import { APIEmbed } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { UnknownUser, emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines } from "../../../utils"; +import { emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines, UnknownUser } from "../../../utils"; import { asyncMap } from "../../../utils/async"; import { createPaginatedMessage } from "../../../utils/createPaginatedMessage"; import { getGuildPrefix } from "../../../utils/getGuildPrefix"; diff --git a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts index 08e586c8..77746a21 100644 --- a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts +++ b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts @@ -3,7 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { CaseTypes } from "../../../data/CaseTypes"; import { sendErrorMessage } from "../../../pluginUtils"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; -import { UnknownUser, chunkArray, emptyEmbedValue, renderUsername, resolveMember, resolveUser } from "../../../utils"; +import { chunkArray, emptyEmbedValue, renderUsername, resolveMember, resolveUser, UnknownUser } from "../../../utils"; import { asyncMap } from "../../../utils/async"; import { createPaginatedMessage } from "../../../utils/createPaginatedMessage.js"; import { getGuildPrefix } from "../../../utils/getGuildPrefix"; diff --git a/backend/src/plugins/ModActions/commands/DeleteCaseCmd.ts b/backend/src/plugins/ModActions/commands/DeleteCaseCmd.ts index c107791d..4909caa6 100644 --- a/backend/src/plugins/ModActions/commands/DeleteCaseCmd.ts +++ b/backend/src/plugins/ModActions/commands/DeleteCaseCmd.ts @@ -2,7 +2,7 @@ import { helpers } from "knub"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { Case } from "../../../data/entities/Case"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; -import { SECONDS, renderUsername, trimLines } from "../../../utils"; +import { renderUsername, SECONDS, trimLines } from "../../../utils"; import { CasesPlugin } from "../../Cases/CasesPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; diff --git a/backend/src/plugins/ModActions/commands/MassBanCmd.ts b/backend/src/plugins/ModActions/commands/MassBanCmd.ts index d31aadd7..0108389f 100644 --- a/backend/src/plugins/ModActions/commands/MassBanCmd.ts +++ b/backend/src/plugins/ModActions/commands/MassBanCmd.ts @@ -7,7 +7,7 @@ import { LogType } from "../../../data/LogType"; import { humanizeDurationShort } from "../../../humanizeDurationShort"; import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; -import { DAYS, MINUTES, SECONDS, noop } from "../../../utils"; +import { DAYS, MINUTES, noop, SECONDS } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { ignoreEvent } from "../functions/ignoreEvent"; diff --git a/backend/src/plugins/ModActions/events/CreateBanCaseOnManualBanEvt.ts b/backend/src/plugins/ModActions/events/CreateBanCaseOnManualBanEvt.ts index 237454ba..929c1e25 100644 --- a/backend/src/plugins/ModActions/events/CreateBanCaseOnManualBanEvt.ts +++ b/backend/src/plugins/ModActions/events/CreateBanCaseOnManualBanEvt.ts @@ -1,7 +1,7 @@ import { AuditLogEvent, User } from "discord.js"; import { CaseTypes } from "../../../data/CaseTypes"; import { Case } from "../../../data/entities/Case"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { CasesPlugin } from "../../Cases/CasesPlugin"; diff --git a/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts b/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts index 0f840910..d03d3763 100644 --- a/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts +++ b/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts @@ -2,7 +2,7 @@ import { AuditLogEvent, User } from "discord.js"; import { CaseTypes } from "../../../data/CaseTypes"; import { Case } from "../../../data/entities/Case"; import { logger } from "../../../logger"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry"; import { CasesPlugin } from "../../Cases/CasesPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin"; diff --git a/backend/src/plugins/ModActions/events/CreateUnbanCaseOnManualUnbanEvt.ts b/backend/src/plugins/ModActions/events/CreateUnbanCaseOnManualUnbanEvt.ts index 9400c732..e6e8fbb3 100644 --- a/backend/src/plugins/ModActions/events/CreateUnbanCaseOnManualUnbanEvt.ts +++ b/backend/src/plugins/ModActions/events/CreateUnbanCaseOnManualUnbanEvt.ts @@ -1,7 +1,7 @@ import { AuditLogEvent, User } from "discord.js"; import { CaseTypes } from "../../../data/CaseTypes"; import { Case } from "../../../data/entities/Case"; -import { UnknownUser, resolveUser } from "../../../utils"; +import { resolveUser, UnknownUser } from "../../../utils"; import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry"; import { CasesPlugin } from "../../Cases/CasesPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin"; diff --git a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts index a755ee08..76732899 100644 --- a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts @@ -3,7 +3,7 @@ import { GuildPluginData } from "knub"; import { hasPermission } from "knub/helpers"; import { LogType } from "../../../data/LogType"; import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; -import { DAYS, SECONDS, errorMessage, renderUsername, resolveMember, resolveUser } from "../../../utils"; +import { DAYS, errorMessage, renderUsername, resolveMember, resolveUser, SECONDS } from "../../../utils"; import { IgnoredEventType, ModActionsPluginType } from "../types"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; import { ignoreEvent } from "./ignoreEvent"; diff --git a/backend/src/plugins/ModActions/functions/actualMuteUserCmd.ts b/backend/src/plugins/ModActions/functions/actualMuteUserCmd.ts index 2f108410..26f7b55d 100644 --- a/backend/src/plugins/ModActions/functions/actualMuteUserCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualMuteUserCmd.ts @@ -4,7 +4,7 @@ import { GuildPluginData } from "knub"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; import { logger } from "../../../logger"; import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; -import { UnknownUser, asSingleLine, isDiscordAPIError, renderUsername } from "../../../utils"; +import { asSingleLine, isDiscordAPIError, renderUsername, UnknownUser } from "../../../utils"; import { MutesPlugin } from "../../Mutes/MutesPlugin"; import { MuteResult } from "../../Mutes/types"; import { ModActionsPluginType } from "../types"; diff --git a/backend/src/plugins/ModActions/functions/actualUnmuteUserCmd.ts b/backend/src/plugins/ModActions/functions/actualUnmuteUserCmd.ts index 5b28aee7..5dd268a5 100644 --- a/backend/src/plugins/ModActions/functions/actualUnmuteUserCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualUnmuteUserCmd.ts @@ -3,7 +3,7 @@ import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin"; -import { UnknownUser, asSingleLine, renderUsername } from "../../../utils"; +import { asSingleLine, renderUsername, UnknownUser } from "../../../utils"; import { ModActionsPluginType } from "../types"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; diff --git a/backend/src/plugins/ModActions/functions/banUserId.ts b/backend/src/plugins/ModActions/functions/banUserId.ts index 65686c81..b5242293 100644 --- a/backend/src/plugins/ModActions/functions/banUserId.ts +++ b/backend/src/plugins/ModActions/functions/banUserId.ts @@ -5,16 +5,16 @@ import { CaseTypes } from "../../../data/CaseTypes"; import { LogType } from "../../../data/LogType"; import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop"; import { logger } from "../../../logger"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; import { - DAYS, - SECONDS, - UserNotificationResult, createUserNotificationError, + DAYS, notifyUser, resolveMember, resolveUser, + SECONDS, ucfirst, + UserNotificationResult, } from "../../../utils"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { CasesPlugin } from "../../Cases/CasesPlugin"; diff --git a/backend/src/plugins/ModActions/functions/isBanned.ts b/backend/src/plugins/ModActions/functions/isBanned.ts index 50dc4823..839adf8d 100644 --- a/backend/src/plugins/ModActions/functions/isBanned.ts +++ b/backend/src/plugins/ModActions/functions/isBanned.ts @@ -1,6 +1,6 @@ import { PermissionsBitField, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; -import { SECONDS, isDiscordAPIError, isDiscordHTTPError, sleep } from "../../../utils"; +import { isDiscordAPIError, isDiscordHTTPError, SECONDS, sleep } from "../../../utils"; import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { ModActionsPluginType } from "../types"; diff --git a/backend/src/plugins/ModActions/functions/warnMember.ts b/backend/src/plugins/ModActions/functions/warnMember.ts index 9aba15f4..8264ae4c 100644 --- a/backend/src/plugins/ModActions/functions/warnMember.ts +++ b/backend/src/plugins/ModActions/functions/warnMember.ts @@ -1,8 +1,8 @@ import { GuildMember, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { CaseTypes } from "../../../data/CaseTypes"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; -import { UserNotificationResult, createUserNotificationError, notifyUser, resolveUser, ucfirst } from "../../../utils"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; +import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { waitForButtonConfirm } from "../../../utils/waitForInteraction"; import { CasesPlugin } from "../../Cases/CasesPlugin"; diff --git a/backend/src/plugins/Mutes/MutesPlugin.ts b/backend/src/plugins/Mutes/MutesPlugin.ts index db8548be..71143901 100644 --- a/backend/src/plugins/Mutes/MutesPlugin.ts +++ b/backend/src/plugins/Mutes/MutesPlugin.ts @@ -1,5 +1,4 @@ import { GuildMember, Snowflake } from "discord.js"; -import { EventEmitter } from "events"; import { guildPlugin } from "knub"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildCases } from "../../data/GuildCases"; @@ -24,6 +23,7 @@ import { onMutesEvent } from "./functions/onMutesEvent"; import { renewTimeoutMute } from "./functions/renewTimeoutMute"; import { unmuteUser } from "./functions/unmuteUser"; import { MutesPluginType, zMutesConfig } from "./types"; +import { EventEmitter } from "events"; const defaultOptions = { config: { diff --git a/backend/src/plugins/Mutes/functions/muteUser.ts b/backend/src/plugins/Mutes/functions/muteUser.ts index fcc27307..682850d8 100644 --- a/backend/src/plugins/Mutes/functions/muteUser.ts +++ b/backend/src/plugins/Mutes/functions/muteUser.ts @@ -9,15 +9,15 @@ import { Case } from "../../../data/entities/Case"; import { Mute } from "../../../data/entities/Mute"; import { registerExpiringMute } from "../../../data/loops/expiringMutesLoop"; import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; import { - UserNotificationMethod, - UserNotificationResult, noop, notifyUser, resolveMember, resolveUser, ucfirst, + UserNotificationMethod, + UserNotificationResult, } from "../../../utils"; import { muteLock } from "../../../utils/lockNameHelpers"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; diff --git a/backend/src/plugins/NameHistory/NameHistoryPlugin.ts b/backend/src/plugins/NameHistory/NameHistoryPlugin.ts index ee226f3e..ae611b27 100644 --- a/backend/src/plugins/NameHistory/NameHistoryPlugin.ts +++ b/backend/src/plugins/NameHistory/NameHistoryPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { Queue } from "../../Queue"; import { GuildNicknameHistory } from "../../data/GuildNicknameHistory"; import { UsernameHistory } from "../../data/UsernameHistory"; diff --git a/backend/src/plugins/Persist/PersistPlugin.ts b/backend/src/plugins/Persist/PersistPlugin.ts index 760ecc26..ab46f697 100644 --- a/backend/src/plugins/Persist/PersistPlugin.ts +++ b/backend/src/plugins/Persist/PersistPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildPersistedData } from "../../data/GuildPersistedData"; import { LogsPlugin } from "../Logs/LogsPlugin"; diff --git a/backend/src/plugins/Persist/events/LoadDataEvt.ts b/backend/src/plugins/Persist/events/LoadDataEvt.ts index 3fb1dcdb..8dfa7169 100644 --- a/backend/src/plugins/Persist/events/LoadDataEvt.ts +++ b/backend/src/plugins/Persist/events/LoadDataEvt.ts @@ -8,7 +8,7 @@ import { getMissingPermissions } from "../../../utils/getMissingPermissions"; import { missingPermissionError } from "../../../utils/missingPermissionError"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin"; -import { PersistPluginType, persistEvt } from "../types"; +import { persistEvt, PersistPluginType } from "../types"; const p = PermissionFlagsBits; diff --git a/backend/src/plugins/Phisherman/PhishermanPlugin.ts b/backend/src/plugins/Phisherman/PhishermanPlugin.ts index a5196235..36618760 100644 --- a/backend/src/plugins/Phisherman/PhishermanPlugin.ts +++ b/backend/src/plugins/Phisherman/PhishermanPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { hasPhishermanMasterAPIKey, phishermanApiKeyIsValid } from "../../data/Phisherman"; import { makePublicFn } from "../../pluginUtils"; import { getDomainInfo } from "./functions/getDomainInfo"; diff --git a/backend/src/plugins/PingableRoles/PingableRolesPlugin.ts b/backend/src/plugins/PingableRoles/PingableRolesPlugin.ts index 68dbcd2e..70fdf80f 100644 --- a/backend/src/plugins/PingableRoles/PingableRolesPlugin.ts +++ b/backend/src/plugins/PingableRoles/PingableRolesPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildPingableRoles } from "../../data/GuildPingableRoles"; import { PingableRoleDisableCmd } from "./commands/PingableRoleDisableCmd"; import { PingableRoleEnableCmd } from "./commands/PingableRoleEnableCmd"; diff --git a/backend/src/plugins/Post/PostPlugin.ts b/backend/src/plugins/Post/PostPlugin.ts index 0deb881b..d836fa6c 100644 --- a/backend/src/plugins/Post/PostPlugin.ts +++ b/backend/src/plugins/Post/PostPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { onGuildEvent } from "../../data/GuildEvents"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; diff --git a/backend/src/plugins/Post/commands/ScheduledPostsListCmd.ts b/backend/src/plugins/Post/commands/ScheduledPostsListCmd.ts index c118440f..092be2e2 100644 --- a/backend/src/plugins/Post/commands/ScheduledPostsListCmd.ts +++ b/backend/src/plugins/Post/commands/ScheduledPostsListCmd.ts @@ -1,4 +1,4 @@ -import { escapeCodeBlock } from "discord.js"; +import { escapeCodeBlock, TextChannel } from "discord.js"; import humanizeDuration from "humanize-duration"; import moment from "moment-timezone"; import { createChunkedMessage, DBDateFormat, deactivateMentions, sorter, trimLines } from "../../../utils"; @@ -58,6 +58,6 @@ export const ScheduledPostsListCmd = postCmd({ Use \`scheduled_posts \` to view a scheduled post in full Use \`scheduled_posts delete \` to delete a scheduled post `); - createChunkedMessage(msg.channel, finalMessage); + createChunkedMessage(msg.channel as TextChannel, finalMessage); }, }); diff --git a/backend/src/plugins/Post/util/actualPostCmd.ts b/backend/src/plugins/Post/util/actualPostCmd.ts index 29c3d5ec..9f9b1500 100644 --- a/backend/src/plugins/Post/util/actualPostCmd.ts +++ b/backend/src/plugins/Post/util/actualPostCmd.ts @@ -1,10 +1,10 @@ -import { GuildTextBasedChannel, Message } from "discord.js"; +import { GuildTextBasedChannel, Message, TextBasedChannelFields } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import moment from "moment-timezone"; import { registerUpcomingScheduledPost } from "../../../data/loops/upcomingScheduledPostsLoop"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; -import { DBDateFormat, MINUTES, StrictMessageContent, errorMessage, renderUsername } from "../../../utils"; +import { DBDateFormat, errorMessage, MINUTES, renderUsername, StrictMessageContent } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { PostPluginType } from "../types"; @@ -29,12 +29,12 @@ export async function actualPostCmd( } = {}, ) { if (!targetChannel.isTextBased()) { - msg.channel.send(errorMessage("Specified channel is not a text-based channel")); + await (msg.channel as TextBasedChannelFields).send(errorMessage("Specified channel is not a text-based channel")); return; } if (content == null && msg.attachments.size === 0) { - msg.channel.send(errorMessage("Message content or attachment required")); + await (msg.channel as TextBasedChannelFields).send(errorMessage("Message content or attachment required")); return; } diff --git a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts index 8622b3b9..7660ad6b 100644 --- a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts +++ b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { Queue } from "../../Queue"; import { GuildReactionRoles } from "../../data/GuildReactionRoles"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; diff --git a/backend/src/plugins/ReactionRoles/commands/InitReactionRolesCmd.ts b/backend/src/plugins/ReactionRoles/commands/InitReactionRolesCmd.ts index fefc166e..e724168a 100644 --- a/backend/src/plugins/ReactionRoles/commands/InitReactionRolesCmd.ts +++ b/backend/src/plugins/ReactionRoles/commands/InitReactionRolesCmd.ts @@ -3,7 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils"; import { canReadChannel } from "../../../utils/canReadChannel"; -import { TReactionRolePair, reactionRolesCmd } from "../types"; +import { reactionRolesCmd, TReactionRolePair } from "../types"; import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage"; const CLEAR_ROLES_EMOJI = "❌"; diff --git a/backend/src/plugins/Reminders/RemindersPlugin.ts b/backend/src/plugins/Reminders/RemindersPlugin.ts index d43961c3..abb7c2e1 100644 --- a/backend/src/plugins/Reminders/RemindersPlugin.ts +++ b/backend/src/plugins/Reminders/RemindersPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { onGuildEvent } from "../../data/GuildEvents"; import { GuildReminders } from "../../data/GuildReminders"; import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin"; diff --git a/backend/src/plugins/Reminders/commands/RemindersCmd.ts b/backend/src/plugins/Reminders/commands/RemindersCmd.ts index ce914a34..d0d39fda 100644 --- a/backend/src/plugins/Reminders/commands/RemindersCmd.ts +++ b/backend/src/plugins/Reminders/commands/RemindersCmd.ts @@ -4,6 +4,7 @@ import { sendErrorMessage } from "../../../pluginUtils"; import { createChunkedMessage, DBDateFormat, sorter } from "../../../utils"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { remindersCmd } from "../types"; +import { TextChannel } from "discord.js"; export const RemindersCmd = remindersCmd({ trigger: "reminders", @@ -32,6 +33,6 @@ export const RemindersCmd = remindersCmd({ return `\`${paddedNum}.\` \`${prettyRemindAt} (${result})\` ${reminder.body}`; }); - createChunkedMessage(msg.channel, lines.join("\n")); + await createChunkedMessage(msg.channel as TextChannel, lines.join("\n")); }, }); diff --git a/backend/src/plugins/Roles/RolesPlugin.ts b/backend/src/plugins/Roles/RolesPlugin.ts index 89b3b6c9..576552a2 100644 --- a/backend/src/plugins/Roles/RolesPlugin.ts +++ b/backend/src/plugins/Roles/RolesPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { LogsPlugin } from "../Logs/LogsPlugin"; import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin"; diff --git a/backend/src/plugins/SelfGrantableRoles/SelfGrantableRolesPlugin.ts b/backend/src/plugins/SelfGrantableRoles/SelfGrantableRolesPlugin.ts index 9a9e770c..5ce70a88 100644 --- a/backend/src/plugins/SelfGrantableRoles/SelfGrantableRolesPlugin.ts +++ b/backend/src/plugins/SelfGrantableRoles/SelfGrantableRolesPlugin.ts @@ -1,4 +1,4 @@ -import { CooldownManager, PluginOptions, guildPlugin } from "knub"; +import { CooldownManager, guildPlugin, PluginOptions } from "knub"; import { RoleAddCmd } from "./commands/RoleAddCmd"; import { RoleHelpCmd } from "./commands/RoleHelpCmd"; import { RoleRemoveCmd } from "./commands/RoleRemoveCmd"; diff --git a/backend/src/plugins/Slowmode/SlowmodePlugin.ts b/backend/src/plugins/Slowmode/SlowmodePlugin.ts index 8e97adb1..e204aa7e 100644 --- a/backend/src/plugins/Slowmode/SlowmodePlugin.ts +++ b/backend/src/plugins/Slowmode/SlowmodePlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildSlowmodes } from "../../data/GuildSlowmodes"; diff --git a/backend/src/plugins/Slowmode/util/actualDisableSlowmodeCmd.ts b/backend/src/plugins/Slowmode/util/actualDisableSlowmodeCmd.ts index 2bc00bed..b3f6c162 100644 --- a/backend/src/plugins/Slowmode/util/actualDisableSlowmodeCmd.ts +++ b/backend/src/plugins/Slowmode/util/actualDisableSlowmodeCmd.ts @@ -1,4 +1,4 @@ -import { Message } from "discord.js"; +import { Message, TextBasedChannelFields } from "discord.js"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { noop } from "../../../utils"; import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions"; @@ -26,7 +26,7 @@ export async function actualDisableSlowmodeCmd(msg: Message, args, pluginData) { return; } - const initMsg = await msg.channel.send("Disabling slowmode..."); + const initMsg = await (msg.channel as TextBasedChannelFields).send("Disabling slowmode..."); // Disable bot-maintained slowmode let failedUsers: string[] = []; diff --git a/backend/src/plugins/Slowmode/util/applyBotSlowmodeToUserId.ts b/backend/src/plugins/Slowmode/util/applyBotSlowmodeToUserId.ts index ebfd653d..27da9d72 100644 --- a/backend/src/plugins/Slowmode/util/applyBotSlowmodeToUserId.ts +++ b/backend/src/plugins/Slowmode/util/applyBotSlowmodeToUserId.ts @@ -2,7 +2,7 @@ import { GuildTextBasedChannel, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { LogType } from "../../../data/LogType"; import { logger } from "../../../logger"; -import { UnknownUser, isDiscordAPIError, verboseChannelMention, verboseUserMention } from "../../../utils"; +import { isDiscordAPIError, UnknownUser, verboseChannelMention, verboseUserMention } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { SlowmodePluginType } from "../types"; diff --git a/backend/src/plugins/Spam/SpamPlugin.ts b/backend/src/plugins/Spam/SpamPlugin.ts index b4d27ae3..2e952f2f 100644 --- a/backend/src/plugins/Spam/SpamPlugin.ts +++ b/backend/src/plugins/Spam/SpamPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildLogs } from "../../data/GuildLogs"; import { GuildMutes } from "../../data/GuildMutes"; diff --git a/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts b/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts index b2a46432..0c11a698 100644 --- a/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts +++ b/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts @@ -9,7 +9,7 @@ import { logger } from "../../../logger"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin"; import { MuteResult } from "../../../plugins/Mutes/types"; -import { DBDateFormat, convertDelayStringToMS, noop, resolveMember, trimLines } from "../../../utils"; +import { convertDelayStringToMS, DBDateFormat, noop, resolveMember, trimLines } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { RecentActionType, SpamPluginType, TBaseSingleSpamConfig } from "../types"; import { addRecentAction } from "./addRecentAction"; diff --git a/backend/src/plugins/Starboard/StarboardPlugin.ts b/backend/src/plugins/Starboard/StarboardPlugin.ts index 7e12102c..a6cdb06d 100644 --- a/backend/src/plugins/Starboard/StarboardPlugin.ts +++ b/backend/src/plugins/Starboard/StarboardPlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildStarboardMessages } from "../../data/GuildStarboardMessages"; import { GuildStarboardReactions } from "../../data/GuildStarboardReactions"; diff --git a/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts b/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts index 93ba4dfd..6c732db0 100644 --- a/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts +++ b/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts @@ -1,6 +1,6 @@ import { GuildChannel, Message } from "discord.js"; import path from "path"; -import { EMPTY_CHAR, EmbedWith, renderUsername } from "../../../utils"; +import { EmbedWith, EMPTY_CHAR, renderUsername } from "../../../utils"; const imageAttachmentExtensions = ["jpeg", "jpg", "png", "gif", "webp"]; const audioAttachmentExtensions = ["wav", "mp3", "m4a"]; diff --git a/backend/src/plugins/Tags/TagsPlugin.ts b/backend/src/plugins/Tags/TagsPlugin.ts index 09379d6d..d59c4c00 100644 --- a/backend/src/plugins/Tags/TagsPlugin.ts +++ b/backend/src/plugins/Tags/TagsPlugin.ts @@ -1,6 +1,6 @@ import { Snowflake } from "discord.js"; import humanizeDuration from "humanize-duration"; -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import moment from "moment-timezone"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildLogs } from "../../data/GuildLogs"; diff --git a/backend/src/plugins/Tags/commands/TagCreateCmd.ts b/backend/src/plugins/Tags/commands/TagCreateCmd.ts index 10c81e87..0595e4bb 100644 --- a/backend/src/plugins/Tags/commands/TagCreateCmd.ts +++ b/backend/src/plugins/Tags/commands/TagCreateCmd.ts @@ -1,6 +1,6 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; -import { TemplateParseError, parseTemplate } from "../../../templateFormatter"; +import { parseTemplate, TemplateParseError } from "../../../templateFormatter"; import { tagsCmd } from "../types"; export const TagCreateCmd = tagsCmd({ diff --git a/backend/src/plugins/Tags/commands/TagListCmd.ts b/backend/src/plugins/Tags/commands/TagListCmd.ts index 008a22a1..466db5e7 100644 --- a/backend/src/plugins/Tags/commands/TagListCmd.ts +++ b/backend/src/plugins/Tags/commands/TagListCmd.ts @@ -2,6 +2,7 @@ import escapeStringRegexp from "escape-string-regexp"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { createChunkedMessage } from "../../../utils"; import { tagsCmd } from "../types"; +import { TextChannel } from "discord.js"; export const TagListCmd = tagsCmd({ trigger: ["tag list", "tags", "taglist"], @@ -46,6 +47,6 @@ export const TagListCmd = tagsCmd({ .map((key) => `[${key}] ${tagGroups[key].join(", ")}`) .join("\n"); - createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagList}\`\`\``); + createChunkedMessage(msg.channel as TextChannel, `Available tags (use with ${prefix}tag): \`\`\`${tagList}\`\`\``); }, }); diff --git a/backend/src/plugins/Tags/util/findTagByName.ts b/backend/src/plugins/Tags/util/findTagByName.ts index 98fafc3f..7f8c2d42 100644 --- a/backend/src/plugins/Tags/util/findTagByName.ts +++ b/backend/src/plugins/Tags/util/findTagByName.ts @@ -1,5 +1,5 @@ import { ExtendedMatchParams, GuildPluginData } from "knub"; -import { TTag, TagsPluginType } from "../types"; +import { TagsPluginType, TTag } from "../types"; export async function findTagByName( pluginData: GuildPluginData, diff --git a/backend/src/plugins/Tags/util/matchAndRenderTagFromString.ts b/backend/src/plugins/Tags/util/matchAndRenderTagFromString.ts index 8e90fe82..67760d3d 100644 --- a/backend/src/plugins/Tags/util/matchAndRenderTagFromString.ts +++ b/backend/src/plugins/Tags/util/matchAndRenderTagFromString.ts @@ -2,7 +2,7 @@ import { GuildMember } from "discord.js"; import escapeStringRegexp from "escape-string-regexp"; import { ExtendedMatchParams, GuildPluginData } from "knub"; import { StrictMessageContent } from "../../../utils"; -import { TTagCategory, TagsPluginType } from "../types"; +import { TagsPluginType, TTagCategory } from "../types"; import { renderTagFromString } from "./renderTagFromString"; interface BaseResult { diff --git a/backend/src/plugins/Tags/util/renderTagBody.ts b/backend/src/plugins/Tags/util/renderTagBody.ts index e75a12cf..a321360d 100644 --- a/backend/src/plugins/Tags/util/renderTagBody.ts +++ b/backend/src/plugins/Tags/util/renderTagBody.ts @@ -1,7 +1,7 @@ import { ExtendedMatchParams, GuildPluginData } from "knub"; -import { TemplateSafeValue, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; -import { StrictMessageContent, renderRecursively } from "../../../utils"; -import { TTag, TagsPluginType } from "../types"; +import { renderTemplate, TemplateSafeValue, TemplateSafeValueContainer } from "../../../templateFormatter"; +import { renderRecursively, StrictMessageContent } from "../../../utils"; +import { TagsPluginType, TTag } from "../types"; import { findTagByName } from "./findTagByName"; const MAX_TAG_FN_CALLS = 25; diff --git a/backend/src/plugins/Tags/util/renderTagFromString.ts b/backend/src/plugins/Tags/util/renderTagFromString.ts index 10306777..ab4de697 100644 --- a/backend/src/plugins/Tags/util/renderTagFromString.ts +++ b/backend/src/plugins/Tags/util/renderTagFromString.ts @@ -6,7 +6,7 @@ import { TemplateParseError } from "../../../templateFormatter"; import { StrictMessageContent, validateAndParseMessageContent } from "../../../utils"; import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { LogsPlugin } from "../../Logs/LogsPlugin"; -import { TTag, TagsPluginType } from "../types"; +import { TagsPluginType, TTag } from "../types"; import { renderTagBody } from "./renderTagBody"; export async function renderTagFromString( diff --git a/backend/src/plugins/TimeAndDate/TimeAndDatePlugin.ts b/backend/src/plugins/TimeAndDate/TimeAndDatePlugin.ts index 78dd8fa0..ad29f7d5 100644 --- a/backend/src/plugins/TimeAndDate/TimeAndDatePlugin.ts +++ b/backend/src/plugins/TimeAndDate/TimeAndDatePlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildMemberTimezones } from "../../data/GuildMemberTimezones"; import { makePublicFn } from "../../pluginUtils"; import { ResetTimezoneCmd } from "./commands/ResetTimezoneCmd"; diff --git a/backend/src/plugins/Utility/UtilityPlugin.ts b/backend/src/plugins/Utility/UtilityPlugin.ts index 0b44fca5..f6b4cf27 100644 --- a/backend/src/plugins/Utility/UtilityPlugin.ts +++ b/backend/src/plugins/Utility/UtilityPlugin.ts @@ -1,5 +1,5 @@ import { Snowflake } from "discord.js"; -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildCases } from "../../data/GuildCases"; import { GuildLogs } from "../../data/GuildLogs"; diff --git a/backend/src/plugins/Utility/commands/AvatarCmd.ts b/backend/src/plugins/Utility/commands/AvatarCmd.ts index e4ba07d5..337c0259 100644 --- a/backend/src/plugins/Utility/commands/AvatarCmd.ts +++ b/backend/src/plugins/Utility/commands/AvatarCmd.ts @@ -1,7 +1,7 @@ import { APIEmbed, ImageFormat } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { UnknownUser, renderUsername } from "../../../utils"; +import { renderUsername, UnknownUser } from "../../../utils"; import { utilityCmd } from "../types"; export const AvatarCmd = utilityCmd({ diff --git a/backend/src/plugins/Utility/commands/CleanCmd.ts b/backend/src/plugins/Utility/commands/CleanCmd.ts index 18d4efa2..6fcef79c 100644 --- a/backend/src/plugins/Utility/commands/CleanCmd.ts +++ b/backend/src/plugins/Utility/commands/CleanCmd.ts @@ -7,9 +7,9 @@ import { SavedMessage } from "../../../data/entities/SavedMessage"; import { humanizeDurationShort } from "../../../humanizeDurationShort"; import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin"; -import { DAYS, SECONDS, chunkArray, getInviteCodesInString, noop } from "../../../utils"; +import { chunkArray, DAYS, getInviteCodesInString, noop, SECONDS } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; -import { UtilityPluginType, utilityCmd } from "../types"; +import { utilityCmd, UtilityPluginType } from "../types"; const MAX_CLEAN_COUNT = 300; const MAX_CLEAN_TIME = 1 * DAYS; diff --git a/backend/src/plugins/Utility/commands/HelpCmd.ts b/backend/src/plugins/Utility/commands/HelpCmd.ts index 7e3391fd..0a8b9b74 100644 --- a/backend/src/plugins/Utility/commands/HelpCmd.ts +++ b/backend/src/plugins/Utility/commands/HelpCmd.ts @@ -2,6 +2,7 @@ import { LoadedGuildPlugin, PluginCommandDefinition } from "knub"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { createChunkedMessage } from "../../../utils"; import { utilityCmd } from "../types"; +import { TextChannel } from "discord.js"; export const HelpCmd = utilityCmd({ trigger: "help", @@ -78,6 +79,6 @@ export const HelpCmd = utilityCmd({ : ""; message += commandSnippets.join("\n\n"); - createChunkedMessage(msg.channel, message); + createChunkedMessage(msg.channel as TextChannel, message); }, }); diff --git a/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts b/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts index befd1467..ff7bd81e 100644 --- a/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts @@ -1,7 +1,7 @@ import { APIEmbed, ChannelType, Snowflake, StageChannel, VoiceChannel } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import { EmbedWith, MINUTES, formatNumber, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils"; +import { EmbedWith, formatNumber, MINUTES, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils"; import { UtilityPluginType } from "../types"; const TEXT_CHANNEL_ICON = diff --git a/backend/src/plugins/Utility/functions/getGuildPreview.ts b/backend/src/plugins/Utility/functions/getGuildPreview.ts index 6ead2537..fc1d00db 100644 --- a/backend/src/plugins/Utility/functions/getGuildPreview.ts +++ b/backend/src/plugins/Utility/functions/getGuildPreview.ts @@ -1,5 +1,5 @@ import { Client, GuildPreview, Snowflake } from "discord.js"; -import { MINUTES, memoize } from "../../../utils"; +import { memoize, MINUTES } from "../../../utils"; /** * Memoized getGuildPreview diff --git a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts index b844b937..01a0753f 100644 --- a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts @@ -2,8 +2,8 @@ import { APIEmbed, ChannelType } from "discord.js"; import { GuildPluginData } from "knub"; import { EmbedWith, - GroupDMInvite, formatNumber, + GroupDMInvite, inviteHasCounts, isGroupDMInvite, isGuildInvite, @@ -102,28 +102,28 @@ export async function getInviteInfoEmbed( invite = invite as GroupDMInvite; embed.author = { - name: invite.channel!.name ? `Group DM invite: ${invite.channel!.name}` : `Group DM invite`, - url: `https://discord.gg/${invite.code}`, + name: invite?.channel!.name ? `Group DM invite: ${invite!.channel!.name}` : `Group DM invite`, + url: `https://discord.gg/${invite?.code}`, }; // FIXME pending invite re-think /*if (invite.channel.icon) { embed.author.icon_url = `https://cdn.discordapp.com/channel-icons/${invite.channel.id}/${invite.channel.icon}.png?size=256`; }*/ - const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel!.id); + const channelCreatedAtTimestamp = snowflakeToTimestamp(invite!.channel!.id); embed.fields.push({ name: preEmbedPadding + "Group DM information", value: trimLines(` - Name: ${invite.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`} - ID: \`${invite.channel!.id}\` + Name: ${invite?.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`} + ID: \`${invite?.channel!.id}\` Created: **** Members: **${formatNumber((invite as any).memberCount)}** `), inline: true, }); - if (invite.inviter) { + if (invite?.inviter) { embed.fields.push({ name: preEmbedPadding + "Invite creator", value: trimLines(` diff --git a/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts b/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts index 34a89fe6..fba261e0 100644 --- a/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts @@ -1,8 +1,8 @@ import { APIEmbed, MessageType, Snowflake, TextChannel } from "discord.js"; -import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub"; +import { getDefaultMessageCommandPrefix, GuildPluginData } from "knub"; import { - EmbedWith, chunkMessageLines, + EmbedWith, messageLink, preEmbedPadding, renderUsername, diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index fa7368a6..008b628b 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -2,10 +2,10 @@ import { APIEmbed, ChannelType, GuildPremiumTier, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { EmbedWith, - MINUTES, formatNumber, inviteHasCounts, memoize, + MINUTES, preEmbedPadding, renderUsername, resolveInvite, diff --git a/backend/src/plugins/Utility/search.ts b/backend/src/plugins/Utility/search.ts index 4f5d08ef..a5901898 100644 --- a/backend/src/plugins/Utility/search.ts +++ b/backend/src/plugins/Utility/search.ts @@ -7,17 +7,18 @@ import { MessageComponentInteraction, PermissionsBitField, Snowflake, + TextBasedChannelFields, User, } from "discord.js"; import escapeStringRegexp from "escape-string-regexp"; import { ArgsFromSignatureOrArray, GuildPluginData } from "knub"; import moment from "moment-timezone"; -import { RegExpRunner, allowTimeout } from "../../RegExpRunner"; +import { allowTimeout, RegExpRunner } from "../../RegExpRunner"; import { getBaseUrl, sendErrorMessage } from "../../pluginUtils"; import { + inputPatternToRegExp, InvalidRegexError, MINUTES, - inputPatternToRegExp, multiSorter, renderUsername, sorter, @@ -106,7 +107,7 @@ export async function displaySearch( if (originalSearchMsg) { searchMsgPromise = originalSearchMsg.edit("Searching..."); } else { - searchMsgPromise = msg.channel.send("Searching..."); + searchMsgPromise = (msg.channel as TextBasedChannelFields).send("Searching..."); searchMsgPromise.then((m) => (originalSearchMsg = m)); } @@ -165,7 +166,7 @@ export async function displaySearch( const embed = await getUserInfoEmbed(pluginData, searchResult.results[0].id, false); if (embed) { searchMsg.edit("Only one result:"); - msg.channel.send({ embeds: [embed] }); + (msg.channel as TextBasedChannelFields).send({ embeds: [embed] }); return; } } @@ -297,7 +298,7 @@ export async function archiveSearch( const baseUrl = getBaseUrl(pluginData); const url = await pluginData.state.archives.getUrl(baseUrl, archiveId); - await msg.channel.send(`Exported search results: ${url}`); + await (msg.channel as TextBasedChannelFields).send(`Exported search results: ${url}`); } async function performMemberSearch( diff --git a/backend/src/plugins/WelcomeMessage/WelcomeMessagePlugin.ts b/backend/src/plugins/WelcomeMessage/WelcomeMessagePlugin.ts index a8fb9261..38eefaef 100644 --- a/backend/src/plugins/WelcomeMessage/WelcomeMessagePlugin.ts +++ b/backend/src/plugins/WelcomeMessage/WelcomeMessagePlugin.ts @@ -1,4 +1,4 @@ -import { PluginOptions, guildPlugin } from "knub"; +import { guildPlugin, PluginOptions } from "knub"; import { GuildLogs } from "../../data/GuildLogs"; import { LogsPlugin } from "../Logs/LogsPlugin"; import { SendWelcomeMessageEvt } from "./events/SendWelcomeMessageEvt"; diff --git a/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts b/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts index 879b99cd..fac26322 100644 --- a/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts +++ b/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts @@ -1,5 +1,5 @@ import { Snowflake, TextChannel } from "discord.js"; -import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter"; +import { renderTemplate, TemplateParseError, TemplateSafeValueContainer } from "../../../templateFormatter"; import { createChunkedMessage, verboseChannelMention, verboseUserMention } from "../../../utils"; import { sendDM } from "../../../utils/sendDM"; import { diff --git a/backend/src/templateFormatter.ts b/backend/src/templateFormatter.ts index 299efb2e..5b705f9b 100644 --- a/backend/src/templateFormatter.ts +++ b/backend/src/templateFormatter.ts @@ -482,7 +482,7 @@ export async function renderTemplate( // If our template cache is full, delete the first item if (templateCache.size >= TEMPLATE_CACHE_SIZE) { const firstKey = templateCache.keys().next().value; - templateCache.delete(firstKey); + templateCache.delete(firstKey!); } templateCache.set(template, parseResult); diff --git a/backend/src/threadsSignalFix.ts b/backend/src/threadsSignalFix.ts index 86f53067..d85f4a0e 100644 --- a/backend/src/threadsSignalFix.ts +++ b/backend/src/threadsSignalFix.ts @@ -7,6 +7,7 @@ */ import "threads"; import { env } from "./env"; + if (!env.DEBUG) { process.removeAllListeners("SIGINT"); process.removeAllListeners("SIGTERM"); diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 174a720f..bfc85267 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -22,7 +22,7 @@ import { PartialMessage, RoleResolvable, Sticker, - TextBasedChannel, + TextChannel, User, } from "discord.js"; import emojiRegex from "emoji-regex"; @@ -836,7 +836,7 @@ export function chunkMessageLines(str: string, maxChunkLength = 1990): string[] } export async function createChunkedMessage( - channel: TextBasedChannel | User, + channel: TextChannel | User, messageText: string, allowedMentions?: MessageMentionOptions, ) { diff --git a/backend/src/utils/createPaginatedMessage.ts b/backend/src/utils/createPaginatedMessage.ts index 18e8f3d0..e1ad9bb7 100644 --- a/backend/src/utils/createPaginatedMessage.ts +++ b/backend/src/utils/createPaginatedMessage.ts @@ -7,6 +7,7 @@ import { PartialMessageReaction, PartialUser, TextBasedChannel, + TextBasedChannelFields, User, } from "discord.js"; import { MINUTES, noop } from "../utils"; @@ -34,7 +35,7 @@ export async function createPaginatedMessage( ): Promise { const fullOpts = { ...defaultOpts, ...opts } as PaginateMessageOpts; const firstPageContent = await loadPageFn(1); - const message = await channel.send(firstPageContent); + const message = await (channel as TextBasedChannelFields).send(firstPageContent); let page = 1; let pageLoadId = 0; // Used to avoid race conditions when rapidly switching pages diff --git a/backend/src/utils/permissionNames.ts b/backend/src/utils/permissionNames.ts index ca4922de..05d9d0dd 100644 --- a/backend/src/utils/permissionNames.ts +++ b/backend/src/utils/permissionNames.ts @@ -48,4 +48,5 @@ export const PERMISSION_NAMES = { UseExternalSounds: "Use External Sounds", UseSoundboard: "Use Soundboard", ViewCreatorMonetizationAnalytics: "View Creator Monetization Analytics", + // @ts-ignore } as const satisfies Record; diff --git a/backend/src/utils/sendDM.ts b/backend/src/utils/sendDM.ts index bfcfe97e..7cfc3f87 100644 --- a/backend/src/utils/sendDM.ts +++ b/backend/src/utils/sendDM.ts @@ -1,6 +1,6 @@ import { MessagePayload, User } from "discord.js"; import { logger } from "../logger"; -import { HOURS, createChunkedMessage, isDiscordAPIError } from "../utils"; +import { createChunkedMessage, HOURS, isDiscordAPIError } from "../utils"; import Timeout = NodeJS.Timeout; let dmsDisabled = false; diff --git a/backend/src/utils/templateSafeObjects.ts b/backend/src/utils/templateSafeObjects.ts index 06ed04b1..ced36311 100644 --- a/backend/src/utils/templateSafeObjects.ts +++ b/backend/src/utils/templateSafeObjects.ts @@ -22,11 +22,11 @@ import { SavedMessage, } from "../data/entities/SavedMessage"; import { + ingestDataIntoTemplateSafeValueContainer, TemplateSafeValueContainer, TypedTemplateSafeValueContainer, - ingestDataIntoTemplateSafeValueContainer, } from "../templateFormatter"; -import { UnknownUser, renderUsername } from "../utils"; +import { renderUsername, UnknownUser } from "../utils"; type InputProps = Omit< { diff --git a/dashboard/package.json b/dashboard/package.json index 0d3a328e..9857f915 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -12,6 +12,7 @@ "@babel/core": "^7.22.5", "@babel/preset-env": "^7.22.5", "@babel/preset-typescript": "^7.22.5", + "@types/node": "^18.16.3", "babel-loader": "^9.1.2", "cross-env": "^7.0.3", "css-loader": "^6.8.1", @@ -24,6 +25,7 @@ "postcss-loader": "^7.3.3", "postcss-nesting": "^11.3.0", "postcss-preset-env": "^8.5.1", + "rimraf": "^6.0.1", "source-map-loader": "^4.0.1", "tailwindcss": "^1.9.6", "ts-loader": "^9.4.3", @@ -38,6 +40,8 @@ "dependencies": { "@fastify/static": "^7.0.1", "@highlightjs/vue-plugin": "^1.0.2", + "@zeppelinbot/shared": "workspace:*", + "brace": "^0.11.1", "fastify": "^4.26.2", "highlight.js": "^11.8.0", "humanize-duration": "^3.27.0", diff --git a/dashboard/src/components/PrivacyPolicy.vue b/dashboard/src/components/PrivacyPolicy.vue index be563dd1..e688db3f 100644 --- a/dashboard/src/components/PrivacyPolicy.vue +++ b/dashboard/src/components/PrivacyPolicy.vue @@ -15,7 +15,7 @@ in to through Discord OAuth.

- The bot's source code is available at + Zeppelin's source code (what we base on) is available at https://github.com/ZeppelinBot/Zeppelin diff --git a/dashboard/src/components/dashboard/Layout.vue b/dashboard/src/components/dashboard/Layout.vue index 9a46852c..0658e5b8 100644 --- a/dashboard/src/components/dashboard/Layout.vue +++ b/dashboard/src/components/dashboard/Layout.vue @@ -1,13 +1,13 @@