40 lines
996 B
TypeScript
40 lines
996 B
TypeScript
|
|
import { Client } from 'discord.js';
|
||
|
|
import express from 'express';
|
||
|
|
|
||
|
|
export interface Plugin {
|
||
|
|
name: string;
|
||
|
|
version: string;
|
||
|
|
description: string;
|
||
|
|
|
||
|
|
/** Called once when plugin is loaded */
|
||
|
|
init(ctx: PluginContext): Promise<void>;
|
||
|
|
|
||
|
|
/** Called when Discord client is ready */
|
||
|
|
onReady?(ctx: PluginContext): Promise<void>;
|
||
|
|
|
||
|
|
/** Called to register Express routes */
|
||
|
|
registerRoutes?(app: express.Application, ctx: PluginContext): void;
|
||
|
|
|
||
|
|
/** Called to build SSE snapshot data for new clients */
|
||
|
|
getSnapshot?(ctx: PluginContext): Record<string, any>;
|
||
|
|
|
||
|
|
/** Called on graceful shutdown */
|
||
|
|
destroy?(ctx: PluginContext): Promise<void>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface PluginContext {
|
||
|
|
client: Client;
|
||
|
|
dataDir: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
const loadedPlugins: Plugin[] = [];
|
||
|
|
|
||
|
|
export function registerPlugin(plugin: Plugin): void {
|
||
|
|
loadedPlugins.push(plugin);
|
||
|
|
console.log(`[Plugin] Registered: ${plugin.name} v${plugin.version}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getPlugins(): Plugin[] {
|
||
|
|
return [...loadedPlugins];
|
||
|
|
}
|