Compare commits

..

No commits in common. "master" and "metrics" have entirely different histories.

3 changed files with 7 additions and 28 deletions

View File

@ -2,14 +2,10 @@ package commands
import ( import (
"fmt" "fmt"
"runtime"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
) )
var startTime = time.Now()
type DebugCommand struct{} type DebugCommand struct{}
func (d DebugCommand) Name() string { func (d DebugCommand) Name() string {
@ -22,31 +18,16 @@ func (d DebugCommand) Help() string {
func (d DebugCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) { func (d DebugCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
user := update.Message.From user := update.Message.From
isAdmin := user != nil && IsAdmin(user.ID) if user == nil || !IsAdmin(user.ID) {
var info string msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You are not authorized to use this command.")
if isAdmin { bot.Send(msg)
var m runtime.MemStats return
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) msg := tgbotapi.NewMessage(update.Message.Chat.ID, info)
bot.Send(msg) bot.Send(msg)
if isAdmin && update.Message.CommandArguments() == "panic" { if update.Message.CommandArguments() == "panic" {
panic("test panic") panic("test panic")
} }
} }

View File

@ -2,7 +2,6 @@ package commands
import ( import (
"strings" "strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
) )

View File

@ -2,7 +2,6 @@ package commands
import ( import (
"log" "log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
) )
@ -17,7 +16,7 @@ func (i InfoCommand) Help() string {
} }
func (i InfoCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) { func (i InfoCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "This bot does dumb stuff and chemistry. Now version 2.0, rewritten in Go.") msg := tgbotapi.NewMessage(update.Message.Chat.ID, "This bot does XYZ.")
_, err := bot.Send(msg) _, err := bot.Send(msg)
if err != nil { if err != nil {
log.Println("Failed to send info message:", err) log.Println("Failed to send info message:", err)