From 8769c7625cafd14e6f304601cc99a195e833d38b Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 13 Aug 2022 17:16:23 +0200 Subject: Fix config table, add plugin events, implement onPreMessageEvent, add http error data field, migrations --- src/util/plugin/Plugin.ts | 155 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 139 insertions(+), 16 deletions(-) (limited to 'src/util/plugin/Plugin.ts') diff --git a/src/util/plugin/Plugin.ts b/src/util/plugin/Plugin.ts index 0fb1732f..6a6f03f4 100644 --- a/src/util/plugin/Plugin.ts +++ b/src/util/plugin/Plugin.ts @@ -1,13 +1,22 @@ import EventEmitter from "events"; -import { PluginLoadedEventArgs, TypedEventEmitter } from "@fosscord/util"; +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 '.'; -type PluginEvents = { + +/*type PluginEvents = { error: (error: Error | unknown) => void; loaded: () => void; -}; +};*/ //this doesnt work, check later: - //EventEmitter as new () => TypedEventEmitter +//EventEmitter as new () => TypedEventEmitter export class Plugin { /** * Path the plugin resides in. @@ -15,23 +24,137 @@ export class Plugin { * @type {string} * @memberof Plugin */ - pluginPath: string; - /** - * - * - * @memberof Plugin - */ - async initConfig() { - // insert default config into database? - console.log("did you forget to implement initConfig?"); - } + pluginPath?: string; + pluginManifest?: PluginManifest; /** * * * @param {PluginLoadedEventArgs} args Info about plugin environment * @memberof Plugin */ - onPluginLoaded?(args?: PluginLoadedEventArgs) { - + async onPluginLoaded?(args?: PluginLoadedEventArgs) { + } + + //generated + /** + * 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 + */ + async onPreRegister?(args: PreRegisterEventArgs): Promise; + /** + * 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 + */ + async onPreMessage?(args: PreMessageEventArgs): Promise; + /** + * 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 + */ + async onPreLogin?(args: PreLoginEventArgs): Promise; + /** + * 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 + */ + async onPreGuildCreate?(args: PreGuildCreateEventArgs): Promise; + /** + * 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 + */ + async onPreChannelCreate?(args: PreChannelCreateEventArgs): Promise; + /** + * 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 + */ + async onPreTyping?(args: PreTypingEventArgs): Promise; + /** + * 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 + */ + async onPreStatusChange?(args: PreStatusChangeEventArgs): Promise; + } -- cgit 1.5.1