mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-28 23:00:36 +00:00
Cleanup, reformat, fix some todos, git hook
fixup! Cleanup, reformat, fix some todos, git hook
This commit is contained in:
@@ -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
|
||||
|
||||
+16
@@ -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"]
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -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'))
|
||||
})
|
||||
@@ -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;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import { Router } from "express";
|
||||
const router: Router = Router();
|
||||
// TODO:
|
||||
// TODO: implement route
|
||||
|
||||
export default router;
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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: [] });
|
||||
});
|
||||
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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: [] });
|
||||
});
|
||||
|
||||
|
||||
@@ -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: [] });
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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(),
|
||||
};
|
||||
"example-plugin": new example_plugin.default()
|
||||
};
|
||||
|
||||
@@ -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<PreMessageEventResult> {
|
||||
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<PreMessageEventResult> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
someStr: string = "jklm";
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@@ -8,4 +8,4 @@ export class PluginConfigEntity extends BaseClassWithoutId {
|
||||
|
||||
@Column({ type: "simple-json", nullable: true })
|
||||
value: number | boolean | null | string | Date | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)[] = [
|
||||
|
||||
@@ -348,7 +348,7 @@ export class User extends BaseClass {
|
||||
* date_of_birth,
|
||||
* req,
|
||||
* }
|
||||
* @return {*}
|
||||
* @return {*}
|
||||
* @memberof User
|
||||
*/
|
||||
static async register({
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class PluginConfigs1660404644371 implements MigrationInterface {
|
||||
name = 'PluginConfigs1660404644371'
|
||||
name = "PluginConfigs1660404644371";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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\`)
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,229 +1,228 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateMigrations1660534571948 implements MigrationInterface {
|
||||
name = 'UpdateMigrations1660534571948'
|
||||
name = "UpdateMigrations1660534571948";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class PluginConfigs1660404619978 implements MigrationInterface {
|
||||
name = 'PluginConfigs1660404619978'
|
||||
name = "PluginConfigs1660404619978";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
DROP TABLE "plugin_config"
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateMigrations1660534525799 implements MigrationInterface {
|
||||
name = 'UpdateMigrations1660534525799'
|
||||
name = "UpdateMigrations1660534525799";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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"
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class syncRebase15aug20221660565540177 implements MigrationInterface {
|
||||
name = 'syncRebase15aug20221660565540177'
|
||||
name = "syncRebase15aug20221660565540177";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE "plugin_config" ("key" varchar PRIMARY KEY NOT NULL, "value" text)
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
DROP TABLE "plugin_config"
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+110
-100
@@ -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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreRegisterEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreMessageEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreLoginEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreGuildCreateEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreChannelCreateEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreTypingEventResult>;
|
||||
/**
|
||||
* 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<void>;
|
||||
|
||||
/**
|
||||
* 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<PreStatusChangeEventResult>;
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PreRegisterEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onRegister).map(x=>x.onRegister && x.onRegister(args)));
|
||||
}
|
||||
|
||||
public static async preMessageEvent(args: PreMessageEventArgs): Promise<PreMessageEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onMessage).map(x=>x.onMessage && x.onMessage(args)));
|
||||
}
|
||||
|
||||
public static async preLoginEvent(args: PreLoginEventArgs): Promise<PreLoginEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onLogin).map(x=>x.onLogin && x.onLogin(args)));
|
||||
}
|
||||
|
||||
public static async preGuildCreateEvent(args: PreGuildCreateEventArgs): Promise<PreGuildCreateEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onGuildCreate).map(x=>x.onGuildCreate && x.onGuildCreate(args)));
|
||||
}
|
||||
|
||||
public static async preChannelCreateEvent(args: PreChannelCreateEventArgs): Promise<PreChannelCreateEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onChannelCreate).map(x=>x.onChannelCreate && x.onChannelCreate(args)));
|
||||
}
|
||||
|
||||
public static async preTypingEvent(args: PreTypingEventArgs): Promise<PreTypingEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onTyping).map(x=>x.onTyping && x.onTyping(args)));
|
||||
}
|
||||
|
||||
public static async preStatusChangeEvent(args: PreStatusChangeEventArgs): Promise<PreStatusChangeEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter(x=>x.onStatusChange).map(x=>x.onStatusChange && x.onStatusChange(args)));
|
||||
}
|
||||
|
||||
public static async preRegisterEvent(args: PreRegisterEventArgs): Promise<PreRegisterEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onRegister).map((x) => x.onRegister && x.onRegister(args)));
|
||||
}
|
||||
|
||||
public static async preMessageEvent(args: PreMessageEventArgs): Promise<PreMessageEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onMessage).map((x) => x.onMessage && x.onMessage(args)));
|
||||
}
|
||||
|
||||
public static async preLoginEvent(args: PreLoginEventArgs): Promise<PreLoginEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onLogin).map((x) => x.onLogin && x.onLogin(args)));
|
||||
}
|
||||
|
||||
public static async preGuildCreateEvent(args: PreGuildCreateEventArgs): Promise<PreGuildCreateEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onGuildCreate).map((x) => x.onGuildCreate && x.onGuildCreate(args)));
|
||||
}
|
||||
|
||||
public static async preChannelCreateEvent(args: PreChannelCreateEventArgs): Promise<PreChannelCreateEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onChannelCreate).map((x) => x.onChannelCreate && x.onChannelCreate(args)));
|
||||
}
|
||||
|
||||
public static async preTypingEvent(args: PreTypingEventArgs): Promise<PreTypingEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onTyping).map((x) => x.onTyping && x.onTyping(args)));
|
||||
}
|
||||
|
||||
public static async preStatusChangeEvent(args: PreStatusChangeEventArgs): Promise<PreStatusChangeEventResult[]> {
|
||||
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<void> {
|
||||
await Promise.all(PluginStore.plugins.filter((x) => x.onStatusChange).map((x) => x.onStatusChange && x.onStatusChange(args)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<any>): Promise<void> {
|
||||
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) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
id: string;
|
||||
name: string;
|
||||
authors: string[];
|
||||
repository: string;
|
||||
license: string;
|
||||
version: string; // semver
|
||||
versionCode: number; // integer
|
||||
mainClass: string;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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>
|
||||
channel: Partial<Channel>;
|
||||
}
|
||||
|
||||
export interface OnChannelCreateEventArgs {
|
||||
channel: Channel,
|
||||
guild: Guild,
|
||||
user: User
|
||||
channel: Channel;
|
||||
guild: Guild;
|
||||
user: User;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
guild: Partial<Guild>;
|
||||
}
|
||||
|
||||
export interface OnGuildCreateEventArgs {
|
||||
user: User,
|
||||
guild: Guild
|
||||
user: User;
|
||||
guild: Guild;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
message: Partial<Message>;
|
||||
}
|
||||
|
||||
export interface OnMessageEventArgs {
|
||||
user: User,
|
||||
message: Message
|
||||
user: User;
|
||||
message: Message;
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
export interface PluginLoadedEventArgs {
|
||||
|
||||
}
|
||||
export interface PluginLoadedEventArgs {}
|
||||
|
||||
@@ -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>
|
||||
user: Partial<User>;
|
||||
}
|
||||
|
||||
export interface OnRegisterEventArgs {
|
||||
age: any,
|
||||
user: User,
|
||||
ip: String
|
||||
age: any;
|
||||
user: User;
|
||||
ip: String;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
presence: Partial<Presence>;
|
||||
}
|
||||
|
||||
export interface OnStatusChangeEventArgs {
|
||||
user: User,
|
||||
presence: Presence
|
||||
user: User;
|
||||
presence: Presence;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ do
|
||||
echo " async onPre${event}?(args: Pre${event}EventArgs): Promise<Pre${event}EventResult>;"
|
||||
) >> ../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
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface EventResult {
|
||||
cancel?: boolean;
|
||||
blockReason?: string;
|
||||
}
|
||||
cancel?: boolean;
|
||||
blockReason?: string;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(" "));
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user