2
2
package quan
3
3
4
4
import (
5
- "fmt "
5
+ "encoding/json "
6
6
"strconv"
7
7
"strings"
8
8
@@ -11,13 +11,18 @@ import (
11
11
"github.com/FloatTech/zbputils/control"
12
12
zero "github.com/wdvxdr1123/ZeroBot"
13
13
"github.com/wdvxdr1123/ZeroBot/message"
14
- "github.com/wdvxdr1123/ZeroBot/utils/helper"
15
14
)
16
15
17
16
const (
18
- quan = "http://tc.tfkapi. top/API/qqqz.php?qq=%v " // api
17
+ quan = "http://tfapi. top/API/qqqz.php?type=json& qq=" // api
19
18
)
20
19
20
+ type result struct {
21
+ Code int `json:"code"`
22
+ Msg string `json:"msg"`
23
+ Qz string `json:"qz"`
24
+ }
25
+
21
26
func init () { // 主函数
22
27
en := control .Register ("quan" , & ctrl.Options [* zero.Ctx ]{
23
28
DisableOnDefault : false ,
@@ -31,28 +36,25 @@ func init() { // 主函数
31
36
if str == "" { // user
32
37
str = strconv .FormatInt (ctx .Event .UserID , 10 )
33
38
}
34
- es , err := web .GetData (fmt . Sprintf ( quan , str ) ) // 将网站返回结果赋值
39
+ es , err := web .GetData (quan + str ) // 将网站返回结果赋值
35
40
if err != nil {
36
- ctx .SendChain (message .Text ("出现错误捏:" , err ))
37
- return
38
- }
39
- if len (helper .BytesToString (es )) <= 24 {
40
- ctx .SendChain (message .Text ("网站维护中" )) // 输出结果
41
+ ctx .SendChain (message .Text ("出现错误捏: " , err ))
41
42
return
42
43
}
43
- f := helper . BytesToString ( es )[ 24 :]
44
- _ , err = strconv . Atoi ( f )
44
+ var data result
45
+ err = json . Unmarshal ( es , & data )
45
46
if err != nil {
46
- ctx .SendChain (message .Text ("网站维护中" )) // 输出结果
47
+ ctx .SendChain (message .Text ("解析json错误: " , err ))
47
48
return
48
49
}
49
50
var msg strings.Builder
50
- msg .WriteString ("查询账号:" )
51
+ msg .WriteString ("查询账号: " )
51
52
msg .WriteString (str )
52
53
msg .WriteString ("\n " )
53
- msg .WriteString ("查询状态:成功\n " )
54
- msg .WriteString ("您的权重为:" )
55
- msg .WriteString (f )
54
+ msg .WriteString ("查询状态: " )
55
+ msg .WriteString (data .Msg )
56
+ msg .WriteString ("\n 您的权重为: " )
57
+ msg .WriteString (data .Qz )
56
58
ctx .SendChain (message .Text (msg .String ())) // 输出结果
57
59
})
58
60
}
0 commit comments