From 7d936efb2f37db42c3e57ee9a915ed4d5ab8e25f Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 27 Aug 2022 05:18:48 +0200 Subject: Cleanup, reformat, fix some todos, git hook fixup! Cleanup, reformat, fix some todos, git hook --- src/util/plugin/Plugin.ts | 210 +++++++++++---------- src/util/plugin/PluginConfig.ts | 35 ++-- src/util/plugin/PluginEventHandler.ts | 161 +++++++++------- src/util/plugin/PluginLoader.ts | 30 ++- src/util/plugin/PluginManifest.ts | 18 +- src/util/plugin/PluginStore.ts | 7 +- .../plugin/event_types/ChannelCreateEventArgs.ts | 14 +- .../plugin/event_types/GuildCreateEventArgs.ts | 10 +- src/util/plugin/event_types/LoginEventArgs.ts | 12 +- src/util/plugin/event_types/MessageEventArgs.ts | 10 +- .../plugin/event_types/PluginLoadedEventArgs.ts | 4 +- src/util/plugin/event_types/RegisterEventArgs.ts | 14 +- .../plugin/event_types/StatusChangeEventArgs.ts | 10 +- src/util/plugin/event_types/TypingEventArgs.ts | 16 +- src/util/plugin/event_types/_gen.sh | 4 +- src/util/plugin/event_types/base/EventResult.ts | 6 +- src/util/plugin/event_types/index.ts | 2 +- src/util/plugin/index.ts | 2 +- 18 files changed, 298 insertions(+), 267 deletions(-) (limited to 'src/util/plugin') diff --git a/src/util/plugin/Plugin.ts b/src/util/plugin/Plugin.ts index 6a6f03f4..9bccba9d 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 883bca7c..b9c8aef0 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 d5fc67f4..3ed1efa6 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 4dc0129a..9f37ed87 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 79ecc465..518202ec 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 60d7f7b7..8b02f157 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 87fa3691..eb103346 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 7724b4f3..0df9beb1 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 8f80b69f..4f10e451 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 ab276429..01df9b75 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 58829f15..a585675b 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 d36d7e64..f3e0fdd4 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 c1a67112..b412cffa 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 3ac59b41..694ef83b 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 9f761d1e..f8769301 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 f18837cd..7acaa775 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 4a585dc0..773e8dc9 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 7a297981..ffc7803e 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"; -- cgit 1.5.1