mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 18:26:16 +00:00
init
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package telegram
|
||||
|
||||
import tb "gopkg.in/telebot.v3"
|
||||
|
||||
const (
|
||||
START_CMD = "/start"
|
||||
)
|
||||
|
||||
var Cmds = []tb.Command{
|
||||
{
|
||||
Text: START_CMD,
|
||||
Description: "开始",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/assimon/luuu/model/data"
|
||||
"github.com/assimon/luuu/model/mdb"
|
||||
"github.com/gookit/goutil/mathutil"
|
||||
"github.com/gookit/goutil/strutil"
|
||||
tb "gopkg.in/telebot.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
ReplayAddWallet = "请发给我一个合法的钱包地址"
|
||||
)
|
||||
|
||||
func OnTextMessageHandle(c tb.Context) error {
|
||||
if c.Message().ReplyTo.Text == ReplayAddWallet {
|
||||
defer bots.Delete(c.Message().ReplyTo)
|
||||
_, err := data.AddWalletAddress(c.Message().Text)
|
||||
if err != nil {
|
||||
return c.Send(err.Error())
|
||||
}
|
||||
c.Send(fmt.Sprintf("钱包[%s]添加成功!", c.Message().Text))
|
||||
return WalletList(c)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func WalletList(c tb.Context) error {
|
||||
wallets, err := data.GetAllWalletAddress()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var btnList [][]tb.InlineButton
|
||||
for _, wallet := range wallets {
|
||||
status := "已启用✅"
|
||||
if wallet.Status == mdb.TokenStatusDisable {
|
||||
status = "已禁用🚫"
|
||||
}
|
||||
var temp []tb.InlineButton
|
||||
btnInfo := tb.InlineButton{
|
||||
Unique: wallet.Token,
|
||||
Text: fmt.Sprintf("%s[%s]", wallet.Token, status),
|
||||
Data: strutil.MustString(wallet.ID),
|
||||
}
|
||||
bots.Handle(&btnInfo, WalletInfo)
|
||||
btnList = append(btnList, append(temp, btnInfo))
|
||||
}
|
||||
addBtn := tb.InlineButton{Text: "添加钱包地址", Unique: "AddWallet"}
|
||||
bots.Handle(&addBtn, func(c tb.Context) error {
|
||||
return c.Send(ReplayAddWallet, &tb.ReplyMarkup{
|
||||
ForceReply: true,
|
||||
})
|
||||
})
|
||||
btnList = append(btnList, []tb.InlineButton{addBtn})
|
||||
return c.EditOrSend("请点击钱包继续操作", &tb.ReplyMarkup{
|
||||
InlineKeyboard: btnList,
|
||||
})
|
||||
}
|
||||
|
||||
func WalletInfo(c tb.Context) error {
|
||||
id := mathutil.MustUint(c.Data())
|
||||
tokenInfo, err := data.GetWalletAddressById(id)
|
||||
if err != nil {
|
||||
return c.Send(err.Error())
|
||||
}
|
||||
enableBtn := tb.InlineButton{
|
||||
Text: "启用",
|
||||
Unique: "enableBtn",
|
||||
Data: c.Data(),
|
||||
}
|
||||
disableBtn := tb.InlineButton{
|
||||
Text: "禁用",
|
||||
Unique: "disableBtn",
|
||||
Data: c.Data(),
|
||||
}
|
||||
delBtn := tb.InlineButton{
|
||||
Text: "删除",
|
||||
Unique: "delBtn",
|
||||
Data: c.Data(),
|
||||
}
|
||||
backBtn := tb.InlineButton{
|
||||
Text: "返回",
|
||||
Unique: "WalletList",
|
||||
}
|
||||
bots.Handle(&enableBtn, EnableWallet)
|
||||
bots.Handle(&disableBtn, DisableWallet)
|
||||
bots.Handle(&delBtn, DelWallet)
|
||||
bots.Handle(&backBtn, WalletList)
|
||||
return c.EditOrReply(tokenInfo.Token, &tb.ReplyMarkup{InlineKeyboard: [][]tb.InlineButton{
|
||||
{
|
||||
enableBtn,
|
||||
disableBtn,
|
||||
delBtn,
|
||||
},
|
||||
{
|
||||
backBtn,
|
||||
},
|
||||
}})
|
||||
}
|
||||
|
||||
func EnableWallet(c tb.Context) error {
|
||||
id := mathutil.MustUint(c.Data())
|
||||
if id <= 0 {
|
||||
return c.Send("请求不合法!")
|
||||
}
|
||||
err := data.ChangeWalletAddressStatus(id, mdb.TokenStatusEnable)
|
||||
if err != nil {
|
||||
return c.Send(err.Error())
|
||||
}
|
||||
return WalletList(c)
|
||||
}
|
||||
|
||||
func DisableWallet(c tb.Context) error {
|
||||
id := mathutil.MustUint(c.Data())
|
||||
if id <= 0 {
|
||||
return c.Send("请求不合法!")
|
||||
}
|
||||
err := data.ChangeWalletAddressStatus(id, mdb.TokenStatusDisable)
|
||||
if err != nil {
|
||||
return c.Send(err.Error())
|
||||
}
|
||||
return WalletList(c)
|
||||
}
|
||||
|
||||
func DelWallet(c tb.Context) error {
|
||||
id := mathutil.MustUint(c.Data())
|
||||
if id <= 0 {
|
||||
return c.Send("请求不合法!")
|
||||
}
|
||||
err := data.DeleteWalletAddressById(id)
|
||||
if err != nil {
|
||||
return c.Send(err.Error())
|
||||
}
|
||||
return WalletList(c)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"github.com/assimon/luuu/config"
|
||||
"github.com/assimon/luuu/util/log"
|
||||
tb "gopkg.in/telebot.v3"
|
||||
"gopkg.in/telebot.v3/middleware"
|
||||
"time"
|
||||
)
|
||||
|
||||
var bots *tb.Bot
|
||||
|
||||
// BotStart 机器人启动
|
||||
func BotStart() {
|
||||
var err error
|
||||
botSetting := tb.Settings{
|
||||
Token: config.TgBotToken,
|
||||
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
|
||||
}
|
||||
if config.TgProxy != "" {
|
||||
botSetting.URL = config.TgProxy
|
||||
}
|
||||
bots, err = tb.NewBot(botSetting)
|
||||
if err != nil {
|
||||
log.Sugar.Error(err.Error())
|
||||
return
|
||||
}
|
||||
err = bots.SetCommands(Cmds)
|
||||
if err != nil {
|
||||
log.Sugar.Error(err.Error())
|
||||
return
|
||||
}
|
||||
RegisterHandle()
|
||||
bots.Start()
|
||||
}
|
||||
|
||||
// RegisterHandle 注册处理器
|
||||
func RegisterHandle() {
|
||||
adminOnly := bots.Group()
|
||||
adminOnly.Use(middleware.Whitelist(config.TgManage))
|
||||
adminOnly.Handle(START_CMD, WalletList)
|
||||
adminOnly.Handle(tb.OnText, OnTextMessageHandle)
|
||||
}
|
||||
|
||||
// SendToBot 主动发送消息机器人消息
|
||||
func SendToBot(msg string) {
|
||||
go func() {
|
||||
user := tb.User{
|
||||
ID: config.TgManage,
|
||||
}
|
||||
_, err := bots.Send(&user, msg, &tb.SendOptions{
|
||||
ParseMode: tb.ModeHTML,
|
||||
})
|
||||
if err != nil {
|
||||
log.Sugar.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user