Harden Telegram bot cleanup commands

This commit is contained in:
ShukeBta
2026-06-16 18:52:04 +08:00
parent 829b88036a
commit 6e7854e8f6
7 changed files with 252 additions and 30 deletions
+18
View File
@@ -449,4 +449,22 @@ func TestTelegramCommandFiltering(t *testing.T) {
t.Fatalf("%s should be supported so group slash commands get feedback", cmd)
}
}
for _, cmd := range []string{"/restart", "/update_bot", "/coins", "/red", "/white_channel", "/config"} {
if telegramSupportedCommand(cmd) {
t.Fatalf("%s should not be treated as supported until it has a real Mgo implementation", cmd)
}
}
}
func TestTelegramSupportedCommandSetMatchesRegistry(t *testing.T) {
_, bot := newBotTestService(t)
channel := &model.NotifyChannel{Name: "Telegram", Type: "telegram", Enabled: true, Config: `{"admin_user_ids":"9001"}`}
msg := &TelegramMessage{From: TelegramUser{ID: 9001, Username: "admin"}, Chat: TelegramChat{ID: 9001, Type: "private"}}
for _, def := range bot.telegramCommandDefinitions(t.Context(), channel, msg) {
for _, alias := range def.Aliases {
if !telegramSupportedCommand(alias) {
t.Fatalf("registered command %s must be in telegramSupportedCommandSet", alias)
}
}
}
}