Fix the problem that the data parameter of inlinebtn cannot exceed 64 bytes
This commit is contained in:
parent
5378f1dfa0
commit
4c9503d390
39
README.md
39
README.md
@ -1 +1,38 @@
|
||||
## E5SubBot
|
||||
# E5SubBot
|
||||
|
||||
|
||||
|
||||
Github项目README.md模板
|
||||
(项目背景/作用介绍)
|
||||
|
||||
#### 示例:
|
||||
把使用了该项目的案例放在这里。可以放APK下载链接,或者简单放几张截图。
|
||||
(示例一开始就放出来,方便浏览者一眼就看出是不是想找的东西)
|
||||
|
||||
### 特性(可选)
|
||||
- 特性A
|
||||
|
||||
- 特性B
|
||||
|
||||
###原理说明(可选)
|
||||
阐述项目是基于什么思路设计的
|
||||
|
||||
|
||||
### 下载安装
|
||||
Gradle:
|
||||
``` xml
|
||||
compile 'xxx'
|
||||
```
|
||||
(说明项目的配置方法,android开源库多用Gradle导入)
|
||||
|
||||
### 使用方法
|
||||
怎么使用,有哪些步骤哪些接口。
|
||||
|
||||
### 注意事项
|
||||
比如混淆方法等
|
||||
|
||||
### TODO(可选)
|
||||
接下来的开发/维护计划。
|
||||
|
||||
## License
|
||||
GPLv3
|
||||
@ -38,16 +38,18 @@ func BindUser(m *tb.Message) string {
|
||||
var u MSData
|
||||
u.tgId = m.Chat.ID
|
||||
u.refreshToken = refresh
|
||||
u.msId = gjson.Get(info, "id").String()
|
||||
//TG的Data传递最高64bytes,一些msid超过了报错BUTTON_DATA_INVALID (0),采取md5
|
||||
u.msId = Get16MD5Encode(gjson.Get(info, "id").String())
|
||||
u.uptime = time.Now()
|
||||
u.other = SetJsonValue("{}", "alias", alias)
|
||||
//u.other = SetJsonValue(u.other, "sign", Get16MD5Encode(u.msId))
|
||||
//MS User Is Exist
|
||||
if MSUserIsExist(u.tgId, u.msId) {
|
||||
fmt.Printf("%d Bind error:MSUserHasExisted\n", m.Chat.ID)
|
||||
return "该ID对应的用户已经绑定过了"
|
||||
}
|
||||
//MS information has gotten
|
||||
bot.Send(m.Chat, "MS_ID: "+u.msId+"\nuserPrincipalName: "+gjson.Get(info, "userPrincipalName").String()+"\ndisplayName: "+gjson.Get(info, "displayName").String()+"\n")
|
||||
bot.Send(m.Chat, "MS_ID(MD5): "+u.msId+"\nuserPrincipalName: "+gjson.Get(info, "userPrincipalName").String()+"\ndisplayName: "+gjson.Get(info, "displayName").String()+"\n")
|
||||
if ok, err := AddData(db, u); !ok {
|
||||
fmt.Printf("%d Bind error: %s\n", m.Chat.ID, err)
|
||||
return "数据库写入错误"
|
||||
|
||||
21
handle.go
21
handle.go
@ -43,24 +43,21 @@ func bMy(m *tb.Message) {
|
||||
var inlineKeys [][]tb.InlineButton
|
||||
for _, u := range data {
|
||||
inlineBtn := tb.InlineButton{
|
||||
Unique: u.msId,
|
||||
Unique: "my" + u.msId,
|
||||
Text: gjson.Get(u.other, "alias").String(),
|
||||
Data: u.msId,
|
||||
}
|
||||
bot.Handle(&inlineBtn, bMyInlineBtn)
|
||||
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})
|
||||
_, err := bot.Send(m.Chat, "选择一个账户查看具体信息\n\n绑定数: "+strconv.Itoa(GetBindNum(m.Chat.ID))+"/"+strconv.Itoa(BindMaxNum), &tb.ReplyMarkup{InlineKeyboard: inlineKeys})
|
||||
fmt.Println(err)
|
||||
}
|
||||
func bMyInlineBtn(c *tb.Callback) {
|
||||
//var inlineKeys [][]tb.InlineButton
|
||||
//bot.Handle(&inlineBtn, bMyinlineBtn)
|
||||
//inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn})
|
||||
//bot.EditReplyMarkup(tb.Editable(c.MessageID, int64(c.Sender.ID)))
|
||||
fmt.Println(c.Data)
|
||||
r := QueryDataByMS(db, c.Data)
|
||||
u := r[0]
|
||||
bot.Send(c.Message.Chat, "信息\n别名:"+gjson.Get(u.other, "alias").String()+"\nMS_ID: "+u.msId+"\n最近更新时间: "+u.uptime.Format("2006-01-02 15:04:05"))
|
||||
bot.Send(c.Message.Chat, "信息\n别名:"+gjson.Get(u.other, "alias").String()+"\nMS_ID(MD5): "+u.msId+"\n最近更新时间: "+u.uptime.Format("2006-01-02 15:04:05"))
|
||||
bot.Respond(c)
|
||||
}
|
||||
func bBind(m *tb.Message) {
|
||||
@ -78,7 +75,7 @@ func bUnBind(m *tb.Message) {
|
||||
var inlineKeys [][]tb.InlineButton
|
||||
for _, u := range data {
|
||||
inlineBtn := tb.InlineButton{
|
||||
Unique: u.msId,
|
||||
Unique: "unbind" + u.msId,
|
||||
Text: gjson.Get(u.other, "alias").String(),
|
||||
Data: u.msId,
|
||||
}
|
||||
@ -89,12 +86,14 @@ func bUnBind(m *tb.Message) {
|
||||
}
|
||||
func bUnBindInlineBtn(c *tb.Callback) {
|
||||
fmt.Println(c.Data)
|
||||
if ok, _ := DelData(db, c.Data); !ok {
|
||||
fmt.Println(c.Data + " UnBind ERROR")
|
||||
r := QueryDataByMS(db, c.Data)
|
||||
u := r[0]
|
||||
if ok, _ := DelData(db, u.msId); !ok {
|
||||
fmt.Println(u.msId + " UnBind ERROR")
|
||||
bot.Send(c.Message.Chat, "解绑失败!")
|
||||
return
|
||||
}
|
||||
fmt.Println(c.Data + " UnBind Success")
|
||||
fmt.Println(u.msId + " UnBind Success")
|
||||
bot.Send(c.Message.Chat, "解绑成功!")
|
||||
bot.Respond(c)
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@ -74,7 +74,7 @@ func MakeHandle() {
|
||||
}
|
||||
func TaskLaunch() {
|
||||
task := cron.New()
|
||||
SignTask()
|
||||
//SignTask()
|
||||
//每三小时执行一次
|
||||
task.AddFunc("1 */3 * * *", SignTask)
|
||||
// */1 * * * *
|
||||
|
||||
17
sqlite.go
17
sqlite.go
@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/tidwall/gjson"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -98,22 +97,6 @@ func QueryDataAll(db *sql.DB) []MSData {
|
||||
}
|
||||
return result
|
||||
}
|
||||
func QueryDataBySign(db *sql.DB, tgId int64, sign string) []MSData {
|
||||
rows, err := db.Query("select * from users where tg_id = ?", tgId)
|
||||
CheckErr(err)
|
||||
var result = make([]MSData, 0)
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var refresht, othert, msidt string
|
||||
var tgIdt int64
|
||||
var uptimet time.Time
|
||||
rows.Scan(&tgIdt, &refresht, &msidt, &uptimet, &othert)
|
||||
if gjson.Get(othert, "sign").String() == sign {
|
||||
result = append(result, MSData{tgIdt, refresht, msidt, uptimet, othert})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//query data by tg_id
|
||||
func QueryDataByTG(db *sql.DB, tgId int64) []MSData {
|
||||
|
||||
14
util.go
14
util.go
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -80,3 +82,15 @@ func MarshalMSData(u MSData) string {
|
||||
result, _ := json.Marshal(MSNoTime)
|
||||
return string(result)
|
||||
}
|
||||
|
||||
//返回一个32位md5加密后的字符串
|
||||
func GetMD5Encode(data string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
//返回一个16位md5加密后的字符串
|
||||
func Get16MD5Encode(data string) string {
|
||||
return GetMD5Encode(data)[8:24]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user