diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml index e56a32e03..d9afb3b9e 100644 --- a/.github/workflows/test_build.yml +++ b/.github/workflows/test_build.yml @@ -13,11 +13,11 @@ jobs: os: [windows, macos, ubuntu] include: - os: windows - deps: '' + deps: "" - os: macos - deps: '' + deps: "" - os: ubuntu - deps: 'sudo apt install -y libpango1.0-dev libgif-dev' + deps: "sudo apt install -y libpango1.0-dev libgif-dev" runs-on: ${{ matrix.os }}-latest steps: - uses: actions/checkout@v2 diff --git a/build.json b/build.json new file mode 100644 index 000000000..1c0e410d5 --- /dev/null +++ b/build.json @@ -0,0 +1,16 @@ +{ + "compiler": "tsc", + "verbose": true, + "writeBuildLog": true, + "writeAnsiBuildLog": true, + "logErrors": true, + "tsc": { + "prettyErrors": true + }, + "clean": true, + "quiet": false, + "steps": { + "pre": ["clean", "plugin_prepare"], + "post": ["plugin_resources", "remap_imports"] + } +} diff --git a/scripts/build.js b/scripts/build.js index 704909cec..6cf4e8183 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -29,7 +29,7 @@ if (silent) console.error = console.log = function () {}; if (argv.includes("clean")) { console.log(`[${++i}/${steps}] Cleaning...`); - let d = "dist"; + let d = "../" + "/dist"; if (fs.existsSync(d)) { fs.rmSync(d, { recursive: true }); if (verbose) console.log(`Deleted ${d}!`); @@ -110,7 +110,7 @@ if (!argv.includes("copyonly")) { } console.log(`[${++i}/${steps}] Copying plugin data...`); -let pluginFiles = walk(pluginDir).filter((x) => !x.endsWith(".ts")); -pluginFiles.forEach((x) => { - fs.copyFileSync(x, x.replace("src", "dist")); -}); +let pluginFiles = walk(pluginDir).filter(x=>!x.endsWith('.ts')); +pluginFiles.forEach(x=>{ + fs.copyFileSync(x, x.replace('src','dist')) +}) \ No newline at end of file diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts index 6c4b5f67d..0b6b81ce7 100644 --- a/src/api/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts @@ -33,14 +33,13 @@ export function ErrorHandler( let code = 400; let httpcode = code; let message = error?.toString(); - let errors = undefined; - let data = undefined; + let errors = null; + let data = null; if (error instanceof HTTPError && error.code) { code = httpcode = error.code; - if(error.data) data = error.data; - } - else if (error instanceof ApiError) { + if (error.data) data = error.data; + } else if (error instanceof ApiError) { code = error.code; message = error.message; httpcode = error.httpStatus; diff --git a/src/api/routes/channels/#channel_id/followers.ts b/src/api/routes/channels/#channel_id/followers.ts index 58906e73a..e54a43b2a 100644 --- a/src/api/routes/channels/#channel_id/followers.ts +++ b/src/api/routes/channels/#channel_id/followers.ts @@ -18,7 +18,7 @@ import { Router } from "express"; const router: Router = Router(); -// TODO: +// TODO: implement route export default router; diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index 05ca79d45..1bcf3f16e 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -427,10 +427,17 @@ router.post( read_state = ReadState.create({ user_id: req.user_id, channel_id }); read_state.last_message_id = message.id; - let blocks = (await PluginEventHandler.preMessageEvent({ - message - } as PreMessageEventArgs)).filter(x=>x.cancel); - if(blocks.length > 0) throw new HTTPError("Message denied.", 400, blocks.filter(x=>x.blockReason).map(x=>x.blockReason)); + let blocks = ( + await PluginEventHandler.preMessageEvent({ + message + } as PreMessageEventArgs) + ).filter((x) => x.cancel); + if (blocks.length > 0) + throw new HTTPError( + "Message denied.", + 400, + blocks.filter((x) => x.blockReason).map((x) => x.blockReason) + ); await Promise.all([ read_state.save(), diff --git a/src/api/routes/experiments.ts b/src/api/routes/experiments.ts index cd206d79f..94a9734f7 100644 --- a/src/api/routes/experiments.ts +++ b/src/api/routes/experiments.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.send({ fingerprint: "", assignments: [], guild_experiments: [] }); }); diff --git a/src/api/routes/guilds/#guild_id/premium.ts b/src/api/routes/guilds/#guild_id/premium.ts index 7b343daf4..5acb0f8f5 100644 --- a/src/api/routes/guilds/#guild_id/premium.ts +++ b/src/api/routes/guilds/#guild_id/premium.ts @@ -21,7 +21,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/subscriptions", route({}), async (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.json([]); }); diff --git a/src/api/routes/partners/#guild_id/requirements.ts b/src/api/routes/partners/#guild_id/requirements.ts index 5e15676ae..0e6b60276 100644 --- a/src/api/routes/partners/#guild_id/requirements.ts +++ b/src/api/routes/partners/#guild_id/requirements.ts @@ -23,9 +23,8 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - // TODO: - // Load from database - // Admin control, but for now it allows anyone to be discoverable + // TODO: Load from database + // TODO: Admin control, but for now it allows anyone to be discoverable res.send({ guild_id: guild_id, diff --git a/src/api/routes/track.ts b/src/api/routes/track.ts index 099da18bc..d2cad8124 100644 --- a/src/api/routes/track.ts +++ b/src/api/routes/track.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.post("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route? res.sendStatus(204); }); diff --git a/src/api/routes/users/@me/activities/statistics/applications.ts b/src/api/routes/users/@me/activities/statistics/applications.ts index 5e797ce87..2675a5ebb 100644 --- a/src/api/routes/users/@me/activities/statistics/applications.ts +++ b/src/api/routes/users/@me/activities/statistics/applications.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.json([]).status(200); }); diff --git a/src/api/routes/users/@me/affinities/guilds.ts b/src/api/routes/users/@me/affinities/guilds.ts index e49661483..9029adc2b 100644 --- a/src/api/routes/users/@me/affinities/guilds.ts +++ b/src/api/routes/users/@me/affinities/guilds.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.status(200).send({ guild_affinities: [] }); }); diff --git a/src/api/routes/users/@me/affinities/users.ts b/src/api/routes/users/@me/affinities/users.ts index 76fb8aa64..953ef7134 100644 --- a/src/api/routes/users/@me/affinities/users.ts +++ b/src/api/routes/users/@me/affinities/users.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.status(200).send({ user_affinities: [], inverse_user_affinities: [] }); }); diff --git a/src/api/routes/users/@me/billing/payment-sources.ts b/src/api/routes/users/@me/billing/payment-sources.ts index 5e797ce87..2675a5ebb 100644 --- a/src/api/routes/users/@me/billing/payment-sources.ts +++ b/src/api/routes/users/@me/billing/payment-sources.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.json([]).status(200); }); diff --git a/src/api/routes/users/@me/devices.ts b/src/api/routes/users/@me/devices.ts index 099da18bc..e04ff26df 100644 --- a/src/api/routes/users/@me/devices.ts +++ b/src/api/routes/users/@me/devices.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.post("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.sendStatus(204); }); diff --git a/src/api/routes/users/@me/email-settings.ts b/src/api/routes/users/@me/email-settings.ts index 4c9e16b14..87616b477 100644 --- a/src/api/routes/users/@me/email-settings.ts +++ b/src/api/routes/users/@me/email-settings.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.json({ categories: { social: true, diff --git a/src/api/routes/users/@me/entitlements.ts b/src/api/routes/users/@me/entitlements.ts index 7f5526226..c364e1582 100644 --- a/src/api/routes/users/@me/entitlements.ts +++ b/src/api/routes/users/@me/entitlements.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/gifts", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: implement route res.json([]).status(200); }); diff --git a/src/api/routes/users/@me/library.ts b/src/api/routes/users/@me/library.ts index 54d9b04fd..78b7d8c0f 100644 --- a/src/api/routes/users/@me/library.ts +++ b/src/api/routes/users/@me/library.ts @@ -22,7 +22,7 @@ import { route } from "@spacebar/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: Add library route res.status(200).send([]); }); diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts index 362152d7f..6553a7b8a 100644 --- a/src/api/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts @@ -26,6 +26,7 @@ import { import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; import { verifyToken } from "node-2fa"; +import { route } from "../../../../.."; const router = Router(); diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 2a6d416ef..ecc812375 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -436,11 +436,15 @@ export async function postHandleMessage(message: Message) { export async function sendMessage(opts: MessageOptions) { const message = await handleMessage({ ...opts, timestamp: new Date() }); - if((await PluginEventHandler.preMessageEvent({ - message - } as PreMessageEventArgs)).filter(x=>x.cancel).length > 0) return; + if ( + ( + await PluginEventHandler.preMessageEvent({ + message + } as PreMessageEventArgs) + ).filter((x) => x.cancel).length > 0 + ) + return; - //TODO: check this, removed toJSON call await Promise.all([ Message.insert(message), emitEvent({ diff --git a/src/plugins/PluginIndex.ts b/src/plugins/PluginIndex.ts index 502161a16..2688d0bf4 100644 --- a/src/plugins/PluginIndex.ts +++ b/src/plugins/PluginIndex.ts @@ -1,6 +1,5 @@ -import { Plugin } from "util/plugin"; import * as example_plugin from "./example-plugin/TestPlugin"; export const PluginIndex: any = { - "example-plugin": new example_plugin.default(), -}; \ No newline at end of file + "example-plugin": new example_plugin.default() +}; diff --git a/src/plugins/example-plugin/TestPlugin.ts b/src/plugins/example-plugin/TestPlugin.ts index 18e634f7f..da25c474b 100644 --- a/src/plugins/example-plugin/TestPlugin.ts +++ b/src/plugins/example-plugin/TestPlugin.ts @@ -1,26 +1,36 @@ -import { setupListener } from "@fosscord/gateway"; -import { Channel, Guild, Plugin, PluginLoadedEventArgs, PluginLoader, PluginManifest, PreMessageEventArgs, PreMessageEventResult } from "@fosscord/util"; +import { + Channel, + Guild, + Plugin, + PluginLoadedEventArgs, + PluginLoader, + PluginManifest, + PreMessageEventArgs, + PreMessageEventResult +} from "@fosscord/util"; import { TestSettings } from "./TestSettings"; export default class TestPlugin implements Plugin { - pluginManifest?: PluginManifest | undefined; - settings: TestSettings = new TestSettings(); - async onPluginLoaded(env: PluginLoadedEventArgs) { - console.log("Test plugin active!"); - if(this.pluginManifest) this.settings = PluginLoader.getPluginConfig(this.pluginManifest.id, this.settings) as TestSettings; - } - async onPreMessage(data: PreMessageEventArgs): Promise { - let channel = await Channel.findOne({ where: { id: data.message.channel_id } }); - let guild = await Guild.findOne({ where: { id: data.message.guild_id } }); - let block = data.message.content?.includes('UwU'); - - let result = {cancel: block} as PreMessageEventResult; + pluginManifest?: PluginManifest | undefined; + settings: TestSettings = new TestSettings(); + async onPluginLoaded(env: PluginLoadedEventArgs) { + console.log("Test plugin active!"); + if (this.pluginManifest) this.settings = PluginLoader.getPluginConfig(this.pluginManifest.id, this.settings) as TestSettings; + } + async onPreMessage(data: PreMessageEventArgs): Promise { + let channel = await Channel.findOne({ where: { id: data.message.channel_id } }); + let guild = await Guild.findOne({ where: { id: data.message.guild_id } }); + let block = data.message.content?.includes("UwU"); - if(block) { - console.log(`[TestPlugin] Blocked message in ${guild?.name}/#${channel?.name} by ${data.message.author?.username}: ${data.message.content}`); - result.blockReason = "[TestPlugin] Your message contains UwU! Get bamboozled!"; - } + let result = { cancel: block } as PreMessageEventResult; - return result; - } -} \ No newline at end of file + if (block) { + console.log( + `[TestPlugin] Blocked message in ${guild?.name}/#${channel?.name} by ${data.message.author?.username}: ${data.message.content}` + ); + result.blockReason = "[TestPlugin] Your message contains UwU! Get bamboozled!"; + } + + return result; + } +} diff --git a/src/plugins/example-plugin/TestSettings.ts b/src/plugins/example-plugin/TestSettings.ts index d8c521873..f7ec79ff1 100644 --- a/src/plugins/example-plugin/TestSettings.ts +++ b/src/plugins/example-plugin/TestSettings.ts @@ -1,11 +1,11 @@ export class TestSettings { - someInt: number = 10; - someStr: string = "asdf"; - someBool: boolean = true; - someDate: Date = new Date(); - subSettings: SubSettings = new SubSettings(); + someInt: number = 10; + someStr: string = "asdf"; + someBool: boolean = true; + someDate: Date = new Date(); + subSettings: SubSettings = new SubSettings(); } export class SubSettings { - someStr: string = "jklm"; -} \ No newline at end of file + someStr: string = "jklm"; +} diff --git a/src/plugins/example-plugin/plugin.json b/src/plugins/example-plugin/plugin.json index f6c1b7ff7..4db011521 100644 --- a/src/plugins/example-plugin/plugin.json +++ b/src/plugins/example-plugin/plugin.json @@ -1,10 +1,8 @@ { - "id": "example-plugin", - "name": "Fosscord example plugin", - "authors": [ - "The Arcane Brony" - ], - "repository": "https://github.com/fosscord/fosscord-server", - "license": "", - "mainClass": "TestPlugin" + "id": "example-plugin", + "name": "Fosscord example plugin", + "authors": ["The Arcane Brony"], + "repository": "https://github.com/fosscord/fosscord-server", + "license": "", + "mainClass": "TestPlugin" } diff --git a/src/util/config/Config.ts b/src/util/config/Config.ts index 56054641d..94a98ef77 100644 --- a/src/util/config/Config.ts +++ b/src/util/config/Config.ts @@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ diff --git a/src/util/entities/PluginConfig.ts b/src/util/entities/PluginConfig.ts index 87de5167e..2fb0c0c20 100644 --- a/src/util/entities/PluginConfig.ts +++ b/src/util/entities/PluginConfig.ts @@ -8,4 +8,4 @@ export class PluginConfigEntity extends BaseClassWithoutId { @Column({ type: "simple-json", nullable: true }) value: number | boolean | null | string | Date | undefined; -} \ No newline at end of file +} diff --git a/src/util/entities/Session.ts b/src/util/entities/Session.ts index 5c3d5a4fd..cd90830cd 100644 --- a/src/util/entities/Session.ts +++ b/src/util/entities/Session.ts @@ -23,7 +23,7 @@ import { ClientStatus, Status } from "../interfaces/Status"; import { Activity } from "../interfaces/Activity"; import { dbEngine } from "../util/Database"; -//TODO we need to remove all sessions on server start because if the server crashes without closing websockets it won't delete them +//TODO: we need to remove all sessions on server start because if the server crashes without closing websockets it won't delete them @Entity({ name: "sessions", @@ -40,7 +40,7 @@ export class Session extends BaseClass { }) user: User; - //TODO check, should be 32 char long hex string + //TODO: check, should be 32 char long hex string @Column({ nullable: false, select: false }) session_id: string; @@ -58,7 +58,7 @@ export class Session extends BaseClass { client_status: ClientStatus; @Column({ nullable: false, type: "varchar" }) - status: Status; //TODO enum + status: Status; //TODO: enum } export const PrivateSessionProjection: (keyof Session)[] = [ diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index 7bd632963..ee04e245d 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -348,7 +348,7 @@ export class User extends BaseClass { * date_of_birth, * req, * } - * @return {*} + * @return {*} * @memberof User */ static async register({ diff --git a/src/util/entities/VoiceState.ts b/src/util/entities/VoiceState.ts index 549d667f4..080bd2d46 100644 --- a/src/util/entities/VoiceState.ts +++ b/src/util/entities/VoiceState.ts @@ -87,7 +87,7 @@ export class VoiceState extends BaseClass { // @ManyToOne(() => Member, { // onDelete: "CASCADE", // }) - //TODO find a way to make it work without breaking Guild.voice_states + //TODO: find a way to make it work without breaking Guild.voice_states member: Member; @Column() diff --git a/src/util/entities/index.ts b/src/util/entities/index.ts index 1cbe2451f..ba0fcc46e 100644 --- a/src/util/entities/index.ts +++ b/src/util/entities/index.ts @@ -39,6 +39,7 @@ export * from "./Member"; export * from "./Message"; export * from "./Migration"; export * from "./Note"; +export * from "./PluginConfig"; export * from "./RateLimit"; export * from "./ReadState"; export * from "./Recipient"; @@ -58,8 +59,3 @@ export * from "./UserSettings"; export * from "./ValidRegistrationTokens"; export * from "./VoiceState"; export * from "./Webhook"; -export * from "./ClientRelease"; -export * from "./BackupCodes"; -export * from "./Note"; -export * from "./UserSettings"; -export * from "./PluginConfig"; diff --git a/src/util/migrations/mariadb/1660404644371-PluginConfigs.ts b/src/util/migrations/mariadb/1660404644371-PluginConfigs.ts index 73953ca83..6cbc594c9 100644 --- a/src/util/migrations/mariadb/1660404644371-PluginConfigs.ts +++ b/src/util/migrations/mariadb/1660404644371-PluginConfigs.ts @@ -1,42 +1,41 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class PluginConfigs1660404644371 implements MigrationInterface { - name = 'PluginConfigs1660404644371' + name = "PluginConfigs1660404644371"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE \`plugin_config\` ( \`key\` varchar(255) NOT NULL, \`value\` text NULL, PRIMARY KEY (\`key\`) ) ENGINE = InnoDB `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` ADD \`flags\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` ADD \`default_thread_rate_limit_per_user\` int NULL `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` DROP COLUMN \`flags\` `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE \`plugin_config\` `); - await queryRunner.query(` + await queryRunner.query(` CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) `); - } - + } } diff --git a/src/util/migrations/mariadb/1660534571948-UpdateMigrations.ts b/src/util/migrations/mariadb/1660534571948-UpdateMigrations.ts index d799fe808..eee8c39c2 100644 --- a/src/util/migrations/mariadb/1660534571948-UpdateMigrations.ts +++ b/src/util/migrations/mariadb/1660534571948-UpdateMigrations.ts @@ -1,229 +1,228 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class UpdateMigrations1660534571948 implements MigrationInterface { - name = 'UpdateMigrations1660534571948' + name = "UpdateMigrations1660534571948"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` ALTER TABLE \`applications\` DROP FOREIGN KEY \`FK_e5bf78cdbbe9ba91062d74c5aba\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` `); - await queryRunner.query(` + await queryRunner.query(` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE \`plugin_config\` ( \`key\` varchar(255) NOT NULL, \`value\` text NULL, PRIMARY KEY (\`key\`) ) ENGINE = InnoDB `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`rpc_origins\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`primary_sku_id\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`slug\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`guild_id\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`type\` text NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`hook\` tinyint NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`redirect_uris\` text NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`rpc_application_state\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`store_application_state\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`verification_state\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`interactions_endpoint_url\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`integration_public\` tinyint NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`integration_require_code_grant\` tinyint NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`discoverability_state\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`discovery_eligibility_flags\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`tags\` text NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`install_params\` text NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`bot_user_id\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD UNIQUE INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` (\`bot_user_id\`) `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` ADD \`flags\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` ADD \`default_thread_rate_limit_per_user\` int NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` CHANGE \`description\` \`description\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`flags\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`flags\` int NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` CREATE UNIQUE INDEX \`REL_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` (\`bot_user_id\`) `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD CONSTRAINT \`FK_2ce5a55796fe4c2f77ece57a647\` FOREIGN KEY (\`bot_user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`invites\` ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP FOREIGN KEY \`FK_2ce5a55796fe4c2f77ece57a647\` `); - await queryRunner.query(` + await queryRunner.query(` DROP INDEX \`REL_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`flags\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`flags\` varchar(255) NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` CHANGE \`description\` \`description\` varchar(255) NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`channels\` DROP COLUMN \`flags\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`bot_user_id\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`install_params\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`tags\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`discovery_eligibility_flags\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`discoverability_state\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`integration_require_code_grant\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`integration_public\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`interactions_endpoint_url\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`verification_state\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`store_application_state\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`rpc_application_state\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`redirect_uris\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`hook\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` DROP COLUMN \`type\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`guild_id\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`slug\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`primary_sku_id\` varchar(255) NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD \`rpc_origins\` text NULL `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE \`plugin_config\` `); - await queryRunner.query(` + await queryRunner.query(` CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`invites\` ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`applications\` ADD CONSTRAINT \`FK_e5bf78cdbbe9ba91062d74c5aba\` FOREIGN KEY (\`guild_id\`) REFERENCES \`guilds\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION `); - } - + } } diff --git a/src/util/migrations/postgres/1660404619978-PluginConfigs.ts b/src/util/migrations/postgres/1660404619978-PluginConfigs.ts index d8a5ab4d8..21d4757c6 100644 --- a/src/util/migrations/postgres/1660404619978-PluginConfigs.ts +++ b/src/util/migrations/postgres/1660404619978-PluginConfigs.ts @@ -1,22 +1,21 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class PluginConfigs1660404619978 implements MigrationInterface { - name = 'PluginConfigs1660404619978' + name = "PluginConfigs1660404619978"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` CREATE TABLE "plugin_config" ( "key" character varying NOT NULL, "value" text, CONSTRAINT "PK_aa929ece56c59233b85a16f62ef" PRIMARY KEY ("key") ) `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` DROP TABLE "plugin_config" `); - } - + } } diff --git a/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts b/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts index 54a59fab0..8f5e364b0 100644 --- a/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts +++ b/src/util/migrations/sqlite/1660534525799-UpdateMigrations.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class UpdateMigrations1660534525799 implements MigrationInterface { - name = 'UpdateMigrations1660534525799' + name = "UpdateMigrations1660534525799"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` CREATE TABLE "temporary_applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -28,7 +28,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_applications"( "id", "name", @@ -69,14 +69,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "guild_id" FROM "applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_applications" RENAME TO "applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -96,7 +96,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_applications"( "id", "name", @@ -129,14 +129,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "team_id" FROM "applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_applications" RENAME TO "applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -171,7 +171,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_applications"( "id", "name", @@ -204,14 +204,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "team_id" FROM "applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_applications" RENAME TO "applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -246,7 +246,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_applications"( "id", "name", @@ -307,14 +307,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "bot_user_id" FROM "applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_applications" RENAME TO "applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -350,7 +350,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_2ce5a55796fe4c2f77ece57a647" FOREIGN KEY ("bot_user_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_applications"( "id", "name", @@ -411,21 +411,21 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "bot_user_id" FROM "applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_applications" RENAME TO "applications" `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` ALTER TABLE "applications" RENAME TO "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -460,7 +460,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "applications"( "id", "name", @@ -521,14 +521,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "bot_user_id" FROM "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "applications" RENAME TO "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -563,7 +563,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "applications"( "id", "name", @@ -624,14 +624,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "bot_user_id" FROM "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "applications" RENAME TO "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -651,7 +651,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "applications"( "id", "name", @@ -684,14 +684,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "team_id" FROM "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "applications" RENAME TO "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -715,7 +715,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "applications"( "id", "name", @@ -748,14 +748,14 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "team_id" FROM "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "applications" RENAME TO "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "applications" ( "id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, @@ -780,7 +780,7 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { CONSTRAINT "FK_e57508958bf92b9d9d25231b5e8" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "applications"( "id", "name", @@ -821,9 +821,8 @@ export class UpdateMigrations1660534525799 implements MigrationInterface { "guild_id" FROM "temporary_applications" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_applications" `); - } - + } } diff --git a/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts b/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts index 665df6c5b..17f1fb162 100644 --- a/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts +++ b/src/util/migrations/sqlite/1660565540177-sync_rebase_15aug2022.ts @@ -1,18 +1,17 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class syncRebase15aug20221660565540177 implements MigrationInterface { - name = 'syncRebase15aug20221660565540177' + name = "syncRebase15aug20221660565540177"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` CREATE TABLE "plugin_config" ("key" varchar PRIMARY KEY NOT NULL, "value" text) `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` DROP TABLE "plugin_config" `); - } - + } } diff --git a/src/util/plugin/Plugin.ts b/src/util/plugin/Plugin.ts index 6a6f03f41..9bccba9d7 100644 --- a/src/util/plugin/Plugin.ts +++ b/src/util/plugin/Plugin.ts @@ -1,14 +1,27 @@ -import EventEmitter from "events"; -import { PluginLoadedEventArgs, PluginManifest, TypedEventEmitter } from "@fosscord/util"; -import { PluginConfig } from "./PluginConfig"; -import { PreRegisterEventArgs, PreRegisterEventResult, OnRegisterEventArgs } from '.'; -import { PreMessageEventArgs, PreMessageEventResult, OnMessageEventArgs } from '.'; -import { PreLoginEventArgs, PreLoginEventResult, OnLoginEventArgs } from '.'; -import { PreGuildCreateEventArgs, PreGuildCreateEventResult, OnGuildCreateEventArgs } from '.'; -import { PreChannelCreateEventArgs, PreChannelCreateEventResult, OnChannelCreateEventArgs } from '.'; -import { PreTypingEventArgs, PreTypingEventResult, OnTypingEventArgs } from '.'; -import { PreStatusChangeEventArgs, PreStatusChangeEventResult, OnStatusChangeEventArgs } from '.'; - +import { + OnChannelCreateEventArgs, + OnGuildCreateEventArgs, + OnLoginEventArgs, + OnMessageEventArgs, + OnRegisterEventArgs, + OnStatusChangeEventArgs, + OnTypingEventArgs, + PreChannelCreateEventArgs, + PreChannelCreateEventResult, + PreGuildCreateEventArgs, + PreGuildCreateEventResult, + PreLoginEventArgs, + PreLoginEventResult, + PreMessageEventArgs, + PreMessageEventResult, + PreRegisterEventArgs, + PreRegisterEventResult, + PreStatusChangeEventArgs, + PreStatusChangeEventResult, + PreTypingEventArgs, + PreTypingEventResult +} from "."; +import { PluginLoadedEventArgs, PluginManifest } from ".."; /*type PluginEvents = { error: (error: Error | unknown) => void; @@ -27,134 +40,131 @@ export class Plugin { pluginPath?: string; pluginManifest?: PluginManifest; /** - * + * * * @param {PluginLoadedEventArgs} args Info about plugin environment * @memberof Plugin */ - async onPluginLoaded?(args?: PluginLoadedEventArgs) { - - } + async onPluginLoaded?(args?: PluginLoadedEventArgs) {} //generated /** - * RegisterEvent: document me - * - * @param {OnRegisterEventArgs} args Info about what's going on - * @memberof Plugin - */ + * RegisterEvent: document me + * + * @param {OnRegisterEventArgs} args Info about what's going on + * @memberof Plugin + */ async onRegister?(args: OnRegisterEventArgs): Promise; /** - * RegisterEvent: Executed before changes are announced - * document me. - * - * @param {PreRegisterEventArgs} args Info about what's going on - * @return {PreRegisterEventResult} How event should be handled - * @memberof Plugin - */ + * RegisterEvent: Executed before changes are announced + * document me. + * + * @param {PreRegisterEventArgs} args Info about what's going on + * @return {PreRegisterEventResult} How event should be handled + * @memberof Plugin + */ async onPreRegister?(args: PreRegisterEventArgs): Promise; /** - * MessageEvent: document me - * - * @param {OnMessageEventArgs} args Info about what's going on - * @memberof Plugin - */ + * MessageEvent: document me + * + * @param {OnMessageEventArgs} args Info about what's going on + * @memberof Plugin + */ async onMessage?(args: OnMessageEventArgs): Promise; /** - * MessageEvent: Executed before changes are announced - * document me. - * - * @param {PreMessageEventArgs} args Info about what's going on - * @return {PreMessageEventResult} How event should be handled - * @memberof Plugin - */ + * MessageEvent: Executed before changes are announced + * document me. + * + * @param {PreMessageEventArgs} args Info about what's going on + * @return {PreMessageEventResult} How event should be handled + * @memberof Plugin + */ async onPreMessage?(args: PreMessageEventArgs): Promise; /** - * LoginEvent: document me - * - * @param {OnLoginEventArgs} args Info about what's going on - * @memberof Plugin - */ + * LoginEvent: document me + * + * @param {OnLoginEventArgs} args Info about what's going on + * @memberof Plugin + */ async onLogin?(args: OnLoginEventArgs): Promise; /** - * LoginEvent: Executed before changes are announced - * document me. - * - * @param {PreLoginEventArgs} args Info about what's going on - * @return {PreLoginEventResult} How event should be handled - * @memberof Plugin - */ + * LoginEvent: Executed before changes are announced + * document me. + * + * @param {PreLoginEventArgs} args Info about what's going on + * @return {PreLoginEventResult} How event should be handled + * @memberof Plugin + */ async onPreLogin?(args: PreLoginEventArgs): Promise; /** - * GuildCreateEvent: document me - * - * @param {OnGuildCreateEventArgs} args Info about what's going on - * @memberof Plugin - */ + * GuildCreateEvent: document me + * + * @param {OnGuildCreateEventArgs} args Info about what's going on + * @memberof Plugin + */ async onGuildCreate?(args: OnGuildCreateEventArgs): Promise; /** - * GuildCreateEvent: Executed before changes are announced - * document me. - * - * @param {PreGuildCreateEventArgs} args Info about what's going on - * @return {PreGuildCreateEventResult} How event should be handled - * @memberof Plugin - */ + * GuildCreateEvent: Executed before changes are announced + * document me. + * + * @param {PreGuildCreateEventArgs} args Info about what's going on + * @return {PreGuildCreateEventResult} How event should be handled + * @memberof Plugin + */ async onPreGuildCreate?(args: PreGuildCreateEventArgs): Promise; /** - * ChannelCreateEvent: document me - * - * @param {OnChannelCreateEventArgs} args Info about what's going on - * @memberof Plugin - */ + * ChannelCreateEvent: document me + * + * @param {OnChannelCreateEventArgs} args Info about what's going on + * @memberof Plugin + */ async onChannelCreate?(args: OnChannelCreateEventArgs): Promise; /** - * ChannelCreateEvent: Executed before changes are announced - * document me. - * - * @param {PreChannelCreateEventArgs} args Info about what's going on - * @return {PreChannelCreateEventResult} How event should be handled - * @memberof Plugin - */ + * ChannelCreateEvent: Executed before changes are announced + * document me. + * + * @param {PreChannelCreateEventArgs} args Info about what's going on + * @return {PreChannelCreateEventResult} How event should be handled + * @memberof Plugin + */ async onPreChannelCreate?(args: PreChannelCreateEventArgs): Promise; /** - * TypingEvent: document me - * - * @param {OnTypingEventArgs} args Info about what's going on - * @memberof Plugin - */ + * TypingEvent: document me + * + * @param {OnTypingEventArgs} args Info about what's going on + * @memberof Plugin + */ async onTyping?(args: OnTypingEventArgs): Promise; /** - * TypingEvent: Executed before changes are announced - * document me. - * - * @param {PreTypingEventArgs} args Info about what's going on - * @return {PreTypingEventResult} How event should be handled - * @memberof Plugin - */ + * TypingEvent: Executed before changes are announced + * document me. + * + * @param {PreTypingEventArgs} args Info about what's going on + * @return {PreTypingEventResult} How event should be handled + * @memberof Plugin + */ async onPreTyping?(args: PreTypingEventArgs): Promise; /** - * StatusChangeEvent: document me - * - * @param {OnStatusChangeEventArgs} args Info about what's going on - * @memberof Plugin - */ + * StatusChangeEvent: document me + * + * @param {OnStatusChangeEventArgs} args Info about what's going on + * @memberof Plugin + */ async onStatusChange?(args: OnStatusChangeEventArgs): Promise; /** - * StatusChangeEvent: Executed before changes are announced - * document me. - * - * @param {PreStatusChangeEventArgs} args Info about what's going on - * @return {PreStatusChangeEventResult} How event should be handled - * @memberof Plugin - */ + * StatusChangeEvent: Executed before changes are announced + * document me. + * + * @param {PreStatusChangeEventArgs} args Info about what's going on + * @return {PreStatusChangeEventResult} How event should be handled + * @memberof Plugin + */ async onPreStatusChange?(args: PreStatusChangeEventArgs): Promise; - } diff --git a/src/util/plugin/PluginConfig.ts b/src/util/plugin/PluginConfig.ts index 883bca7cb..b9c8aef02 100644 --- a/src/util/plugin/PluginConfig.ts +++ b/src/util/plugin/PluginConfig.ts @@ -1,6 +1,6 @@ import fs from "fs"; -import { OrmUtils, Environment } from ".."; -import { PluginConfigEntity } from "util/entities/PluginConfig"; +import { Environment } from ".."; +import { PluginConfigEntity } from "../entities/PluginConfig"; // TODO: yaml instead of json const overridePath = process.env.PLUGIN_CONFIG_PATH ?? ""; @@ -14,26 +14,28 @@ let pairs: PluginConfigEntity[]; export const PluginConfig = { init: async function init() { if (config) return config; - console.log('[PluginConfig] Loading configuration...') + console.log("[PluginConfig] Loading configuration..."); pairs = await PluginConfigEntity.find(); config = pairsToConfig(pairs); //config = (config || {}).merge(new ConfigValue()); //config = OrmUtils.mergeDeep(new ConfigValue(), config) - if(process.env.PLUGIN_CONFIG_PATH) + if (process.env.PLUGIN_CONFIG_PATH) try { const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" })); config = overrideConfig.merge(config); } catch (error) { fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); } - + return this.set(config); }, get: function get() { - if(!config) { - if(Environment.isDebug) - console.log("Oops.. trying to get config without config existing... Returning defaults... (Is the database still initialising?)"); + if (!config) { + if (Environment.isDebug) + console.log( + "Oops.. trying to get config without config existing... Returning defaults... (Is the database still initialising?)" + ); return {}; } return config; @@ -43,7 +45,7 @@ export const PluginConfig = { config = val.merge(config); return applyConfig(config); - }, + } }; function applyConfig(val: any) { @@ -56,17 +58,14 @@ function applyConfig(val: any) { pair.key = key; pair.value = obj; - if(!pair.key || pair.key == null) { - console.log(`[PluginConfig] WARN: Empty key`) + if (!pair.key || pair.key == null) { + console.log(`[PluginConfig] WARN: Empty key`); console.log(pair); - if(Environment.isDebug) debugger; - } - else - return pair.save(); + if (Environment.isDebug) debugger; + } else return pair.save(); } - if(process.env.PLUGIN_CONFIG_PATH) { - if(Environment.isDebug) - console.log(`Writing config: ${process.env.PLUGIN_CONFIG_PATH}`) + if (process.env.PLUGIN_CONFIG_PATH) { + if (Environment.isDebug) console.log(`Writing config: ${process.env.PLUGIN_CONFIG_PATH}`); fs.writeFileSync(overridePath, JSON.stringify(val, null, 4)); } diff --git a/src/util/plugin/PluginEventHandler.ts b/src/util/plugin/PluginEventHandler.ts index d5fc67f4c..3ed1efa60 100644 --- a/src/util/plugin/PluginEventHandler.ts +++ b/src/util/plugin/PluginEventHandler.ts @@ -1,67 +1,102 @@ -import { PreRegisterEventArgs, OnRegisterEventArgs, PreRegisterEventResult } from './event_types'; -import { PreMessageEventArgs, OnMessageEventArgs, PreMessageEventResult } from './event_types'; -import { PreLoginEventArgs, OnLoginEventArgs, PreLoginEventResult } from './event_types'; -import { PreGuildCreateEventArgs, OnGuildCreateEventArgs, PreGuildCreateEventResult } from './event_types'; -import { PreChannelCreateEventArgs, OnChannelCreateEventArgs, PreChannelCreateEventResult } from './event_types'; -import { PreTypingEventArgs, OnTypingEventArgs, PreTypingEventResult } from './event_types'; -import { PreStatusChangeEventArgs, OnStatusChangeEventArgs, PreStatusChangeEventResult } from './event_types'; import { PluginStore } from "."; +import { + OnChannelCreateEventArgs, + OnGuildCreateEventArgs, + OnLoginEventArgs, + OnMessageEventArgs, + OnRegisterEventArgs, + OnStatusChangeEventArgs, + OnTypingEventArgs, + PreChannelCreateEventArgs, + PreChannelCreateEventResult, + PreGuildCreateEventArgs, + PreGuildCreateEventResult, + PreLoginEventArgs, + PreLoginEventResult, + PreMessageEventArgs, + PreMessageEventResult, + PreRegisterEventArgs, + PreRegisterEventResult, + PreStatusChangeEventArgs, + PreStatusChangeEventResult, + PreTypingEventArgs, + PreTypingEventResult +} from "./event_types"; export class PluginEventHandler { - public static async preRegisterEvent(args: PreRegisterEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreRegister).map(x=>x.onPreRegister && x.onPreRegister(args)))).filter(x=>x) as PreRegisterEventResult[]; - } - - public static async onRegisterEvent(args: OnRegisterEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onRegister).map(x=>x.onRegister && x.onRegister(args))); - } - - public static async preMessageEvent(args: PreMessageEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreMessage).map(x=>x.onPreMessage && x.onPreMessage(args)))).filter(x=>x) as PreMessageEventResult[]; - } - - public static async onMessageEvent(args: OnMessageEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onMessage).map(x=>x.onMessage && x.onMessage(args))); - } - - public static async preLoginEvent(args: PreLoginEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreLogin).map(x=>x.onPreLogin && x.onPreLogin(args)))).filter(x=>x) as PreLoginEventResult[]; - } - - public static async onLoginEvent(args: OnLoginEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onLogin).map(x=>x.onLogin && x.onLogin(args))); - } - - public static async preGuildCreateEvent(args: PreGuildCreateEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreGuildCreate).map(x=>x.onPreGuildCreate && x.onPreGuildCreate(args)))).filter(x=>x) as PreGuildCreateEventResult[]; - } - - public static async onGuildCreateEvent(args: OnGuildCreateEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onGuildCreate).map(x=>x.onGuildCreate && x.onGuildCreate(args))); - } - - public static async preChannelCreateEvent(args: PreChannelCreateEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreChannelCreate).map(x=>x.onPreChannelCreate && x.onPreChannelCreate(args)))).filter(x=>x) as PreChannelCreateEventResult[]; - } - - public static async onChannelCreateEvent(args: OnChannelCreateEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onChannelCreate).map(x=>x.onChannelCreate && x.onChannelCreate(args))); - } - - public static async preTypingEvent(args: PreTypingEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreTyping).map(x=>x.onPreTyping && x.onPreTyping(args)))).filter(x=>x) as PreTypingEventResult[]; - } - - public static async onTypingEvent(args: OnTypingEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onTyping).map(x=>x.onTyping && x.onTyping(args))); - } - - public static async preStatusChangeEvent(args: PreStatusChangeEventArgs): Promise { - return (await Promise.all(PluginStore.plugins.filter(x=>x.onPreStatusChange).map(x=>x.onPreStatusChange && x.onPreStatusChange(args)))).filter(x=>x) as PreStatusChangeEventResult[]; - } - - public static async onStatusChangeEvent(args: OnStatusChangeEventArgs): Promise { - await Promise.all(PluginStore.plugins.filter(x=>x.onStatusChange).map(x=>x.onStatusChange && x.onStatusChange(args))); - } - + public static async preRegisterEvent(args: PreRegisterEventArgs): Promise { + return ( + await Promise.all(PluginStore.plugins.filter((x) => x.onPreRegister).map((x) => x.onPreRegister && x.onPreRegister(args))) + ).filter((x) => x) as PreRegisterEventResult[]; + } + + public static async onRegisterEvent(args: OnRegisterEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onRegister).map((x) => x.onRegister && x.onRegister(args))); + } + + public static async preMessageEvent(args: PreMessageEventArgs): Promise { + return ( + await Promise.all(PluginStore.plugins.filter((x) => x.onPreMessage).map((x) => x.onPreMessage && x.onPreMessage(args))) + ).filter((x) => x) as PreMessageEventResult[]; + } + + public static async onMessageEvent(args: OnMessageEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onMessage).map((x) => x.onMessage && x.onMessage(args))); + } + + public static async preLoginEvent(args: PreLoginEventArgs): Promise { + return (await Promise.all(PluginStore.plugins.filter((x) => x.onPreLogin).map((x) => x.onPreLogin && x.onPreLogin(args)))).filter( + (x) => x + ) as PreLoginEventResult[]; + } + + public static async onLoginEvent(args: OnLoginEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onLogin).map((x) => x.onLogin && x.onLogin(args))); + } + + public static async preGuildCreateEvent(args: PreGuildCreateEventArgs): Promise { + return ( + await Promise.all( + PluginStore.plugins.filter((x) => x.onPreGuildCreate).map((x) => x.onPreGuildCreate && x.onPreGuildCreate(args)) + ) + ).filter((x) => x) as PreGuildCreateEventResult[]; + } + + public static async onGuildCreateEvent(args: OnGuildCreateEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onGuildCreate).map((x) => x.onGuildCreate && x.onGuildCreate(args))); + } + + public static async preChannelCreateEvent(args: PreChannelCreateEventArgs): Promise { + return ( + await Promise.all( + PluginStore.plugins.filter((x) => x.onPreChannelCreate).map((x) => x.onPreChannelCreate && x.onPreChannelCreate(args)) + ) + ).filter((x) => x) as PreChannelCreateEventResult[]; + } + + public static async onChannelCreateEvent(args: OnChannelCreateEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onChannelCreate).map((x) => x.onChannelCreate && x.onChannelCreate(args))); + } + + public static async preTypingEvent(args: PreTypingEventArgs): Promise { + return ( + await Promise.all(PluginStore.plugins.filter((x) => x.onPreTyping).map((x) => x.onPreTyping && x.onPreTyping(args))) + ).filter((x) => x) as PreTypingEventResult[]; + } + + public static async onTypingEvent(args: OnTypingEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onTyping).map((x) => x.onTyping && x.onTyping(args))); + } + + public static async preStatusChangeEvent(args: PreStatusChangeEventArgs): Promise { + return ( + await Promise.all( + PluginStore.plugins.filter((x) => x.onPreStatusChange).map((x) => x.onPreStatusChange && x.onPreStatusChange(args)) + ) + ).filter((x) => x) as PreStatusChangeEventResult[]; + } + + public static async onStatusChangeEvent(args: OnStatusChangeEventArgs): Promise { + await Promise.all(PluginStore.plugins.filter((x) => x.onStatusChange).map((x) => x.onStatusChange && x.onStatusChange(args))); + } } diff --git a/src/util/plugin/PluginLoader.ts b/src/util/plugin/PluginLoader.ts index 4dc0129a2..9f37ed873 100644 --- a/src/util/plugin/PluginLoader.ts +++ b/src/util/plugin/PluginLoader.ts @@ -1,16 +1,16 @@ -import path from "path"; import fs from "fs"; -import { Plugin, PluginLoadedEventArgs, PluginManifest, PluginStore } from "./"; -import { PluginIndex } from "plugins/PluginIndex"; +import path from "path"; +import { OrmUtils } from ".."; +import { PluginIndex } from "../../plugins/PluginIndex"; +import { PluginLoadedEventArgs, PluginManifest, PluginStore } from "./"; import { PluginConfig } from "./PluginConfig"; -import { OrmUtils, PluginConfigEntity } from ".."; const root = process.env.PLUGIN_LOCATION || "dist/plugins"; let pluginsLoaded = false; export class PluginLoader { public static async loadPlugins() { - if(pluginsLoaded) return; + if (pluginsLoaded) return; PluginConfig.init(); console.log(`Plugin root directory: ${path.resolve(root)}`); const dirs = fs.readdirSync(root).filter((x) => { @@ -33,33 +33,31 @@ export class PluginLoader { `Plugin info: ${manifest.name} (${manifest.id}), written by ${manifest.authors}, available at ${manifest.repository}` ); const module_ = PluginIndex[manifest.id]; - + module_.pluginPath = modPath; module_.pluginManifest = manifest; Object.freeze(module_.pluginPath); Object.freeze(module_.pluginManifest); - - if(module_.onPluginLoaded) await module_.onPluginLoaded({} as PluginLoadedEventArgs); + + if (module_.onPluginLoaded) await module_.onPluginLoaded({} as PluginLoadedEventArgs); PluginStore.plugins.push(module_); }); console.log(`Done loading ${PluginStore.plugins.length} plugins!`); } - + public static getPluginConfig(id: string, defaults?: any): any { let cfg = PluginConfig.get()[id]; - if(defaults) { - if(cfg) - cfg = OrmUtils.mergeDeep(defaults, cfg); - else - cfg = defaults; + if (defaults) { + if (cfg) cfg = OrmUtils.mergeDeep(defaults, cfg); + else cfg = defaults; this.setPluginConfig(id, cfg); } - if(!cfg) console.log(`[PluginConfig/WARN] Getting plugin settings for '${id}' returned null! (Did you forget to add settings?)`); + if (!cfg) console.log(`[PluginConfig/WARN] Getting plugin settings for '${id}' returned null! (Did you forget to add settings?)`); return cfg; } public static async setPluginConfig(id: string, config: Partial): Promise { - if(!config) console.log(`[PluginConfig/WARN] ${id} tried to set config=null!`); + if (!config) console.log(`[PluginConfig/WARN] ${id} tried to set config=null!`); await PluginConfig.set({ [id]: OrmUtils.mergeDeep(PluginLoader.getPluginConfig(id) || {}, config) }); } } diff --git a/src/util/plugin/PluginManifest.ts b/src/util/plugin/PluginManifest.ts index 79ecc465a..518202ec4 100644 --- a/src/util/plugin/PluginManifest.ts +++ b/src/util/plugin/PluginManifest.ts @@ -1,10 +1,10 @@ export class PluginManifest { - id: string; - name: string; - authors: string[]; - repository: string; - license: string; - version: string // semver - versionCode: number // integer - mainClass: string; -} \ No newline at end of file + id: string; + name: string; + authors: string[]; + repository: string; + license: string; + version: string; // semver + versionCode: number; // integer + mainClass: string; +} diff --git a/src/util/plugin/PluginStore.ts b/src/util/plugin/PluginStore.ts index 60d7f7b77..8b02f1570 100644 --- a/src/util/plugin/PluginStore.ts +++ b/src/util/plugin/PluginStore.ts @@ -1,9 +1,4 @@ -import path from "path"; -import fs from "fs"; -import { Plugin, PluginLoadedEventArgs, PluginManifest } from "./"; -import { PluginIndex } from "plugins/PluginIndex"; -import { PluginConfig } from "./PluginConfig"; -import { OrmUtils, PluginConfigEntity } from ".."; +import { Plugin } from "./"; const root = process.env.PLUGIN_LOCATION || "dist/plugins"; diff --git a/src/util/plugin/event_types/ChannelCreateEventArgs.ts b/src/util/plugin/event_types/ChannelCreateEventArgs.ts index 87fa36915..eb1033467 100644 --- a/src/util/plugin/event_types/ChannelCreateEventArgs.ts +++ b/src/util/plugin/event_types/ChannelCreateEventArgs.ts @@ -2,16 +2,16 @@ import { Channel, Guild, User } from "util/entities"; import { EventResult } from "."; export interface PreChannelCreateEventArgs { - channel: Channel, - guild: Guild, - user: User + channel: Channel; + guild: Guild; + user: User; } export interface PreChannelCreateEventResult extends EventResult { - channel: Partial + channel: Partial; } export interface OnChannelCreateEventArgs { - channel: Channel, - guild: Guild, - user: User + channel: Channel; + guild: Guild; + user: User; } diff --git a/src/util/plugin/event_types/GuildCreateEventArgs.ts b/src/util/plugin/event_types/GuildCreateEventArgs.ts index 7724b4f33..0df9beb18 100644 --- a/src/util/plugin/event_types/GuildCreateEventArgs.ts +++ b/src/util/plugin/event_types/GuildCreateEventArgs.ts @@ -2,14 +2,14 @@ import { Guild, User } from "util/entities"; import { EventResult } from "."; export interface PreGuildCreateEventArgs { - user: User, - guild: Guild + user: User; + guild: Guild; } export interface PreGuildCreateEventResult extends EventResult { - guild: Partial + guild: Partial; } export interface OnGuildCreateEventArgs { - user: User, - guild: Guild + user: User; + guild: Guild; } diff --git a/src/util/plugin/event_types/LoginEventArgs.ts b/src/util/plugin/event_types/LoginEventArgs.ts index 8f80b69fb..4f10e451b 100644 --- a/src/util/plugin/event_types/LoginEventArgs.ts +++ b/src/util/plugin/event_types/LoginEventArgs.ts @@ -2,14 +2,12 @@ import { User } from "util/entities"; import { EventResult } from "."; export interface PreLoginEventArgs { - ip: String, - user: User -} -export interface PreLoginEventResult extends EventResult { - + ip: String; + user: User; } +export interface PreLoginEventResult extends EventResult {} export interface OnLoginEventArgs { - ip: String, - user: User + ip: String; + user: User; } diff --git a/src/util/plugin/event_types/MessageEventArgs.ts b/src/util/plugin/event_types/MessageEventArgs.ts index ab276429d..01df9b756 100644 --- a/src/util/plugin/event_types/MessageEventArgs.ts +++ b/src/util/plugin/event_types/MessageEventArgs.ts @@ -2,14 +2,14 @@ import { Message, User } from "util/entities"; import { EventResult } from "."; export interface PreMessageEventArgs { - user: User, - message: Message; + user: User; + message: Message; } export interface PreMessageEventResult extends EventResult { - message: Partial + message: Partial; } export interface OnMessageEventArgs { - user: User, - message: Message + user: User; + message: Message; } diff --git a/src/util/plugin/event_types/PluginLoadedEventArgs.ts b/src/util/plugin/event_types/PluginLoadedEventArgs.ts index 58829f152..a585675b9 100644 --- a/src/util/plugin/event_types/PluginLoadedEventArgs.ts +++ b/src/util/plugin/event_types/PluginLoadedEventArgs.ts @@ -1,3 +1 @@ -export interface PluginLoadedEventArgs { - -} \ No newline at end of file +export interface PluginLoadedEventArgs {} diff --git a/src/util/plugin/event_types/RegisterEventArgs.ts b/src/util/plugin/event_types/RegisterEventArgs.ts index d36d7e64e..f3e0fdd4d 100644 --- a/src/util/plugin/event_types/RegisterEventArgs.ts +++ b/src/util/plugin/event_types/RegisterEventArgs.ts @@ -2,16 +2,16 @@ import { User } from "util/entities"; import { EventResult } from "."; export interface PreRegisterEventArgs { - age: any, - user: User, - ip: String + age: any; + user: User; + ip: String; } export interface PreRegisterEventResult extends EventResult { - user: Partial + user: Partial; } export interface OnRegisterEventArgs { - age: any, - user: User, - ip: String + age: any; + user: User; + ip: String; } diff --git a/src/util/plugin/event_types/StatusChangeEventArgs.ts b/src/util/plugin/event_types/StatusChangeEventArgs.ts index c1a671128..b412cffab 100644 --- a/src/util/plugin/event_types/StatusChangeEventArgs.ts +++ b/src/util/plugin/event_types/StatusChangeEventArgs.ts @@ -3,14 +3,14 @@ import { Presence } from "util/interfaces"; import { EventResult } from "."; export interface PreStatusChangeEventArgs { - user: User, - presence: Presence + user: User; + presence: Presence; } export interface PreStatusChangeEventResult extends EventResult { - presence: Partial + presence: Partial; } export interface OnStatusChangeEventArgs { - user: User, - presence: Presence + user: User; + presence: Presence; } diff --git a/src/util/plugin/event_types/TypingEventArgs.ts b/src/util/plugin/event_types/TypingEventArgs.ts index 3ac59b416..694ef83b8 100644 --- a/src/util/plugin/event_types/TypingEventArgs.ts +++ b/src/util/plugin/event_types/TypingEventArgs.ts @@ -2,16 +2,14 @@ import { Channel, Guild, User } from "util/entities"; import { EventResult } from "."; export interface PreTypingEventArgs { - channel: Channel, - guild: Guild, - user: User -} -export interface PreTypingEventResult extends EventResult { - + channel: Channel; + guild: Guild; + user: User; } +export interface PreTypingEventResult extends EventResult {} export interface OnTypingEventArgs { - channel: Channel, - guild: Guild, - user: User + channel: Channel; + guild: Guild; + user: User; } diff --git a/src/util/plugin/event_types/_gen.sh b/src/util/plugin/event_types/_gen.sh index 9f761d1e8..f87693017 100755 --- a/src/util/plugin/event_types/_gen.sh +++ b/src/util/plugin/event_types/_gen.sh @@ -48,8 +48,8 @@ do echo " async onPre${event}?(args: Pre${event}EventArgs): Promise;" ) >> ../plugin.eventfuncs.generated - echo "import { Pre${event}EventArgs, On${event}EventArgs, Pre${event}EventResult } from './event_types';" >> ../PluginEventHandler.ts.1 - echo "import { Pre${event}EventArgs, Pre${event}EventResult, On${event}EventArgs } from '.';" >> ../plugin.imports.generated + echo "import { Pre${event}EventArgs, On${event}EventArgs, Pre${event}EventResult } from \"./event_types\";" >> ../PluginEventHandler.ts.1 + echo "import { Pre${event}EventArgs, Pre${event}EventResult, On${event}EventArgs } from \".\";" >> ../plugin.imports.generated cmp --silent "${event}EventArgs.ts" "${event}EventArgs.ts.generated" && rm -f "${event}EventArgs.ts.generated" done < _pdo diff --git a/src/util/plugin/event_types/base/EventResult.ts b/src/util/plugin/event_types/base/EventResult.ts index f18837cdc..7acaa7751 100644 --- a/src/util/plugin/event_types/base/EventResult.ts +++ b/src/util/plugin/event_types/base/EventResult.ts @@ -1,4 +1,4 @@ export interface EventResult { - cancel?: boolean; - blockReason?: string; -} \ No newline at end of file + cancel?: boolean; + blockReason?: string; +} diff --git a/src/util/plugin/event_types/index.ts b/src/util/plugin/event_types/index.ts index 4a585dc02..773e8dc95 100644 --- a/src/util/plugin/event_types/index.ts +++ b/src/util/plugin/event_types/index.ts @@ -1,3 +1,4 @@ +export * from "./base/index"; export * from "./ChannelCreateEventArgs"; export * from "./GuildCreateEventArgs"; export * from "./LoginEventArgs"; @@ -6,4 +7,3 @@ export * from "./PluginLoadedEventArgs"; export * from "./RegisterEventArgs"; export * from "./StatusChangeEventArgs"; export * from "./TypingEventArgs"; -export * from "./base/index"; diff --git a/src/util/plugin/index.ts b/src/util/plugin/index.ts index 7a2979814..ffc7803ea 100644 --- a/src/util/plugin/index.ts +++ b/src/util/plugin/index.ts @@ -1,7 +1,7 @@ +export * from "./event_types/index"; export * from "./Plugin"; export * from "./PluginConfig"; export * from "./PluginEventHandler"; export * from "./PluginLoader"; export * from "./PluginManifest"; export * from "./PluginStore"; -export * from "./event_types/index"; diff --git a/src/api/util/utility/Base64.ts b/src/util/util/Base64.ts similarity index 100% rename from src/api/util/utility/Base64.ts rename to src/util/util/Base64.ts diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts index 2624a60ac..fe9725657 100644 --- a/src/util/util/Config.ts +++ b/src/util/util/Config.ts @@ -22,7 +22,6 @@ import { OrmUtils } from ".."; import { ConfigValue } from "../config"; import { ConfigEntity } from "../entities/Config"; -// TODO: yaml instead of json const overridePath = process.env.CONFIG_PATH ?? ""; let config: ConfigValue; diff --git a/src/util/util/Environment.ts b/src/util/util/Environment.ts index a6d687855..3ebeb56c5 100644 --- a/src/util/util/Environment.ts +++ b/src/util/util/Environment.ts @@ -1,3 +1,3 @@ export class Environment { - static isDebug: boolean = /--debug|--inspect/.test(process.execArgv.join(' ')); + static isDebug: boolean = /--debug|--inspect/.test(process.execArgv.join(" ")); } diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts index 5aae14c25..209454b02 100644 --- a/src/util/util/Permissions.ts +++ b/src/util/util/Permissions.ts @@ -70,11 +70,14 @@ export class Permissions extends BitField { MANAGE_EMOJIS_AND_STICKERS: BitFlag(30), USE_APPLICATION_COMMANDS: BitFlag(31), REQUEST_TO_SPEAK: BitFlag(32), - // TODO: what is permission 33? + MANAGE_EVENTS: BitFlag(33), MANAGE_THREADS: BitFlag(34), USE_PUBLIC_THREADS: BitFlag(35), USE_PRIVATE_THREADS: BitFlag(36), USE_EXTERNAL_STICKERS: BitFlag(37), + SEND_MESSAGES_IN_THREADS: BitFlag(38), + START_VOICE_ACTIVITIES: BitFlag(39), + MODERATE_MEMBERS: BitFlag(40) /** * CUSTOM PERMISSIONS ideas: diff --git a/src/api/util/utility/RandomInviteID.ts b/src/util/util/RandomInviteID.ts similarity index 100% rename from src/api/util/utility/RandomInviteID.ts rename to src/util/util/RandomInviteID.ts diff --git a/src/util/util/Rights.ts b/src/util/util/Rights.ts index 56d0e28d9..243a84db0 100644 --- a/src/util/util/Rights.ts +++ b/src/util/util/Rights.ts @@ -30,7 +30,7 @@ export type RightResolvable = | RightString; type RightString = keyof typeof Rights.FLAGS; -// TODO: just like roles for members, users should have privilidges which combine multiple rights into one and make it easy to assign +// TODO: just like roles for members, users should have privilides which combine multiple rights into one and make it easy to assign export class Rights extends BitField { constructor(bits: BitFieldResolvable = 0) { diff --git a/src/api/util/utility/ipAddress.ts b/src/util/util/ipAddress.ts similarity index 100% rename from src/api/util/utility/ipAddress.ts rename to src/util/util/ipAddress.ts diff --git a/src/api/util/utility/passwordStrength.ts b/src/util/util/passwordStrength.ts similarity index 100% rename from src/api/util/utility/passwordStrength.ts rename to src/util/util/passwordStrength.ts