57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
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 {
|
|
return "debug"
|
|
}
|
|
|
|
func (d DebugCommand) Help() string {
|
|
return "Show debug info (admin only)"
|
|
}
|
|
|
|
func (d DebugCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|
user := update.Message.From
|
|
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)
|
|
}
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, info)
|
|
bot.Send(msg)
|
|
|
|
if isAdmin && update.Message.CommandArguments() == "panic" {
|
|
panic("test panic")
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
Register(DebugCommand{})
|
|
}
|