MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / checkNewUser

Function checkNewUser

plugin/manager/gist.go:20–44  ·  view source on GitHub ↗
(qq, gid int64, ghun, hash string)

Source from the content-addressed store, hash-verified

18const gistraw = "https://gist.githubusercontent.com/%s/%s/raw/%s"
19
20func checkNewUser(qq, gid int64, ghun, hash string) (bool, string) {
21 if db.CanFind("member", "WHERE ghun = ?", ghun) {
22 return false, "该github用户已入群"
23 }
24 gidsum := md5.Sum(helper.StringToBytes(strconv.FormatInt(gid, 10)))
25 gidhex := hex.EncodeToString(gidsum[:])
26 u := fmt.Sprintf(gistraw, ghun, hash, gidhex)
27 logrus.Debugln("[gist]visit url:", u)
28 data, err := web.GetData(u)
29 if err == nil {
30 logrus.Debugln("[gist]get data:", helper.BytesToString(data))
31 st, err := strconv.ParseInt(helper.BytesToString(data), 10, 64)
32 if err == nil {
33 // 600s 内验证成功
34 ok := math.Abs(int(time.Now().Unix()-st)) < 600
35 if ok {
36 _ = db.Insert("member", &member{QQ: qq, Ghun: ghun})
37 return true, ""
38 }
39 return false, "时间戳超时"
40 }
41 return false, "时间戳格式错误: " + helper.BytesToString(data)
42 }
43 return false, "无法连接到gist: " + err.Error()
44}

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected