From 34a15524396a208ac6a481cf903556fa1961a39b Mon Sep 17 00:00:00 2001 From: iyear Date: Sat, 28 Mar 2020 15:22:23 +0800 Subject: [PATCH] Update --- handle.go | 31 ++++++++++++++++++++++++++----- main.go | 20 +++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/handle.go b/handle.go index 8ea4a7a..456e09e 100644 --- a/handle.go +++ b/handle.go @@ -42,8 +42,6 @@ func bMy(m *tb.Message) { data := QueryDataByTG(db, m.Chat.ID) var inlineKeys [][]tb.InlineButton for _, u := range data { - //uJson := MarshalMSData(u) - //fmt.Println(uJson) inlineBtn := tb.InlineButton{ Unique: u.msId, Text: gjson.Get(u.other, "alias").String(), @@ -54,7 +52,6 @@ func bMy(m *tb.Message) { } bot.Send(m.Chat, "选择一个账户查看具体信息\n\n绑定数: "+strconv.Itoa(GetBindNum(m.Chat.ID))+"/"+strconv.Itoa(BindMaxNum), &tb.ReplyMarkup{InlineKeyboard: inlineKeys}) } - func bMyInlineBtn(c *tb.Callback) { //var inlineKeys [][]tb.InlineButton //bot.Handle(&inlineBtn, bMyinlineBtn) @@ -76,6 +73,31 @@ func bBind(m *tb.Message) { } } +func bUnBind(m *tb.Message) { + data := QueryDataByTG(db, m.Chat.ID) + var inlineKeys [][]tb.InlineButton + for _, u := range data { + inlineBtn := tb.InlineButton{ + Unique: u.msId, + Text: gjson.Get(u.other, "alias").String(), + Data: u.msId, + } + bot.Handle(&inlineBtn, bUnBindInlineBtn) + inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn}) + } + bot.Send(m.Chat, "选择一个账户将其解绑\n\n当前绑定数: "+strconv.Itoa(GetBindNum(m.Chat.ID))+"/"+strconv.Itoa(BindMaxNum), &tb.ReplyMarkup{InlineKeyboard: inlineKeys}) +} +func bUnBindInlineBtn(c *tb.Callback) { + fmt.Println(c.Data) + if ok, _ := DelData(db, c.Data); !ok { + fmt.Println(c.Data + " UnBind ERROR") + bot.Send(c.Message.Chat, "解绑失败!") + return + } + fmt.Println(c.Data + " UnBind Success") + bot.Send(c.Message.Chat, "解绑成功!") + bot.Respond(c) +} func bAbout(m *tb.Message) { bot.Send(m.Sender, bStartContent) } @@ -99,8 +121,7 @@ func bOnText(m *tb.Message) { } else { bot.Send(m.Chat, info) } + UserStatus[m.Chat.ID] = USNone } - case USBind: - } } diff --git a/main.go b/main.go index 7b4e1f2..75d5113 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "fmt" + "github.com/robfig/cron/v3" "github.com/spf13/viper" "golang.org/x/net/proxy" tb "gopkg.in/tucnak/telebot.v2" @@ -56,21 +57,26 @@ func init() { } func main() { BotStart() - //b.Handle(tb.OnText, func(m *tb.Message) { - // b.Send(m.Sender, "hello world") - //}) - - //b.Start() } func BotStart() { - makeHandle() + MakeHandle() + TaskLaunch() bot.Start() } -func makeHandle() { +func MakeHandle() { bot.Handle("/start", bStart) bot.Handle("/my", bMy) bot.Handle("/bind", bBind) + bot.Handle("/unbind", bUnBind) bot.Handle("/about", bAbout) bot.Handle(tb.OnText, bOnText) //bot.Handle(tb.InlineButton{Unique: ""}) } +func TaskLaunch() { + task := cron.New() + SignTask() + //每三小时执行一次 + task.AddFunc("1 */3 * * *", SignTask) + // */1 * * * * + task.Start() +}