2023-08-28 15:57:58 +08:00

72 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tgbot
import (
"fmt"
"strconv"
"tg-mc/conf"
"tg-mc/models"
"tg-mc/services/utils"
commonUtils "tg-mc/utils"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/sirupsen/logrus"
)
func GetHandler(msg *tgbotapi.Message, i interface{}) {
if !utils.IsAdmin(msg) &&
len(msg.CommandArguments()) != 0 {
tm := tgbotapi.NewMessage(msg.Chat.ID, "您不是管理员,没有该权限")
conf.Bot.Send(tm)
return
} else if utils.IsAdmin(msg) &&
len(msg.CommandArguments()) != 0 {
a := commonUtils.GetArgs(msg.CommandArguments())
if len(a) != 2 {
tm := tgbotapi.NewMessage(msg.Chat.ID, "参数错误,样例:\n```\n/get <tgid|username> <value>\n```")
tm.ParseMode = "Markdown"
conf.Bot.Send(tm)
return
}
if a[0] == "tgid" {
tgid, err := strconv.ParseInt(a[1], 10, 64)
if err != nil {
conf.Bot.Send(tgbotapi.NewMessage(msg.Chat.ID, "ID错误应该为int64"))
return
}
u, err := models.GetUserByTGID(tgid)
if err != nil {
tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("查询出错err\n```\n%+v\n```", err))
tm.ParseMode = "Markdown"
conf.Bot.Send(tm)
return
}
tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("用户信息:\n```\n%+v\n```", u))
tm.ParseMode = "Markdown"
conf.Bot.Send(tm)
}
if a[0] == "username" {
u, err := models.GetUserByMCName(a[1])
if err != nil {
tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("查询出错err\n```\n%+v\n```", err))
tm.ParseMode = "Markdown"
conf.Bot.Send(tm)
return
}
tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("用户信息:\n```\n%+v\n```", u))
tm.ParseMode = "Markdown"
conf.Bot.Send(tm)
}
return
}
logrus.Infof("id is %d", msg.Chat.ID)
u, err := models.GetUserByTGID(msg.From.ID)
if err != nil {
m := tgbotapi.NewMessage(msg.Chat.ID, "你还没有绑定")
conf.Bot.Send(m)
return
}
m := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("你的MCID是%v", u.MCName))
conf.Bot.Send(m)
return
}