This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cqpapi.go
107 lines (91 loc) · 3.09 KB
/
cqpapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"net"
)
func getToken() {
json := "{\"method\":\"GetToken\",\"params\":{}}"
sendNotification(json)
}
func addFriend(responseFlag string, accept int32, memo string) {
responseFlag = jsonTrans(responseFlag)
memo = jsonTrans(memo)
json := fmt.Sprintf("{\"method\":\"FriendAdd\",\"params\":{\"responseFlag\":\"%s\",\"accept\":%d,\"memo\":\"%s\"}}", responseFlag, accept, memo)
sendNotification(json)
}
func addGroup(responseFlag string, subtype, accept int32, reason string) {
responseFlag = jsonTrans(responseFlag)
reason = jsonTrans(reason)
json := fmt.Sprintf("{\"method\":\"GroupAdd\",\"params\":{\"responseFlag\":\"%s\",\"subType\":%d,\"accept\":%d,\"reason\":\"%s\"}}", responseFlag, subtype, accept, reason)
sendNotification(json)
}
func leaveGroup(groupNum int64) {
json := fmt.Sprintf("{\"method\":\"GroupLeave\",\"params\":{\"groupnum\":%d}}", groupNum)
sendNotification(json)
}
func groupBan(groupNum, qqNum, seconds int64) {
json := fmt.Sprintf("{\"method\":\"GroupBan\",\"params\":{\"groupnum\":%d,\"qqnum\":%d,\"seconds\":%d}}", groupNum, qqNum, seconds)
sendNotification(json)
}
func sendGroupMessage(groupNum int64, message string) {
if len(message) > 0 {
message = jsonTrans(message)
json := fmt.Sprintf("{\"method\":\"SendGroupMessage\",\"params\":{\"groupnum\":%d,\"message\":\"%s\"}}", groupNum, message)
sendNotification(json)
}
}
func sendPrivateMessage(qqNum int64, message string) {
if len(message) > 0 {
message = jsonTrans(message)
json := fmt.Sprintf("{\"method\":\"SendPrivateMessage\",\"params\":{\"qqnum\":%d,\"message\":\"%s\"}}", qqNum, message)
sendNotification(json)
}
}
func sendDiscussMessage(discussNum int64, message string) {
if len(message) > 0 {
message = jsonTrans(message)
json := fmt.Sprintf("{\"method\":\"SendDiscussionMessage\",\"params\":{\"discussionnum\":%d,\"message\":\"%s\"}}", discussNum, message)
sendNotification(json)
}
}
func sendNotification(notification string) {
logger.Printf("\n<<< %s\n", notification)
var b = []byte(notification)
if clientConn == nil {
remoteAddress, err := net.ResolveTCPAddr("tcp4", "127.0.0.1:7000")
if err != nil {
logger.Printf("ResolveTCPAddr Error: %v\n", err)
return
}
clientConn, err = net.DialTCP("tcp4", nil, remoteAddress)
if err != nil {
logger.Printf("Net DialTCP Error: %v\n", err)
return
}
}
count, err := clientConn.Write(b)
if err != nil {
logger.Println(err)
}
if count != len(b) {
logger.Println("not all send...")
}
clientConn.Close()
clientConn = nil
}
func getLoginQQ() {
json := fmt.Sprintf("{\"method\":\"GetLoginQq\",\"params\":{}}")
sendNotification(json)
}
func getGroupList() {
json := fmt.Sprintf("{\"method\":\"GetGroupList\",\"params\":{}}")
sendNotification(json)
}
func getGroupMemberList(groupNum int64) {
json := fmt.Sprintf("{\"method\":\"GetGroupMemberList\",\"params\":{\"groupnum\":%d}}", groupNum)
sendNotification(json)
}
func getGroupMemberInfo(groupNum, qqNum int64) {
json := fmt.Sprintf("{\"method\":\"GetGroupMemberInfo\",\"params\":{\"groupnum\":%d,\"qqnum\":%d}}", groupNum, qqNum)
sendNotification(json)
}