1+ // Package hs 炉石
12package hs
23
34import (
45 "fmt"
56 "os"
67 "strconv"
78 "strings"
9+ "time"
810
911 "github.com/imroc/req"
1012 "github.com/tidwall/gjson"
1113 zero "github.com/wdvxdr1123/ZeroBot"
1214 "github.com/wdvxdr1123/ZeroBot/message"
1315)
1416
17+ const cachedir = "data/hs/"
18+
1519var header = req.Header {
1620 "user-agent" : `Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36` ,
1721 "referer" : `https://hs.fbigame.com` ,
1822}
1923
2024func init () {
25+ os .RemoveAll (cachedir )
26+ err := os .MkdirAll (cachedir , 0755 )
27+ if err != nil {
28+ panic (err )
29+ }
2130 zero .OnRegex (`^搜卡(.+)$` ).
2231 SetBlock (true ).SetPriority (20 ).Handle (func (ctx * zero.Ctx ) {
2332 List := ctx .State ["regex_matched" ].([]string )[1 ]
@@ -26,32 +35,38 @@ func init() {
2635 gjson .Get (g , `list.0.CardID` ).String ()+
2736 `.png?auth_key=` +
2837 gjson .Get (g , `list.0.auth_key` ).String (), header )
29- im .ToFile ("data/image/1.png" )
30- file , _ := os .Open ("data/image/1.png" )
31- sg , _ := req .Post ("https://pic.sogou.com/pic/upload_pic.jsp" , req.FileUpload {
32- File : file ,
33- FieldName : "image" , // FieldName 是表单字段名
34- FileName : "avatar.png" , // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上
35- })
36- var tx string
37- t := int (gjson .Get (g , `list.#` ).Int ())
38- if t == 0 {
39- ctx .SendChain (message .Text ("查询为空!" ))
40- return
41- }
42- for i := 0 ; i < t && i < 10 ; i ++ {
43- tx += strconv .Itoa (i + 1 ) + ". 法力:" +
44- gjson .Get (g , `list.` + strconv .Itoa (i )+ `.COST` ).String () +
45- " " +
46- gjson .Get (g , `list.` + strconv .Itoa (i )+ `.CARDNAME` ).String () +
47- "\n "
38+ cachefile := cachedir + strconv .Itoa (int (time .Now ().Unix ()))
39+ err := im .ToFile (cachefile )
40+ if err == nil {
41+ file , err := os .Open (cachefile )
42+ if err == nil {
43+ defer file .Close ()
44+ sg , _ := req .Post ("https://pic.sogou.com/pic/upload_pic.jsp" , req.FileUpload {
45+ File : file ,
46+ FieldName : "image" , // FieldName 是表单字段名
47+ FileName : "avatar.png" , // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上
48+ })
49+ var tx string
50+ t := int (gjson .Get (g , `list.#` ).Int ())
51+ if t == 0 {
52+ ctx .Send ("查询为空!" )
53+ return
54+ }
55+ for i := 0 ; i < t && i < 10 ; i ++ {
56+ tx += strconv .Itoa (i + 1 ) + ". 法力:" +
57+ gjson .Get (g , `list.` + strconv .Itoa (i )+ `.COST` ).String () +
58+ " " +
59+ gjson .Get (g , `list.` + strconv .Itoa (i )+ `.CARDNAME` ).String () +
60+ "\n "
61+ }
62+ ctx .SendChain (
63+ message .Image (sg .String ()),
64+ message .Text (tx ),
65+ )
66+ }
4867 }
49- ctx .SendChain (
50- message .Image (sg .String ()),
51- message .Text (tx ),
52- )
5368 })
54- //卡组
69+ // 卡组
5570 zero .OnRegex (`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$` ).
5671 SetBlock (true ).SetPriority (20 ).Handle (func (ctx * zero.Ctx ) {
5772 fmt .Print ("成功" )
0 commit comments