feat: approve button

This commit is contained in:
Vaala Cat
2023-08-28 15:57:58 +08:00
parent 46cf57764c
commit 5528766c13
15 changed files with 469 additions and 176 deletions

View File

@@ -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)
}