-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshamrock.js
491 lines (479 loc) · 11.8 KB
/
shamrock.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
import plugin from '../../lib/plugins/plugin.js'
import common from '../../lib/common/common.js'
import { Client } from 'icqq'
import { randomBytes } from 'crypto'
import * as pb from 'icqq/lib/core/protobuf/index.js'
export class shamrock extends plugin {
constructor () {
super({
name: 'shamrock专属接口',
dsc: 'shamrock杂七杂八接口',
/** https://oicqjs.github.io/oicq/#events */
event: 'message',
priority: -5000,
rule: [
{
/** 命令正则匹配 */
reg: '^#(群)?打卡',
/** 执行方法 */
fnc: 'sign'
},
{
/** 命令正则匹配 */
reg: '^#?发音乐',
/** 执行方法 */
fnc: 'music'
},
{
/** 命令正则匹配 */
reg: '^#?发(位置|地点)',
/** 执行方法 */
fnc: 'location'
},
{
/** 命令正则匹配 */
reg: '^#?发(链接|url|URL)',
/** 执行方法 */
fnc: 'url'
},
{
/** 命令正则匹配 */
reg: '^#?发?篮球',
/** 执行方法 */
fnc: 'basketball'
},
{
/** 命令正则匹配 */
reg: '^#?发(石头|剪子|剪刀|布|锤|锤子)',
/** 执行方法 */
fnc: 'newRps'
},
{
/** 命令正则匹配 */
reg: '^#?发骰子',
/** 执行方法 */
fnc: 'newDice'
},
{
reg: '^#?(查|查看)?电量',
/** 执行方法 */
fnc: 'battery'
},
{
reg: '^#?戳',
/** 执行方法 */
fnc: 'poke'
},
{
reg: '^#?发?龙',
/** 执行方法 */
fnc: 'loong'
},
{
reg: '',
/** 执行方法 */
fnc: 'onLoong',
log: false
}
]
})
}
async sign (e) {
if (e.group) {
await e.group.sign()
return await e.reply('打卡成功')
}
}
async music (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发音乐/, '')
if (args.trim() === '帮助') {
await e.reply('仅安装Lain插件并使用shamrock适配器时可用。at或者发送/引用图片,并发送参数标题;作者;跳转链接,默认值分别为测试音乐,用户群名片/昵称和某神秘网址')
return true
}
let images = await getImg(e)
if (images?.length > 0) {
let image = images[0]
let userId = e.isGroup ? (e.at ? e.at : e.sender.user_id) : e.sender.user_id
let defaultAuthor
if (e.isGroup) {
let user = await e.group.pickMember(userId)
defaultAuthor = user.user_displayname || user.card || user.nickname
} else {
let user = await e.bot.pickFriend(e.sender.user_id)
defaultAuthor = user.nickname
}
defaultAuthor = defaultAuthor || '测试作者'
let [title, singer = defaultAuthor, url = 'https://www.bilibili.com/video/BV1uT4y1P7CX'] = args.split(';', 3)
if (!title) {
title = '测试音乐'
}
await sendMsg(e, {
type: 'music',
data: {
type: 'custom',
url,
audio: 'https://music.163.com/song/media/outer/url?id=18520488.mp3', // 瞎填的
title,
singer,
image
}
})
}
}
async location (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发(位置|地点)/, '')
if (args.trim() === '帮助') {
await e.reply('仅安装Lain插件并使用shamrock适配器时可用。#发地点经度;纬度,如#发地点39.915168;116.403875')
return true
}
let [lat, lon = '116.403875'] = args.split(';', 2)
if (!lat) {
lat = '39.915168'
}
await sendMsg(e, {
type: 'location',
data: {
lat: parseFloat(lat),
lon: parseFloat(lon)
}
})
}
async url (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发(链接|url|URL)/, '')
if (args.trim() === '帮助') {
await e.reply('仅安装Lain插件并使用shamrock适配器时可用。#发链接url;标题;内容')
return true
}
let images = await getImg(e)
let image = images[0]
let [url, title = 'StrelitziaJS', content = '一些自用的yunzai js插件'] = args.split(';', 3)
if (!url) {
url = 'https://github.com/ikechan8370/StrelitziaJS'
}
await sendMsg(e, {
type: 'share',
data: {
url,
title,
content,
image
}
})
}
async basketball (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发?篮球/, '')
if (args.trim() === '帮助') {
await e.reply('仅安装Lain插件并使用shamrock适配器时可用。#发篮球+数字,如#发篮球1\n数字意义:5 没中, 4 擦边没中, 3 卡框, 2 擦边中, 1 正中\n默认则随机')
return true
}
let id
if (args) {
id = parseInt(args)
} else {
id = Math.floor(Math.random() * 5) + 1
}
await sendMsg(e, {
type: 'basketball',
data: {
id
}
})
}
async newRps (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发/, '')
let id = 0
switch (args) {
case '石头':
case '锤':
case '锤子': {
id = 3
break
}
case '剪子':
case '剪刀':
case '剪': {
id = 2
break
}
case '布': {
id = 3
break
}
default: {
logger.warn('unknown command')
}
}
// 好吧 完全随机 id并没什么用
await sendMsg(e, {
type: 'new_rps',
data: {
id
}
})
}
async newDice (e) {
if (e.adapter !== 'shamrock') {
return
}
let args = e.msg.replace(/^#?发骰子/, '')
if (args.trim() === '帮助') {
await e.reply('仅安装Lain插件并使用shamrock适配器时可用。#发骰子 随机发送一个骰子')
return true
}
let id
if (args) {
id = parseInt(args)
} else {
id = Math.floor(Math.random() * 6) + 1
}
await sendMsg(e, {
type: 'new_dice',
data: {
id
}
})
}
async battery (e) {
if (e.adapter !== 'shamrock') {
return
}
const api = (await import('../Lain-plugin/adapter/shamrock/api.js')).default
let res = await api.SendApi(e.self_id, 'get_device_battery')
const { battery, scale, status } = res
let text = `当前电量: ${battery}%\n`
if (this.e.isMaster) {
switch (status) {
case 3: {
// BATTERY_STATUS_DISCHARGING
text += '当前未在充电中😔'
break
}
case 2: {
// BATTERY_STATUS_CHARGING
text += '当前正在充电中🔋'
break
}
case 4: {
// BATTERY_STATUS_NOT_CHARGING
text += '当前连接电源线但未在充电中❌'
break
}
case 5: {
// BATTERY_STATUS_FULL
text += '电量充满了!✅'
break
}
case 1: {
// BATTERY_STATUS_UNKNOWN
if (battery < 0) {
text = '无电量信息,可能使用的是虚拟机或模拟器🎮'
}
break
}
}
if (scale > 0) {
text += `\n剩余电量${scale / 1000}毫安时`
}
} else if (battery < 0) {
text = '无电量信息,可能使用的是虚拟机或模拟器🎮'
}
await e.reply(text)
}
async poke (e) {
if (e.adapter !== 'shamrock') {
return
}
if (!e.isGroup) {
return
}
let times = e.msg.replace(/^#?戳/, '').replace('次', '')
try {
times = parseInt(times)
// 最多戳十次吧
times = Math.min(10, times)
} catch (err) {
times = 1
}
if (!times) {
times = 1
}
if (!e.isMaster) {
let lock = await redis.get(`Strelitzia:poke:${e.sender.user_id}`)
if (lock) {
await e.reply('戳一戳正在cd中哦')
return
}
times = 1
}
let userId = e.at || e.sender.user_id
const api = (await import('../Lain-plugin/adapter/shamrock/api.js')).default
for (let i = 0; i < times; i++) {
await api.SendApi(e.self_id, 'poke', {
group_id: e.group_id,
user_id: userId
})
await common.sleep(100)
}
if (!e.isMaster) {
await redis.set(`Strelitzia:poke:${e.sender.user_id}`, '1', { EX: 3 })
}
}
async loong (e) {
let times = e.msg.replace(/^#?发?龙/, '')
if (times) {
try {
times = parseInt(times)
} catch (e) {
times = 1
}
}
if (!e.isMaster) {
times = Math.min(3, times)
} else {
times = Math.min(10, times)
}
times = Math.max(times, 1)
for (let i = 0; i < times; i++) {
if (e.adapter !== 'shamrock') {
await icqqSendLoong(e)
} else {
await sendMsg(e, '[CQ:face,id=394]')
}
}
// 小龙392 stickerId=38 中龙393 stickerId=39 shamrock没写
}
async onLoong (e) {
try {
let loongs = [392, 393, 394]
if (e.message[0]?.type === 'face' && loongs.includes(e.message[0]?.id)) {
if (e.adapter !== 'shamrock') {
await icqqSendLoong(e)
} else {
sendMsg(e, '[CQ:face,id=394]')
}
}
} catch (err) {}
return false
}
}
async function sendMsg (e, data) {
const api = e.bot.api || (await import('../Lain-plugin/adapter/shamrock/api.js')).default
if (e.isGroup) {
await api.SendApi(e.self_id, 'send_group_msg', {
group_id: e.group_id,
message: data
})
} else {
await api.SendApi(e.self_id, 'send_private_msg', {
user_id: e.sender.user_id,
message: data
})
}
}
async function icqqSendLoong (e) {
/**
*
* @type {Client}
*/
let bot = Bot
const rich = {
2: [
{
37: {
1: 0,
16: 0,
17: 0,
19: { 15: 0, 25: 0, 30: 0, 31: 0, 34: 0, 41: 0, 51: 0, 52: 0, 54: 0, 55: 0, 56: 0, 71: 0, 72: 0, 73: { 1: 0, 2: 0, 3: 0, 4: 0 }, 96: 0 }
}
},
{
9: {
1: 0
}
},
{
53: {
1: 37,
2: {
1: '1',
2: '40',
3: 394,
4: 1,
5: 3,
7: '/龙年快乐',
9: 1
},
3: 3
}
},
{
1: {
1: '/新年大龙',
12: {
1: '[新年大龙]请使用最新版手机QQ体验新功能'
}
}
}
]
}
let body = {
1: e.isGroup ? { 2: { 1: e.group_id } } : { 1: { 1: e.friend.uid } },
2: {
1: 1,
2: 0,
3: 0
},
3: { 1: rich },
4: randomBytes(2).readUInt16BE(),
5: randomBytes(4).readUInt32BE()
}
console.log(body)
body = pb.encode(body)
await bot.sendUni('MessageSvc.PbSendMsg', body)
}
async function getImg (e) {
// 取消息中的图片、at的头像、回复的图片,放入e.img
if (e.at && !e.source) {
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`]
}
if (e.source) {
let reply
let seq = e.isGroup ? e.source.seq : e.source.time
if (e.adapter === 'shamrock') {
seq = e.source.message_id
}
if (e.isGroup) {
reply = (await e.group.getChatHistory(seq, 1)).pop()?.message
} else {
reply = (await e.friend.getChatHistory(seq, 1)).pop()?.message
}
if (reply) {
let i = []
for (let val of reply) {
if (val.type === 'image') {
i.push(val.url)
}
}
e.img = i
}
}
if (!e.img || e.img.length === 0) {
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.sender.user_id}`]
}
return e.img
}