feat: support ban and kick
This commit is contained in:
@@ -28,9 +28,9 @@ func GetAuthcator() Auth {
|
||||
}
|
||||
|
||||
func (a *Authcator) IsAuthed(u models.User, expireMode bool) bool {
|
||||
if u.MCName != "VaalaCat" {
|
||||
return true
|
||||
}
|
||||
// if u.MCName != "VaalaCat" {
|
||||
// return true
|
||||
// }
|
||||
if approveTime, ok := a.UserMap.Load(u.MCName); ok {
|
||||
if !expireMode {
|
||||
return true
|
||||
|
@@ -52,7 +52,7 @@ func HandleJoinGame(userName string, mention bool, expireMode bool) {
|
||||
tgbotapi.NewInlineKeyboardButtonData("拒绝", defs.NewRejectCommand(u.MCName).ToJSON())),
|
||||
)
|
||||
conf.Bot.Send(m)
|
||||
kickPlayer(userName)
|
||||
KickPlayer(userName)
|
||||
return
|
||||
}
|
||||
if mention {
|
||||
@@ -61,7 +61,7 @@ func HandleJoinGame(userName string, mention bool, expireMode bool) {
|
||||
case StatusPending:
|
||||
SendMsgToPlayer("你还没有绑定 Telegram 哦, 5秒后你将会被踢出。请在群组中发送 /bind <你的 MC 用户名> 进行绑定。", userName)
|
||||
time.Sleep(5 * time.Second)
|
||||
kickPlayer(userName)
|
||||
KickPlayer(userName)
|
||||
m := tgbotapi.NewMessage(conf.GetBotSettings().GroupID, fmt.Sprintf("用户:%v 没有绑定,尝试登录已被T出", userName))
|
||||
conf.Bot.Send(m)
|
||||
case StatusBanned:
|
||||
@@ -71,13 +71,13 @@ func HandleJoinGame(userName string, mention bool, expireMode bool) {
|
||||
default:
|
||||
SendMsgToPlayer("未知错误,请联系管理员,你将被踢出", userName)
|
||||
time.Sleep(3 * time.Second)
|
||||
kickPlayer(userName)
|
||||
KickPlayer(userName)
|
||||
m := tgbotapi.NewMessage(conf.GetBotSettings().GroupID, fmt.Sprintf("用户:%v 登录失败,错误未知,已被T出", userName))
|
||||
conf.Bot.Send(m)
|
||||
}
|
||||
}
|
||||
|
||||
func sendCommand(cmd string) error {
|
||||
func SendCommand(cmd string) error {
|
||||
var salt int64
|
||||
if err := binary.Read(rand.Reader, binary.BigEndian, &salt); err != nil {
|
||||
return err
|
||||
@@ -95,8 +95,8 @@ func sendCommand(cmd string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func kickPlayer(userName string) error {
|
||||
err := sendCommand("kick " + userName)
|
||||
func KickPlayer(userName string) error {
|
||||
err := SendCommand("kick " + userName)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,7 @@ func SendMsg(msg string) {
|
||||
|
||||
func SendMsgToPlayer(msg string, playerName string) {
|
||||
go func() {
|
||||
err := sendCommand(fmt.Sprintf("tell %s %s", playerName, msg))
|
||||
err := SendCommand(fmt.Sprintf("tell %s %s", playerName, msg))
|
||||
if err != nil {
|
||||
logrus.Error("send msg to player error: ", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user