mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 19:22:09 +00:00
grammY-based bot with a module plugin system loaded from the MODULES env var. Three command visibility levels (public/protected/private) share a unified command namespace with conflict detection at registry build. - 4 initial modules (util, wordle, loldle, misc); util fully implemented, others are stubs proving the plugin system end-to-end - util: /info (chat/thread/sender ids) + /help (pure renderer over the registry, HTML parse mode, escapes user-influenced strings) - KVStore interface with CFKVStore and a per-module prefixing factory; getJSON/putJSON convenience helpers; other backends drop in via one file - Webhook at POST /webhook with secret-token validation via grammY's webhookCallback; no admin HTTP surface - Post-deploy register script (npm run deploy = wrangler deploy && node --env-file=.env.deploy scripts/register.js) for setWebhook and setMyCommands; --dry-run flag for preview - 56 vitest unit tests across 7 suites covering registry, db wrapper, dispatcher, help renderer, validators, and HTML escaper - biome for lint + format; phased implementation plan under plans/
30 lines
941 B
JavaScript
30 lines
941 B
JavaScript
/**
|
|
* @file fake-modules — fixture modules + a helper that builds an import-map
|
|
* shape compatible with `loadModules(env, importMap)`.
|
|
*
|
|
* Using dependency injection (instead of `vi.mock`) sidesteps path-resolution
|
|
* flakiness on Windows and keeps tests fully deterministic.
|
|
*/
|
|
|
|
/**
|
|
* @param {Record<string, import("../../src/modules/registry.js").BotModule>} modules
|
|
*/
|
|
export function makeFakeImportMap(modules) {
|
|
/** @type {Record<string, () => Promise<{default: any}>>} */
|
|
const map = {};
|
|
for (const [name, mod] of Object.entries(modules)) {
|
|
map[name] = async () => ({ default: mod });
|
|
}
|
|
return map;
|
|
}
|
|
|
|
export const noopHandler = async () => {};
|
|
|
|
export function makeCommand(name, visibility, description = "fixture command") {
|
|
return { name, visibility, description, handler: noopHandler };
|
|
}
|
|
|
|
export function makeModule(name, commands, init) {
|
|
return init ? { name, commands, init } : { name, commands };
|
|
}
|