MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / GreetingPlugin

Class GreetingPlugin

goodnight/goodnight.ts:26–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26class GreetingPlugin extends Plugin {
27 // 动态生成描述,包含帮助信息
28 description = () => {
29 const help = `🌙 <b>早晚安统计插件</b>\n\n` +
30 `自动回复早晚安并统计排名。默认关闭,需手动开启。\n\n` +
31 `<b>指令:</b>\n` +
32 `• <code>${mainPrefix}goodnight on/off</code> - 开启或关闭统计\n` +
33 `• <code>${mainPrefix}goodnight utc+8</code> - 设置时区 (支持 utc+8, utc-5 格式)\n` +
34 `• <code>${mainPrefix}goodnight</code> - 查看状态`;
35 return help;
36 };
37
38 // 数据库实例
39 private db: any;
40
41 // 关键词配置
42 private readonly sleepKeywords = ["晚安", "晚", "睡觉", "睡了", "去睡了", "晚安喵"];
43 private readonly wakeKeywords = ["早", "早上好", "早安", "起床", "早安喵"];
44
45 constructor() {
46 super();
47 }
48
49 cleanup(): void {
50 // 引用重置:清空实例级 db / cache / manager 引用,便于 reload 后重新初始化。
51 this.db = null;
52 }
53
54 async setup(): Promise<void> {
55 await this.initDB();
56 }
57
58 // 初始化数据库
59 private async initDB() {
60 // 规范路径 assets/goodnight/data.json(历史 greeting/ 自动迁移)
61 const dbPath = resolvePluginAssetFile({
62 plugin: "goodnight",
63 fileName: "data.json",
64 legacyDirs: ["greeting"],
65 legacyFiles: [{ dir: "greeting", fileName: "data.json" }],
66 });
67
68 // 设置默认值
69 this.db = await JSONFilePreset<DBData>(dbPath, { groups: {} });
70 }
71
72 // 指令处理器
73 cmdHandlers = {
74 goodnight: async (msg: Api.Message) => {
75 await this.handleCommand(msg);
76 },
77 // 添加 gn 作为 .goodnight 的简写别名
78 gn: async (msg: Api.Message) => {
79 await this.handleCommand(msg);
80 }
81 };
82
83 // 统一处理指令逻辑

Callers

nothing calls this directly

Calls 4

handleCommandMethod · 0.95
initDBMethod · 0.95
checkKeywordsMethod · 0.95
processGreetingMethod · 0.95

Tested by

no test coverage detected