-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmiddleware.js
271 lines (223 loc) · 7.28 KB
/
middleware.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
const axios = require('axios');
const url = "http://localhost:9999/otto"
/**
* 获取本地服务响应
* @param {string} path 本地服务路由
* @param {number} timeout 超时时间
* @example
*/
async function accessLocalService(path, timeout) {
try {
const response = await Promise.race([
axios.get(url + path),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Request timeout')), timeout)
)
]);
return response.data;
} catch (error) {
console.error('Error fetching response:', error);
throw error;
}
}
// 获取发送者ID
function getSenderID() {
console.log(process.argv);
const arg = process.argv[1];
return arg
}
// 推送消息
function push(imType, groupCode, userID, title, content) {
return accessLocalService(`/push?imtype=${imType}&groupcode=${groupCode}&userid=${userID}&title=${title}&content=${content}`, 5000,);
}
// 获取机器人名称
function name() {
return accessLocalService(`/name`, 5000);
}
// 获取机器id
function machineId() {
return accessLocalService(`/machineId`, 5000);
}
// 获取机器人版本
function version() {
return accessLocalService(`/version`, 5000);
}
// 获取数据库数据
function get(key) {
return accessLocalService(`/get?key=${key}`, 5000);
}
// 设置数据库数据
function set(key, value) {
return accessLocalService(`/set?key=${key}&value=${value}`, 5000);
}
// 删除数据库数据
function del(key) {
return accessLocalService(`/del?key=${key}`, 5000);
}
// 获取指定数据库指定的key值
function bucketGet(bucket, key) {
return accessLocalService(`/bucketGet?bucket=${bucket}&key=${key}`, 5000);
}
// 设置指定数据库指定的key值
function bucketSet(bucket, key, value) {
return accessLocalService(`/bucketSet?bucket=${bucket}&key=${key}&value=${value}`, 5000);
}
// 删除指定数据库指定key的值
function bucketDel(bucket, key) {
return accessLocalService(`/bucketDel?bucket=${bucket}&key=${key}`, 5000);
}
// 获取指定数据库所有值为value的keys
function bucketKeys(bucket, value) {
keys = accessLocalService(`/bucketKeys?bucket=${bucket}&value=${value}`, 5000);
return keys.split(",");
}
// 获取指定数据桶内所有的key集合
function bucketAllKeys(bucket) {
keys = accessLocalService(`/bucketAllKeys?bucket=${bucket}`, 5000);
return keys.split(",");
}
// 通知管理员
function notifyMasters(content, imtypes) {
return accessLocalService(`/notifyMasters?content=${content}&imtypes=${imtypes}`, 5000);
}
// 当前系统咖啡码激活状态
function coffee() {
return accessLocalService(`/coffee`, 5000);
}
// 京东、淘宝、拼多多转链推广
function spread(msg) {
return accessLocalService(`/spread?msg=${msg}`, 5000);
}
class Sender {
constructor(senderID) {
// 发送者ID,格式:in64时间戳,
this.senderID = senderID;
// 获取发送者渠道
this.getImtype = function () {
accessLocalService(`/getImtype?senderid=${senderID}`, 5000);
}
// 获取当前用户id
this.getUserID = function () {
return accessLocalService(`/getUserID?senderid=${senderID}`, 5000);
}
// 获取当前用户名
this.getUserName = function () {
return accessLocalService(`/getUserName?senderid=${senderID}`, 5000);
}
// 获取用户头像url
this.getUserAvatarUrl = function () {
return accessLocalService(`/getUserAvatarUrl?senderid=${senderID}`, 5000);
}
// 获取当前群组id
this.getGroupID = function () {
return accessLocalService(`/getGroupID?senderid=${senderID}`, 5000);
}
// 获取当前群组名称
this.getGroupName = function () {
return accessLocalService(`/getGroupName?senderid=${senderID}`, 5000);
}
// 是否管理员
this.isAdmin = function () {
return "true" == accessLocalService(`/isAdmin?senderid=${senderID}`, 5000);
}
// 获取消息
this.getMessage = function () {
return accessLocalService(`/getMessage?senderid=${senderID}`, 5000);
}
// 获取消息ID
this.getMessageID = function () {
return accessLocalService(`/getMessageID?senderid=${senderID}`, 5000);
}
// 撤回消息
this.recallMessage = function (messageid) {
accessLocalService(`/recallMessage?senderid=${senderID}&id=${messageid}`, 5000);
}
// 获取匹配的文本参数
this.param = function (index) {
return accessLocalService(`/param?senderid=${senderID}&index=${index}`, 5000);
}
// 回复文本消息
this.reply = function (text) {
accessLocalService(`/sendText?senderid=${senderID}&text=${text}`, 5000);
}
// 回复图片消息
this.replyImage = function (imageUrl) {
accessLocalService(`/sendImage?senderid=${senderID}&imageurl=${imageUrl}`, 5000);
}
// 回复语音消息
this.replyVoice = function (voiceUrl) {
accessLocalService(`/sendVoice?senderid=${senderID}&voiceurl=${voiceUrl}`, 5000);
}
// 回复视频消息
this.replyVideo = function (videoUrl) {
accessLocalService(`/sendVideo?senderid=${senderID}&videourl=${videoUrl}`, 5000);
}
//等待用户输入
this.listen = function (timeout) {
accessLocalService(`/listen?senderid=${senderID}&timeout=${timeout}`, timeout);
}
//等待支付
this.waitPay = function (exitcode,timeout) {
accessLocalService(`/waitPay?senderid=${senderID}&exitcode=${exitcode}&timeout=${timeout}`, timeout);
}
//是否处于等待支付状态
this.atWaitPay = function () {
return "true" == accessLocalService(`/atWaitPay`, 5000);
}
//邀请入群
this.groupInviteIn = function (friend,group) {
accessLocalService(`/groupInviteIn?senderid=${senderID}&friend=${friend}&group=${group}`, 5000);
}
//踢群
this.groupKick = function (userid) {
accessLocalService(`/groupKick?senderid=${senderID}&userid=${userid}`, 5000);
}
//禁言
this.groupBan = function (userid,timeout) {
accessLocalService(`/groupBan?senderid=${senderID}&userid=${userid}&timeout=${timeout}`, 5000);
}
//解除禁言
this.groupUnban = function (userid) {
accessLocalService(`/groupUnban?senderid=${senderID}&userid=${userid}`, 5000);
}
//全员禁言
this.groupWholeBan=function(){
accessLocalService(`/groupWholeBan?senderid=${senderID}`, 5000);
}
//解除全员禁言
this.groupWholeUnban=function(){
accessLocalService(`/groupWholeUnban?senderid=${senderID}`, 5000);
}
//发送群公告
this.groupNoticeSend=function(notice){
accessLocalService(`/groupNoticeSend?senderid=${senderID}¬ice=${notice}`, 5000);
}
//获取当前处理流程的插件名
this.getPluginName = function () {
return accessLocalService(`/getPluginName?senderid=${senderID}`, 5000);
}
//获取当前处理流程的插件版本
this.getPluginVersion = function () {
return accessLocalService(`/getPluginVersion?senderid=${senderID}`, 5000);
}
};
}
module.exports = {
Sender,
getSenderID: getSenderID,
push: push,
name: name,
machineId: machineId,
version: version,
get: get,
set: set,
del: del,
bucketGet: bucketGet,
bucketSet: bucketSet,
bucketDel: bucketDel,
bucketKeys: bucketKeys,
bucketAllKeys: bucketAllKeys,
notifyMasters: notifyMasters,
coffee: coffee,
spread: spread,
}