Add metrics
This commit is contained in:
9
main.go
9
main.go
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user