Add metrics

This commit is contained in:
2025-05-29 00:52:44 +02:00
parent 3ab37d88f4
commit af1080fb6a
4 changed files with 433 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"syscall"
"nignoggobot/commands"
"nignoggobot/metrics"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
@ -66,10 +67,18 @@ func main() {
continue
}
log.Printf("Received command: %s from chat %d (user %d)", update.Message.Command(), update.Message.Chat.ID, update.Message.From.ID)
cmdName := update.Message.Command()
isGroup := update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup()
metrics.UpdateChat(update.Message.Chat.ID, isGroup)
if cmd, ok := commands.All()[cmdName]; ok {
log.Printf("Executing command: %s", cmdName)
// Bottleneck here locking mutexes and writing to json every time but oh well
metrics.IncrementCommandUsage(cmdName)
cmd.Execute(update, bot)
} else {
log.Printf("Unknown command: %s", cmdName)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Unknown command.")
bot.Send(msg)
}