feat: support kick
This commit is contained in:
@@ -6,13 +6,14 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"tg-mc/conf"
|
||||
"tg-mc/models"
|
||||
"tg-mc/services/utils"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Run(sendFunc func(string) error) {
|
||||
func Run(sendFunc func(string)) {
|
||||
var err error
|
||||
|
||||
HttpProxy := conf.GetBotSettings().HTTPProxy
|
||||
@@ -42,18 +43,52 @@ func Run(sendFunc func(string) error) {
|
||||
|
||||
for update := range updates {
|
||||
if update.Message != nil {
|
||||
logrus.Infof("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
if update.Message.Command() == "talk" {
|
||||
logrus.Infof("id is %d", update.Message.Chat.ID)
|
||||
m := fmt.Sprintf("%v: %v", update.Message.From.UserName, update.Message.CommandArguments())
|
||||
err := sendFunc(m)
|
||||
logrus.WithError(err).Error("send message error")
|
||||
}
|
||||
if update.Message.Command() == "list" {
|
||||
logrus.Infof("id is %d", update.Message.Chat.ID)
|
||||
m := tgbotapi.NewMessage(update.Message.Chat.ID, utils.GetAlivePlayer())
|
||||
conf.Bot.Send(m)
|
||||
}
|
||||
go func(m *tgbotapi.Message) {
|
||||
logrus.Infof("[%s] %s", m.From.UserName, m.Text)
|
||||
if m.Command() == "talk" {
|
||||
logrus.Infof("id is %d", m.Chat.ID)
|
||||
m := fmt.Sprintf("%v: %v", m.From.UserName, m.CommandArguments())
|
||||
sendFunc(m)
|
||||
logrus.WithError(err).Error("send message error")
|
||||
return
|
||||
}
|
||||
if m.Command() == "list" {
|
||||
logrus.Infof("id is %d", m.Chat.ID)
|
||||
m := tgbotapi.NewMessage(m.Chat.ID, utils.GetAlivePlayer())
|
||||
conf.Bot.Send(m)
|
||||
return
|
||||
}
|
||||
if m.Command() == "bind" {
|
||||
logrus.Infof("id is %d", m.Chat.ID)
|
||||
models.CreateUserIfNotExist(m.From.ID, &models.User{
|
||||
TGID: m.From.ID,
|
||||
MCName: m.CommandArguments(),
|
||||
Status: 1,
|
||||
})
|
||||
m := tgbotapi.NewMessage(m.Chat.ID,
|
||||
fmt.Sprintf("绑定成功,你的MCID是%v", m.CommandArguments()))
|
||||
conf.Bot.Send(m)
|
||||
return
|
||||
}
|
||||
if m.Command() == "unbind" {
|
||||
logrus.Infof("id is %d", m.Chat.ID)
|
||||
u, err := models.GetUserByTGID(m.From.ID)
|
||||
if err != nil {
|
||||
m := tgbotapi.NewMessage(m.Chat.ID, "你还没有绑定")
|
||||
conf.Bot.Send(m)
|
||||
return
|
||||
}
|
||||
err = u.Delete(m.From.ID)
|
||||
if err != nil {
|
||||
m := tgbotapi.NewMessage(m.Chat.ID, "解绑失败")
|
||||
conf.Bot.Send(m)
|
||||
return
|
||||
}
|
||||
m := tgbotapi.NewMessage(m.Chat.ID, "解绑成功")
|
||||
conf.Bot.Send(m)
|
||||
return
|
||||
}
|
||||
}(update.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user