summary refs log tree commit diff
path: root/src/util/plugin/Plugin.ts
blob: 1c86a0067b408648adaf0f693c816d7c6d87d132 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import EventEmitter from "events";
import { TypedEventEmitter } from "@fosscord/util";

type PluginEvents = {
	error: (error: Error | unknown) => void;
	loaded: () => void;
};

//this doesnt work, check later:
 //(EventEmitter as new () => TypedEventEmitter<PluginEvents>) {
export class Plugin extends EventEmitter {
	private _untypedOn = this.on
	private _untypedEmit = this.emit
	public on = <K extends keyof PluginEvents>(event: K, listener: PluginEvents[K]): this => this._untypedOn(event, listener)
	public emit = <K extends keyof PluginEvents>(event: K, ...args: Parameters<PluginEvents[K]>): boolean => this._untypedEmit(event, ...args)

	async init() {
		// insert default config into database?
	}
}