forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package manager | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/FloatTech/ZeroBot-Plugin/utils/math" | ||
"github.com/FloatTech/ZeroBot-Plugin/utils/web" | ||
"github.com/sirupsen/logrus" | ||
"github.com/wdvxdr1123/ZeroBot/utils/helper" | ||
) | ||
|
||
// 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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package manager | ||
|
||
type Welcome struct { | ||
GrpID int64 `db:"gid"` | ||
Msg string `db:"msg"` | ||
} | ||
|
||
type Member struct { | ||
QQ int64 `db:"qq"` | ||
// github username | ||
Ghun string `db:"ghun"` | ||
} |
Oops, something went wrong.