Make debug slightly cooler
This commit is contained in:
parent
38a318f694
commit
279a94c754
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user