feat: gateway
This commit is contained in:
@@ -1,5 +1,33 @@
|
||||
package tgbot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"tg-mc/conf"
|
||||
"tg-mc/defs"
|
||||
"tg-mc/models"
|
||||
"tg-mc/services/gateway"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ApproveHandler(update tgbotapi.Update, cmd defs.Command) {
|
||||
u, err := models.GetUserByTGID(update.CallbackQuery.From.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
gateway.GetAuthcator().SetAuth(u)
|
||||
|
||||
callback := tgbotapi.NewCallback(update.CallbackQuery.ID, "已授权")
|
||||
if _, err := conf.Bot.Request(callback); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
conf.Bot.Send(tgbotapi.NewDeleteMessage(update.CallbackQuery.Message.Chat.ID,
|
||||
update.CallbackQuery.Message.MessageID))
|
||||
conf.Bot.Send(tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID,
|
||||
fmt.Sprintf("已授权☑️: %s 登录MC", u.MCName)))
|
||||
}
|
||||
|
||||
// func ApproveHandler(update tgbotapi.Update, cmd defs.Command) {
|
||||
// u, err := models.GetUserByTGID(update.CallbackQuery.From.ID)
|
||||
// if err != nil {
|
||||
|
@@ -23,8 +23,8 @@ var funcHandlers = map[string]func(*tgbotapi.Message, interface{}){
|
||||
}
|
||||
|
||||
var callBackHandlers = map[string]func(tgbotapi.Update, defs.Command){
|
||||
// defs.CMD_APPROVE: ApproveHandler,
|
||||
// defs.CMD_REJECT: RejectHandler,
|
||||
defs.CMD_APPROVE: ApproveHandler,
|
||||
defs.CMD_REJECT: RejectHandler,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"tg-mc/conf"
|
||||
"tg-mc/defs"
|
||||
"tg-mc/models"
|
||||
"tg-mc/services/gateway"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -15,6 +16,8 @@ func RejectHandler(update tgbotapi.Update, cmd defs.Command) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
gateway.GetAuthcator().Reject(u)
|
||||
|
||||
callback := tgbotapi.NewCallback(update.CallbackQuery.ID, "已拒绝")
|
||||
if _, err := conf.Bot.Request(callback); err != nil {
|
||||
logrus.Panic(err)
|
||||
|
Reference in New Issue
Block a user