mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
🎨 优化目录结构
This commit is contained in:
44
plugin/manager/gist.go
Normal file
44
plugin/manager/gist.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
|
||||
"github.com/FloatTech/zbputils/math"
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
)
|
||||
|
||||
// user hash file
|
||||
const gistraw = "https://gist.githubusercontent.com/%s/%s/raw/%s"
|
||||
|
||||
func checkNewUser(qq, gid int64, ghun, hash string) (bool, string) {
|
||||
if db.CanFind("member", "where ghun="+ghun) {
|
||||
return false, "该github用户已入群"
|
||||
}
|
||||
gidsum := md5.Sum(helper.StringToBytes(strconv.FormatInt(gid, 10)))
|
||||
gidhex := hex.EncodeToString(gidsum[:])
|
||||
u := fmt.Sprintf(gistraw, ghun, hash, gidhex)
|
||||
logrus.Debugln("[gist]visit url:", u)
|
||||
data, err := web.GetData(u)
|
||||
if err == nil {
|
||||
logrus.Debugln("[gist]get data:", helper.BytesToString(data))
|
||||
st, err := strconv.ParseInt(helper.BytesToString(data), 10, 64)
|
||||
if err == nil {
|
||||
// 600s 内验证成功
|
||||
ok := math.Abs(int(time.Now().Unix()-st)) < 600
|
||||
if ok {
|
||||
_ = db.Insert("member", &member{QQ: qq, Ghun: ghun})
|
||||
return true, ""
|
||||
}
|
||||
return false, "时间戳超时"
|
||||
}
|
||||
return false, "时间戳格式错误: " + helper.BytesToString(data)
|
||||
}
|
||||
return false, "无法连接到gist: " + err.Error()
|
||||
}
|
||||
Reference in New Issue
Block a user