package tgbot import ( "fmt" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) type UserError struct { msg string cmd *Command } func NewUserError(cmd *Command, text string) error { ret := &UserError{ msg: text, cmd: cmd, } return ret } func (e *UserError) Error() string { return e.msg } func (e *UserError) SendBack() error { if e.cmd.CmdType == CommandTypeCallback { return e.cmd.SendEdit(e.msg, nil) } else if e.cmd.CmdType == CommandTypeCommand { return e.cmd.SendReply(e.msg, nil) } else { return e.cmd.SendText(e.msg) } } func CommandError(cmd *Command, err error) error { return fmt.Errorf("命令失败,来自【%s:%d】%s,命令【%s】错误:\n%s", cmd.message.Chat.Title, cmd.message.Chat.ID, UserDisplay(cmd.message), cmd.Cmd, err.Error()) } func CommandPanic(cmd *Command, err error) error { return fmt.Errorf("命令异常,来自【%s:%d】%s,命令【%s】错误:\n%s", cmd.message.Chat.Title, cmd.message.Chat.ID, UserDisplay(cmd.message), cmd.Cmd, err.Error()) } func AuthError(message *tgbotapi.Message) error { return fmt.Errorf("非官方群,来自【%s:%d】%s, 内容:\n%s", message.Chat.Title, message.Chat.ID, UserDisplay(message), message.Text) } func UnknownCommandError(message *tgbotapi.Message) error { return fmt.Errorf("未知命令,来自【%s:%d】%s, 内容:\n%s", message.Chat.Title, message.Chat.ID, UserDisplay(message), message.Text) }