feat: upgrade mod
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
vaalacat 2024-04-23 11:30:28 +00:00
parent 75944abbc2
commit e39db56969
7 changed files with 34 additions and 12 deletions

View File

@ -57,8 +57,11 @@ steps:
- name: publish - amd64 - name: publish - amd64
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24 image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true privileged: true
environment:
HTTP_PROXY: http://10.10.0.17:7890
HTTPS_PROXY: http://10.10.0.17:7890
settings: settings:
mirror: https://dockerproxy.com mirror: https://docker.lab.vaala.tech
debug: true debug: true
platforms: platforms:
- linux/amd64 - linux/amd64
@ -84,8 +87,11 @@ steps:
- name: publish - arm64 - name: publish - arm64
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24 image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true privileged: true
environment:
HTTP_PROXY: http://10.10.0.17:7890
HTTPS_PROXY: http://10.10.0.17:7890
settings: settings:
mirror: https://dockerproxy.com mirror: https://docker.lab.vaala.tech
debug: true debug: true
platforms: platforms:
- linux/arm64 - linux/arm64

View File

@ -9,9 +9,9 @@ import (
type User struct { type User struct {
gorm.Model gorm.Model
TGID int64 `gorm:"unique"` TGID int64 `gorm:"column:tgid;NOT NULL;index"`
MCName string MCName string `gorm:"column:mc_name;NOT NULL;unique"`
Status int // 0: pending, 1: normal, 2: banned Status int `gorm:"column:status;NOT NULL"` // 0: pending, 1: normal, 2: banned
} }
func init() { func init() {
@ -24,6 +24,13 @@ func (u *User) TableName() string {
return "users" return "users"
} }
func GetUsersByTGID(tgID int64) (users []User, err error) {
err = database.GetDB().Where(
&User{TGID: tgID},
).Find(&users).Error
return
}
func GetUserByTGID(tgID int64) (user User, err error) { func GetUserByTGID(tgID int64) (user User, err error) {
err = database.GetDB().Where( err = database.GetDB().Where(
&User{TGID: tgID}, &User{TGID: tgID},

View File

@ -21,7 +21,7 @@ import (
func StartBridgeClient() { func StartBridgeClient() {
for { for {
if err := Run(); err != nil { if err := Run(); err != nil {
utils.SendMsg("致命错误:" + err.Error()) utils.SendMsgToGroup("致命错误:" + err.Error())
} }
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }

View File

@ -12,7 +12,7 @@ import (
) )
func ApproveHandler(update tgbotapi.Update, cmd defs.Command) { func ApproveHandler(update tgbotapi.Update, cmd defs.Command) {
u, err := models.GetUserByTGID(update.CallbackQuery.From.ID) u, err := models.GetUserByMCName(cmd.Argstr)
if err != nil { if err != nil {
return return
} }

View File

@ -3,12 +3,14 @@ package tgbot
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"strings"
"tg-mc/conf" "tg-mc/conf"
"tg-mc/models" "tg-mc/models"
"tg-mc/services/utils" "tg-mc/services/utils"
commonUtils "tg-mc/utils" commonUtils "tg-mc/utils"
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"
) )
@ -33,7 +35,7 @@ func GetHandler(msg *tgbotapi.Message, i interface{}) {
conf.Bot.Send(tgbotapi.NewMessage(msg.Chat.ID, "ID错误应该为int64")) conf.Bot.Send(tgbotapi.NewMessage(msg.Chat.ID, "ID错误应该为int64"))
return return
} }
u, err := models.GetUserByTGID(tgid) u, err := models.GetUsersByTGID(tgid)
if err != nil { if err != nil {
tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("查询出错err\n```\n%+v\n```", err)) tm := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("查询出错err\n```\n%+v\n```", err))
tm.ParseMode = "Markdown" tm.ParseMode = "Markdown"
@ -59,13 +61,14 @@ func GetHandler(msg *tgbotapi.Message, i interface{}) {
return return
} }
logrus.Infof("id is %d", msg.Chat.ID) logrus.Infof("id is %d", msg.Chat.ID)
u, err := models.GetUserByTGID(msg.From.ID) u, 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
} }
m := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("你的MCID是%v", u.MCName)) ans := strings.Join(lo.Map(u, func(u models.User, _ int) string { return u.MCName }), "\n")
m := tgbotapi.NewMessage(msg.Chat.ID, fmt.Sprintf("你的MCID绑定有\n%v", ans))
conf.Bot.Send(m) conf.Bot.Send(m)
return return
} }

View File

@ -12,7 +12,7 @@ import (
) )
func RejectHandler(update tgbotapi.Update, cmd defs.Command) { func RejectHandler(update tgbotapi.Update, cmd defs.Command) {
u, err := models.GetUserByTGID(update.CallbackQuery.From.ID) u, err := models.GetUserByMCName(cmd.Argstr)
if err != nil { if err != nil {
return return
} }

View File

@ -7,12 +7,18 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
) )
func SendMsg(msg string) error { func SendMsgToGroup(msg string) error {
msgT := tgbotapi.NewMessage(conf.GetBotSettings().GroupID, msg) msgT := tgbotapi.NewMessage(conf.GetBotSettings().GroupID, msg)
_, err := conf.Bot.Send(msgT) _, err := conf.Bot.Send(msgT)
return err return err
} }
func SendMsg(chatID int64, msg string) error {
msgT := tgbotapi.NewMessage(chatID, msg)
_, err := conf.Bot.Send(msgT)
return err
}
func IsAdmin(m *tgbotapi.Message) bool { func IsAdmin(m *tgbotapi.Message) bool {
return lo.Contains(conf.GetBotSettings().AdminID, m.From.ID) || return lo.Contains(conf.GetBotSettings().AdminID, m.From.ID) ||
lo.Contains(conf.GetBotSettings().AdminID, m.Chat.ID) lo.Contains(conf.GetBotSettings().AdminID, m.Chat.ID)