(msg: Api.Message)
| 1041 | // 严格按照acron.ts模式进行参数解析 |
| 1042 | const lines = msg.text?.trim()?.split(/\r?\n/g) || []; |
| 1043 | const parts = lines?.[0]?.split(/\s+/) || []; |
| 1044 | const [, ...args] = parts; // 跳过命令本身 |
| 1045 | const sub = (args[0] || "").toLowerCase(); |
| 1046 | |
| 1047 | // Get chat ID |
| 1048 | let chatId: string; |
| 1049 | try { |
| 1050 | if (msg.chat?.id) { |
| 1051 | chatId = String(msg.chat.id); |
| 1052 | } else if (msg.peerId) { |
| 1053 | chatId = String(msg.peerId); |
| 1054 | } else if (msg.chatId) { |
| 1055 | chatId = String(msg.chatId); |
| 1056 | } else { |
| 1057 | throw new Error("无法获取聊天ID"); |
| 1058 | } |
| 1059 | } catch (error) { |
| 1060 | await msg.edit({ |
| 1061 | text: `❌ <b>获取聊天ID失败:</b> ${htmlEscape(String(error))}`, |
| 1062 | parseMode: "html" |
| 1063 | }); |
| 1064 | return; |
| 1065 | } |
| 1066 | |
| 1067 | // 无参数时显示错误提示,不自动显示帮助 |
| 1068 | if (!sub) { |
| 1069 | await msg.edit({ |
| 1070 | text: `❌ <b>请指定子命令</b>\n\n💡 使用 <code>${mainPrefix}lottery help</code> 查看完整帮助`, |
| 1071 | parseMode: "html" |
| 1072 | }); |
| 1073 | return; |
| 1074 | } |
| 1075 | |
| 1076 | // 明确请求帮助时才显示 |
| 1077 | if (sub === "help" || sub === "h") { |
| 1078 | await msg.edit({ |
| 1079 | text: help_text, |
| 1080 | parseMode: "html", |
| 1081 | linkPreview: false, |
| 1082 | }); |
| 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | if (sub === "init" || sub === "initialize") { |
| 1087 | await msg.edit({ |
| 1088 | text: "🔄 <b>正在初始化数据库...</b>", |
| 1089 | parseMode: "html" |
| 1090 | }); |
| 1091 | |
| 1092 | try { |
| 1093 | // Recreate lottery_winners table with correct schema |
| 1094 | db.exec(`DROP TABLE IF EXISTS lottery_winners;`); |
| 1095 | db.exec(` |
| 1096 | CREATE TABLE lottery_winners ( |
| 1097 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 1098 | lottery_id INTEGER NOT NULL, |
| 1099 | user_id TEXT NOT NULL, |
| 1100 | username TEXT, |
nothing calls this directly
no test coverage detected