feat: approve button
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"tg-mc/conf"
|
||||
"tg-mc/defs"
|
||||
"tg-mc/models"
|
||||
su "tg-mc/services/utils"
|
||||
"tg-mc/utils"
|
||||
@@ -34,16 +35,26 @@ func GetLeftPlayer(m chat.Message) (userName string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func HandleJoinGame(userName string, mention bool) {
|
||||
func HandleJoinGame(userName string, mention bool, expireMode bool) {
|
||||
|
||||
u, err := models.GetUserByMCName(userName)
|
||||
if err != nil {
|
||||
logrus.Error("get user name error: ", err)
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
switch u.Status {
|
||||
case StatusNormal:
|
||||
if !GetAuthcator().IsAuthed(u, expireMode) {
|
||||
m := tgbotapi.NewMessage(u.TGID, fmt.Sprintf("MC用户:%v 尝试登录,请手动允许,每次授权持续30秒", userName))
|
||||
m.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(
|
||||
tgbotapi.NewInlineKeyboardRow(
|
||||
tgbotapi.NewInlineKeyboardButtonData("批准", defs.NewApproveCommand(u.MCName).ToJSON()),
|
||||
tgbotapi.NewInlineKeyboardButtonData("拒绝", defs.NewRejectCommand(u.MCName).ToJSON())),
|
||||
)
|
||||
conf.Bot.Send(m)
|
||||
kickPlayer(userName)
|
||||
return
|
||||
}
|
||||
if mention {
|
||||
SendMsgToPlayer("欢迎回来!", userName)
|
||||
}
|
||||
@@ -93,14 +104,19 @@ func CronKick() {
|
||||
utils.CronStart(func() {
|
||||
users := su.GetAlivePlayerList()
|
||||
for _, u := range users {
|
||||
HandleJoinGame(u, false)
|
||||
HandleJoinGame(u, false, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func isBotMsg(msg chat.Message) bool {
|
||||
if msg.Translate == "commands.message.display.outgoing" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return msg.Translate == "commands.message.display.outgoing"
|
||||
}
|
||||
|
||||
func HandleLeftGame(userName string) {
|
||||
u, err := models.GetUserByMCName(userName)
|
||||
if err != nil {
|
||||
logrus.Error("get user name error: ", err)
|
||||
}
|
||||
GetAuthcator().Reject(u)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user