diff --git a/commands/debug.go b/commands/debug.go index 96c58dc..fc0cd57 100644 --- a/commands/debug.go +++ b/commands/debug.go @@ -2,10 +2,14 @@ package commands import ( "fmt" + "runtime" + "time" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) +var startTime = time.Now() + type DebugCommand struct{} func (d DebugCommand) Name() string { @@ -18,16 +22,31 @@ func (d DebugCommand) Help() string { func (d DebugCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) { user := update.Message.From - if user == nil || !IsAdmin(user.ID) { - msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You are not authorized to use this command.") - bot.Send(msg) - return + isAdmin := user != nil && IsAdmin(user.ID) + var info string + if isAdmin { + var m runtime.MemStats + runtime.ReadMemStats(&m) + uptime := time.Since(startTime) + info = fmt.Sprintf( + "[ADMIN DEBUG]\nUserID: %d\nChatID: %d\nText: %s\nGo version: %s\nUptime: %s\nGoroutines: %d\nMemory: %.2f MB\nOS/Arch: %s/%s\n", + user.ID, + update.Message.Chat.ID, + update.Message.Text, + runtime.Version(), + uptime.Truncate(time.Second), + runtime.NumGoroutine(), + float64(m.Alloc)/1024/1024, + runtime.GOOS, + runtime.GOARCH, + ) + } else { + info = fmt.Sprintf("UserID: %d\nChatID: %d\nText: %s", user.ID, update.Message.Chat.ID, update.Message.Text) } - info := fmt.Sprintf("UserID: %d\nChatID: %d\nText: %s", user.ID, update.Message.Chat.ID, update.Message.Text) msg := tgbotapi.NewMessage(update.Message.Chat.ID, info) bot.Send(msg) - if update.Message.CommandArguments() == "panic" { + if isAdmin && update.Message.CommandArguments() == "panic" { panic("test panic") } } diff --git a/commands/help.go b/commands/help.go index 03003e2..b3dca94 100644 --- a/commands/help.go +++ b/commands/help.go @@ -2,6 +2,7 @@ package commands import ( "strings" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) diff --git a/commands/info.go b/commands/info.go index 65ea030..973769c 100644 --- a/commands/info.go +++ b/commands/info.go @@ -2,6 +2,7 @@ package commands import ( "log" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) @@ -16,7 +17,7 @@ func (i InfoCommand) Help() string { } func (i InfoCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) { - msg := tgbotapi.NewMessage(update.Message.Chat.ID, "This bot does XYZ.") + msg := tgbotapi.NewMessage(update.Message.Chat.ID, "This bot does dumb stuff and chemistry. Now version 2.0, rewritten in Go.") _, err := bot.Send(msg) if err != nil { log.Println("Failed to send info message:", err)