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 (
"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 {
@ -22,31 +18,16 @@ func (d DebugCommand) Help() string {
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)
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
}
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" {
if update.Message.CommandArguments() == "panic" {
panic("test panic")
}
}

View File

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

View File

@ -2,7 +2,6 @@ package commands
import (
"log"
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) {
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)
if err != nil {
log.Println("Failed to send info message:", err)