-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathguoba.support.js
More file actions
759 lines (742 loc) · 23.4 KB
/
Copy pathguoba.support.js
File metadata and controls
759 lines (742 loc) · 23.4 KB
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
import Cfg from './lib/config/config.js'
import Yaml from './model/YamlHandler.js'
/**
* 支持锅巴
* 锅巴插件:https://gitee.com/guoba-yunzai/guoba-plugin.git
* 组件类型,可参考 https://vvbin.cn/doc-next/components/introduction.html
* https://antdv.com/components/overview-cn/
*/
// function guildList() {
// const guilds = []
// const channels = []
// const prefixBlack = []
// /** 延迟10秒加载数据,防止某些数据没有加载 */
// setTimeout(async () => {
// while (true) {
// /** 防止为空 */
// if (Bot?.lain?.guilds) {
// const list = Bot.lain.guilds
// for (let id in list) {
// /** 频道 */
// guilds.push({ label: list[id].name, value: `qg_${id}` })
// /** 这里是子频道 */
// for (let i in list[id].channels) {
// channels.push({ label: list[id].name + '-' + list[id].channels[i], value: i })
// }
// }
// break
// } else {
// await lain.sleep(1000)
// }
// }
// const cfg = new yaml('./plugins/Lain-plugin/config/bot.yaml')
// const config = cfg.data()
// for (const i in config) {
// prefixBlack.push({ label: Bot?.[i]?.name || '未知', value: config[i].appID })
// }
// }, 10000)
export function supportGuoba () {
/** 添加url链接白名单 */
const addUrlPromptProps = {
content: '请输入URL:',
placeholder: '请输入URL',
okText: '添加',
rules: [
{ required: true, message: 'URL得填上才行哦~' },
{ pattern: '^https?://\\S+', message: '请输入合法的URL' },
{ max: 255, message: 'URL太长了……' }
]
}
return {
pluginInfo: {
name: '铃音插件',
title: 'Lain-plugin',
author: [
'@sky-summer',
'@Lain.'
],
authorLink: [
'https://gitee.com/sky-summer',
'https://gitee.com/Zyy955'
],
link: 'https://gitee.com/sky-summer/Lain-plugin',
isV3: true,
isV2: false,
description: '主要为云崽提供QQ频道、PC微信、网页版微信机器人等功能',
// 显示图标,此为个性化配置
// 图标可在 https://icon-sets.iconify.design 这里进行搜索
icon: 'mdi: image-filter-drama-outline',
// 图标颜色,例:#FF0000 或 rgb(255, 0, 0)
iconColor: '#6bb9dd',
// 如果想要显示成图片,也可以填写图标路径(绝对路径)
iconPath: process.cwd() + '/plugins/Lain-plugin/resources/icon.png'
},
// 配置项信息
configInfo: {
// 配置项 schemas
schemas: [
{
label: 'HTTP服务器设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Server.baseUrl',
label: '方法1:公网地址',
bottomHelpMessage: '请输入HTTP服务的公网地址,服务器放行http端口',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入公网地址'
}
},
{
field: 'Server.baseIP',
label: '方法2:公网IP',
bottomHelpMessage: '请输入HTTP服务的公网IP,服务器放行http端口',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入公网IP'
}
},
{
field: 'Server.port',
label: '端口',
bottomHelpMessage: '请输入HTTP服务器端口(Shamrock、QQBot共用)',
component: 'InputNumber',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入HTTP服务器端口(Shamrock、QQBot共用)',
min: 1,
max: 65535
}
},
{
field: 'Server.InvalidTime',
label: '临时文件失效时间',
bottomHelpMessage: '请输入时间(QQBot使用)',
component: 'InputNumber',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入时间(QQBot使用)',
min: 1,
addonAfter: 's'
}
},
{
label: 'QQBot设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Token.QQ_Token',
label: 'QQBot Token配置',
bottomHelpMessage: '点击列表项右上角可删除配置,删除后请重启云崽以应用更新',
component: 'GSubForm',
componentProps: {
multiple: true,
schemas: [
{
label: '基础信息设置',
component: 'Divider'
},
{
field: 'appid',
label: 'AppID',
bottomHelpMessage: '机器人ID',
component: 'Input',
required: true,
rules: [
{ pattern: '^\\d{9,}$', message: '最少需要9位哦!' }
]
},
{
field: 'token',
label: 'Token',
bottomHelpMessage: '机器人令牌',
component: 'InputPassword',
required: true
},
{
field: 'secret',
label: 'AppSecret',
bottomHelpMessage: '机器人秘钥',
component: 'InputPassword',
required: true
},
{
label: '',
component: 'Divider'
},
{
field: 'mode',
label: '运行模式',
bottomHelpMessage: '设置运行模式',
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
optionType: 'button',
options: [
{ label: 'websocket', value: 'websocket' },
{ label: 'webhook', value: 'webhook' },
{ label: 'middleware', value: 'middleware' }
]
}
},
{
field: 'type',
label: '启用范围',
bottomHelpMessage: '设置启用的范围',
component: 'Select',
componentProps: {
options: [
{ label: '全部启用', value: 0 },
{ label: '仅启用QQ频道', value: 1 },
{ label: '仅启用QQ群', value: 2 },
{ label: '不启用', value: 3 }
]
}
},
{
field: 'timeout',
label: '超时时间',
bottomHelpMessage: 'QQBot接口请求超时时间',
component: 'InputNumber',
componentProps: {
type: 'number',
placeholder: '请输入时间',
addonAfter: 'ms',
min: 1
}
},
{
label: '防倒卖提示设置',
component: 'Divider'
},
{
field: 'other.Tips',
label: '发送防倒卖提示',
bottomHelpMessage: '进入新群时发送',
component: 'Switch'
},
{
field: 'other.Tips_GroupId',
label: 'QQ群号',
bottomHelpMessage: '防倒卖提示中的QQ群号',
component: 'Input'
},
{
label: '其他设置',
component: 'Divider'
},
{
field: 'sandbox',
label: '使用沙盒',
bottomHelpMessage: 'Bot提审时及上线后须关闭',
component: 'Switch'
},
{
field: 'allMsg',
label: 'QQ频道接收全部消息',
bottomHelpMessage: '',
component: 'Switch'
},
{
field: 'removeAt',
label: '移除at',
bottomHelpMessage: '开启后发送指令无需at,仅私域Bot可用',
component: 'Switch'
},
{
field: 'other.Prefix',
label: '前缀转换',
bottomHelpMessage: 'QQBot前缀转换 [/] => [#]',
component: 'Switch'
},
{
field: 'other.QQCloud',
label: 'QQ图床',
bottomHelpMessage: '填写QQ号后启用,使用QQ发送图片',
component: 'Input'
},
{
label: 'markdown设置',
component: 'Divider'
},
{
field: 'markdown.type',
label: '模板模式',
bottomHelpMessage: '',
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
optionType: 'button',
options: [
{ label: '关闭', value: 0 },
{ label: '全局模式', value: 1 },
{ label: '正则模式', value: 2 },
{ label: '按钮模式', value: 3 }
]
}
},
{
field: 'markdown.id',
label: '模板ID',
bottomHelpMessage: '',
component: 'Input'
},
{
field: 'markdown.text',
label: '模板文字键',
bottomHelpMessage: '',
component: 'Input'
},
{
field: 'markdown.img_dec',
label: '模板图片宽高键',
bottomHelpMessage: '',
component: 'Input'
},
{
field: 'markdown.img_url',
label: '模板图片url键',
bottomHelpMessage: '',
component: 'Input'
}
]
}
},
{
label: 'PC微信设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Adapter.ComWeChat.autoFriend',
label: '自动同意加好友',
component: 'RadioGroup',
bottomHelpMessage: '是否自动同意加好友',
componentProps: {
options: [
{ label: '不处理', value: 0 },
{ label: '自动同意', value: 1 }
]
}
},
{
field: 'Adapter.ComWeChat.name',
label: '椰奶状态名称',
bottomHelpMessage: '自定义PC微信椰奶状态名称',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入椰奶状态名称'
}
},
{
label: '网页微信设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Adapter.WeXin.autoFriend',
label: '自动同意加好友',
component: 'RadioGroup',
bottomHelpMessage: '是否自动同意加好友',
componentProps: {
options: [
{ label: '不处理', value: 0 },
{ label: '自动同意', value: 1 }
]
}
},
{
field: 'Adapter.WeXin.name',
label: '椰奶状态名称',
bottomHelpMessage: '自定义微信椰奶状态名称',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入椰奶状态名称'
}
},
{
label: 'Shamrock设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Adapter.Shamrock.baseUrl',
label: 'Shamrock主动http链接',
bottomHelpMessage: '例如http://localhost:5700。若填写将通过此端口进行文件上传等被动ws不支持的操作',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入公网地址'
}
},
{
field: 'Adapter.Shamrock.token',
label: '鉴权token',
bottomHelpMessage: 'Shamrock鉴权token,如果开放公网强烈建议配置',
component: 'InputPassword',
required: false,
componentProps: {
placeholder: '请输入shamrock鉴权token'
}
},
{
field: 'Adapter.Shamrock.githubKey',
label: 'Github Access Token',
component: 'InputPassword',
bottomHelpMessage: '用于查询shamrock仓库版本信息。登录网页github点击右上角头像,然后settings-developer-personal access tokens-Fine-grained tokens创建一个默认的即可',
required: false,
componentProps: {
placeholder: '请输入Github Access Token'
}
},
{
label: '标准输入设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Adapter.Stdin.state',
label: '标准输入开关',
bottomHelpMessage: '是否开启标准输入',
component: 'Switch'
},
{
field: 'Adapter.Stdin.name',
label: '标准输入昵称',
bottomHelpMessage: '自定义标准输入的椰奶状态名称',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入自定义标准输入昵称'
}
},
{
field: 'Adapter.Stdin.avatar',
label: '标准输入头像',
bottomHelpMessage: '自定义标准输入的椰奶状态头像',
component: 'Input',
required: false,
componentProps: {
placeholder: '请输入自定义标准输入头像路径,可选绝对路径或以崽目录开始相对路径'
}
},
{
label: '其他设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'Other.DelFileCron',
label: '定时清理缓存',
bottomHelpMessage: '在指定的时间清理缓存',
component: 'EasyCron',
componentProps: {
multiple: true,
placeholder: '请输入或选择Cron表达式'
}
},
{
field: 'Other.ICQQtoFile',
label: 'ICQQ魔法文件',
bottomHelpMessage: '是否开启',
component: 'Switch'
},
{
field: 'Other.QQBotdau',
label: 'QQBotdau统计',
bottomHelpMessage: '是否开启QQBotdau统计功能',
component: 'Switch'
},
{
field: 'Other.WhiteLink',
label: '白名单url',
bottomHelpMessage: 'url白名单,在白名单中的链接不会转为二维码',
component: 'GTags',
componentProps: {
placeholder: '请输入链接',
allowAdd: true,
allowDel: true,
showPrompt: true,
promptProps: addUrlPromptProps,
valueFormatter: ((value) => String(value)).toString()
}
}
],
// 获取配置数据方法(用于前端填充显示数据)
getConfigData () {
let QQ_Token = Object.values(Cfg.getToken('QQ_Token') ?? {}).map(i => {
i.other.Tips_GroupId = i.other['Tips-GroupId']
return i
})
return {
Server: Cfg.Server,
Adapter: {
ComWeChat: Cfg.ComWeChat,
WeXin: Cfg.WeXin,
Shamrock: Cfg.Shamrock,
Stdin: Cfg.Stdin
},
Other: Cfg.Other,
Token: {
QQ_Token
}
}
},
// 设置配置的方法(前端点确定后调用的方法)
setConfigData (data, { Result }) {
const selectPath = (name) => {
if (name === 'Token') return `/${name}.yaml`
else return `/Config-${name}.yaml`
}
try {
for (let i in data) {
let value = data[i]
i = i.split('.')
let key = i.shift()
let config = new Yaml(lain._pathCfg + selectPath(key))
if (key === 'Token') {
value = parseQQToken(config, value)
}
config.set(i.join('.'), value)
}
return Result.ok({}, '保存成功~')
} catch (err) {
logger.error('[Lain-plugin][锅巴] 保存失败:\n', err)
return Result.error(`保存失败:\n${err.message}`)
}
}
}
}
}
function convertToNestedObject (data) {
const result = {}
for (const key in data) {
if (Object.hasOwn(data, key)) {
const keys = key.split('.')
let obj = result
keys.forEach((k, index) => {
if (index === keys.length - 1) {
obj[k] = data[key]
} else {
obj[k] = obj[k] || {}
obj = obj[k]
}
})
}
}
return result
}
function parseQQToken (cfg, token) {
let ret = {}
token.map(async i => {
const config = convertToNestedObject(i)
/** 单独处理部分参数 */
config.other['Tips-GroupId'] = Number(config.other.Tips_GroupId) || ''
delete config.other.Tips_GroupId
config.other.QQCloud = Number(config.other.QQCloud) || ''
if (String(config.appid).length < 9) return
config.appid = String(config.appid)
/** 看下是否配置已存在 */
if (cfg.value('QQ_Token', config.appid)) {
ret[String(config.appid)] = {
...cfg.get('QQ_Token', config.appid),
...config
}
} else {
ret[config.appid] = config
}
try {
const QQSDK = (await import('./adapter/QQBot/QQSDK.js')).default
const QQBot = (await import('./adapter/QQBot/index.js')).default
const QQGuild = (await import('./adapter/QQBot/QQGuild.js')).default
lain.info(config.appid, '正在建立连接,请稍等~')
const SDK = new QQSDK(config)
await SDK.start()
switch (config.type) {
case 0:
/** 同时接群和频道 */
try {
const QQB = new QQBot(SDK.sdk, true)
lain.info(config.appid, await QQB.StartBot())
await lain.sleep(1000)
lain.info(config.appid, await new QQGuild(SDK.sdk, true).StartBot())
} catch (err) {
lain.error(config.appid, err)
}
break
case 1:
/** 开始连接QQ频道Bot */
lain.info(config.appid, await new QQGuild(SDK.sdk, true).StartBot())
break
case 2:
try {
const bot = new QQBot(SDK.sdk, true)
lain.info(config.appid, await bot.StartBot())
} catch (err) {
lain.error(config.appid, err)
}
break
default:
break
}
} catch (error) {
/** 异常处理 */
lain.error(config.appid, error)
}
})
return ret
}
/** 后续添加(咕咕咕)
{
label: 'QQ频道设置',
// 第二个分组标记开始
component: 'SOFT_GROUP_BEGIN'
},
{
field: 'prefix',
label: '前缀转换',
bottomHelpMessage: '是否开启前缀“/”转换为“#”',
component: 'Switch'
},
{
field: 'prefixBlack',
label: '前缀转换黑名单',
bottomHelpMessage: '在这里添加机器人的开发者id(appID)则不会转换该机器人的前缀',
component: 'Select',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: prefixBlack
}
},
{
field: 'forwar',
label: '分片转发',
bottomHelpMessage: '是否使用分片发送转发消息',
component: 'Switch'
},
{
field: 'recallQR',
label: '二维码撤回时间',
bottomHelpMessage: 'url转换成二维码后的撤回时间 0表示不撤回',
component: 'Input',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入纯数字',
min: 1,
max: 120
}
},
{
field: 'ImageSize',
label: '图片压缩阈值',
bottomHelpMessage: '超过此大小的图片发送前会进行压缩',
component: 'Input',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入纯数字',
min: 1,
max: 5
}
},
{
field: 'width',
label: '压缩图片-宽度',
bottomHelpMessage: '压缩后的图片宽度像素大小',
component: 'Input',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入压缩后的图片宽度像素大小',
min: 1,
max: 3000
}
},
{
field: 'quality',
label: '压缩图片-质量',
bottomHelpMessage: '压缩后的图片质量',
component: 'Input',
required: true,
componentProps: {
type: 'number',
placeholder: '请输入压缩后的图片质量',
min: 1,
max: 100
}
},
{
field: 'whitelist_Url',
label: '白名单url',
bottomHelpMessage: 'url白名单,在白名单中的链接不会转为二维码',
component: 'GTags',
componentProps: {
placeholder: '请输入链接',
allowAdd: true,
allowDel: true,
showPrompt: true,
promptProps: addUrlPromptProps,
valueFormatter: ((value) => String(value)).toString()
}
},
{
field: 'whitelist',
label: '白名单频道',
bottomHelpMessage: '配置此项后,只有在配置中的频道能响应消息',
component: 'Select',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: guilds
}
},
{
field: 'blacklist',
label: '黑名单频道',
bottomHelpMessage: '顾名思义',
component: 'Select',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: guilds
}
},
{
field: 'channel_whitelist',
label: '白名单子频道',
bottomHelpMessage: '配置此项后,只有在配置中的子频道能响应消息',
component: 'Select',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: channels
}
},
{
field: 'channel_blacklist',
label: '黑名单子频道',
bottomHelpMessage: '顾名思义',
component: 'Select',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: channels
}
},
*/