Use actions/events for plugin interoperability. Move base case and mute functionality to their own plugins.

This commit is contained in:
Dragory 2018-11-25 17:04:26 +02:00
parent 22c515be38
commit 2e30a3b9e7
14 changed files with 674 additions and 332 deletions

24
src/data/GuildActions.ts Normal file
View file

@ -0,0 +1,24 @@
import { BaseRepository } from "./BaseRepository";
type ActionFn = (...args: any[]) => any | Promise<any>;
export class GuildActions extends BaseRepository {
private actions: Map<string, ActionFn>;
constructor(guildId) {
super(guildId);
this.actions = new Map();
}
public register(actionName: string, actionFn: ActionFn) {
this.actions.set(actionName, actionFn);
}
public unregister(actionName: string) {
this.actions.delete(actionName);
}
public fire(actionName: string, ...args: any[]): Promise<any> {
return this.actions.has(actionName) ? this.actions.get(actionName)(...args) : null;
}
}