forked from Yorunina/EPK_mirai_API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPK_mirai_API.js
146 lines (132 loc) · 4.76 KB
/
EPK_mirai_API.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var WebSocket = require('ws');
var zlib = require('zlib');
var fs = require('fs');
var http=require('http');
var request=require('request');
var urlencode = require('urlencode');
const { time, timeStamp } = require('console');
//执行包导入
var ws = new WebSocket('ws://0.0.0.0:6700');
var uploadurl = "http://localhost:8000";
//创建一个websocket链接
//戳一戳事件
function poke_event(data){
group_id = data.group_id ? data.group_id : "0";
queststr = data.user_id + "|" + data.target_id + "|" + group_id;
request(uploadurl + "/?msg=" + urlencode("[HTTP戳一戳]" + queststr), function (error, response, body){
});
console.log("已发送戳一戳消息(" + queststr + ")");
return;
};
//运气王事件
function lucky_king_event(data){
queststr = data.user_id + "|" + data.target_id + "|" + data.group_id;
request(uploadurl + "/?msg=" + urlencode("[HTTP运气王]"+queststr),function (error, response, body){
});
console.log("已发送运气王消息(" + queststr + ")");
return;
};
//群荣耀变更事件
function honor_event(data){
queststr = data.user_id + "|" + data.honor_type + "|" + data.group_id
request(uploadurl + "/?msg=" + urlencode("[HTTP群荣耀变更]"+queststr),function (error, response, body){
});
console.log("已发送群荣耀变更消息(" + queststr + ")");
return;
};
//群撤回事件
function group_recall_event(data){
queststr = data.user_id + "|" + data.operator_id + "|" + data.message_id + "|" + data.group_id;
request(uploadurl + "/?msg=" + urlencode("[HTTP群消息撤回]"+queststr),function (error, response, body){
});
console.log("已发送群撤回消息(" + queststr + ")");
return;
};
//好友撤回事件
function friend_recall_event(data){
queststr = data.user_id + "|" + data.user_id + "|" + data.message_id + "|0";
request(uploadurl + "/?msg=" + urlencode("[HTTP好友消息撤回]"+queststr),function (error, response, body){
});
console.log("已发送好友撤回消息(" + queststr + ")");
return;
};
//精华消息事件
function essence_event(data){
//测试类别
queststr = data.sender_id + "|" + data.operator_id + "|" + data.message_id + "|" +data.sub_type;
request(uploadurl + "/?msg=" + urlencode("[HTTP精华消息]"+queststr),function (error, response, body){
});
console.log("已发送精华消息(" + queststr + ")");
return;
};
function client_status_event(data){
//客户端状态变更
};
function exit_event(){
queststr = new Date().getTime();
request(uploadurl + "/?msg=" + urlencode("[HTTPws断开]") + queststr,function (error, response, body){
});
console.log("已发送ws断开信息(" + queststr + ")")
return;
};
//定义链接建立时的动作
ws.onopen = function (e) {
console.log("与go-cqhttp正向ws接触成功!");
};
//主消息事件处理序列
ws.onmessage = function (e) {
var Jdata = e.data;
if(Jdata){
data = JSON.parse(Jdata.trim());
switch (data.post_type){
case "notice":
//常规事件类别
switch (data.notice_type){
//特殊提醒事件
case "notify":
switch (data.sub_type){
case "poke":
//戳一戳事件
poke_event(data);
break;
case "lucky_king":
//运气王事件
lucky_king_event(data);
break;
case "honor":
//群荣耀事件
honor_event(data);
break;
default:
}
break;
case "group_recall":
//群撤回事件
group_recall_event(data);
break;
case "friend_recall":
//好友撤回事件
friend_recall_event(data);
break;
case "essence":
//精华消息事件
essence_event(data);
break;
case "client_status":
//客户端在线状态变更
client_status_event(data);
break;
default:
}
break;
default:
}
}
};
ws.onerror = function (e) {
console.log("error:" + e);
};
ws.onclose = function (e) {
console.log("ws连接关闭/丢失,我直接爆炸开。");
exit_event();
};