feat: support ban and kick
This commit is contained in:
@@ -2,23 +2,31 @@ package tgbot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"tg-mc/conf"
|
||||
"tg-mc/models"
|
||||
"tg-mc/services/utils"
|
||||
commonUtils "tg-mc/utils"
|
||||
"time"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func SetHandler(m *tgbotapi.Message, i interface{}) {
|
||||
var a []string
|
||||
if t, ok := i.([]string); ok {
|
||||
a = t
|
||||
} else {
|
||||
a = commonUtils.GetArgs(m.CommandArguments())
|
||||
}
|
||||
|
||||
if !utils.IsAdmin(m) {
|
||||
tm := tgbotapi.NewMessage(m.Chat.ID, "您不是管理员,没有该权限")
|
||||
conf.Bot.Send(tm)
|
||||
return
|
||||
}
|
||||
a := commonUtils.GetArgs(m.CommandArguments())
|
||||
if len(a) != 3 {
|
||||
tm := tgbotapi.NewMessage(m.Chat.ID, "参数错误,样例:\n```\n/set username tgid status\n```")
|
||||
tm.ParseMode = "Markdown"
|
||||
@@ -46,5 +54,18 @@ func SetHandler(m *tgbotapi.Message, i interface{}) {
|
||||
return
|
||||
}
|
||||
conf.Bot.Send(tgbotapi.NewMessage(m.Chat.ID, "设置用户成功"))
|
||||
return
|
||||
}
|
||||
|
||||
func BanHandler(m *tgbotapi.Message, i interface{}) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
randomNumber := rand.Intn(11)
|
||||
for {
|
||||
_, err := models.GetUserByTGID(int64(randomNumber))
|
||||
if err != nil {
|
||||
break
|
||||
} else {
|
||||
randomNumber = rand.Intn(11)
|
||||
}
|
||||
}
|
||||
SetHandler(m, []string{m.CommandArguments(), fmt.Sprintf("-%d", randomNumber), "2"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user