fix: unbind
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
vaalacat 2024-04-28 03:52:02 +00:00
parent e39db56969
commit 80cae65b98
2 changed files with 32 additions and 14 deletions

View File

@ -58,8 +58,10 @@ steps:
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24 image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true privileged: true
environment: environment:
HTTP_PROXY: http://10.10.0.17:7890 HTTP_PROXY:
HTTPS_PROXY: http://10.10.0.17:7890 from_secret: HTTP_PROXY
HTTPS_PROXY:
from_secret: HTTP_PROXY
settings: settings:
mirror: https://docker.lab.vaala.tech mirror: https://docker.lab.vaala.tech
debug: true debug: true
@ -88,8 +90,10 @@ steps:
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24 image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true privileged: true
environment: environment:
HTTP_PROXY: http://10.10.0.17:7890 HTTP_PROXY:
HTTPS_PROXY: http://10.10.0.17:7890 from_secret: HTTP_PROXY
HTTPS_PROXY:
from_secret: HTTP_PROXY
settings: settings:
mirror: https://docker.lab.vaala.tech mirror: https://docker.lab.vaala.tech
debug: true debug: true

View File

@ -5,24 +5,38 @@ import (
"tg-mc/models" "tg-mc/models"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/samber/lo"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func UnbindHandler(msg *tgbotapi.Message, i interface{}) { func UnbindHandler(msg *tgbotapi.Message, i interface{}) {
logrus.Infof("id is %d", msg.Chat.ID) logrus.Infof("id is %d", msg.Chat.ID)
u, err := models.GetUserByTGID(msg.From.ID) if len(msg.CommandArguments()) == 0 {
m := tgbotapi.NewMessage(msg.Chat.ID, "请输入正确的参数")
conf.Bot.Send(m)
return
}
us, err := models.GetUsersByTGID(msg.From.ID)
if err != nil { if err != nil {
m := tgbotapi.NewMessage(msg.Chat.ID, "你还没有绑定") m := tgbotapi.NewMessage(msg.Chat.ID, "你还没有绑定")
conf.Bot.Send(m) conf.Bot.Send(m)
return return
} }
lo.Map(us, func(u models.User, _ int) bool {
if u.MCName == msg.CommandArguments() {
u.Status = 0
err = u.Delete(msg.From.ID) err = u.Delete(msg.From.ID)
if err != nil { if err != nil {
m := tgbotapi.NewMessage(msg.Chat.ID, "解绑失败") m := tgbotapi.NewMessage(msg.Chat.ID, "解绑失败")
conf.Bot.Send(m) conf.Bot.Send(m)
return return false
} }
m := tgbotapi.NewMessage(msg.Chat.ID, "解绑成功") m := tgbotapi.NewMessage(msg.Chat.ID, "解绑成功")
conf.Bot.Send(m) conf.Bot.Send(m)
return return false
}
return true
})
} }