-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathguoba.support.js
367 lines (360 loc) · 14.3 KB
/
guoba.support.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
import fs from "fs"
import Yaml from "yaml"
import yaml from "./model/yaml.js"
import common from "../../lib/common/common.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 common.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: "Lian-plugin",
author: "@Lain.",
authorLink: "https://gitee.com/Zyy955",
link: "https://gitee.com/Zyy955/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: [
{
component: "Divider",
label: "PC微信设置"
},
{
field: "port",
label: "端口",
bottomHelpMessage: "请输入HTTP服务器端口(Shamrock共用)",
component: "InputNumber",
required: true,
componentProps: {
type: "number",
placeholder: "请输入HTTP服务器端口(Shamrock共用)",
min: 1,
max: 65535,
},
},
{
field: "autoFriend",
label: "自动同意加好友",
component: "RadioGroup",
bottomHelpMessage: "是否自动同意加好友",
componentProps: {
options: [
{ label: "不处理", value: 0 },
{ label: "自动同意", value: 1 }
]
}
},
{
field: "name",
label: "椰奶状态名称",
bottomHelpMessage: "自定义椰奶状态名称",
component: "Input",
required: true,
componentProps: {
placeholder: "请输入自定义椰奶状态名称",
},
},
{
component: "Divider",
label: "QQ频道设置"
},
{
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: "isLog",
label: "黑白名单日志",
bottomHelpMessage: "关闭后未通过黑白名单的日志将会转为debug日志",
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
}
},
{
component: "Divider",
label: "Shamrock设置"
},
{
field: "baseUrl",
label: "主动http端口",
bottomHelpMessage: "Shamrock主动http端口,例如http://localhost:5700。若填写将通过此端口进行文件上传等被动ws不支持的操作。未开启端口不要填写",
component: "Input",
required: false,
componentProps: {
placeholder: "请输入shamrock主动http端口",
},
},
{
field: "token",
label: "鉴权token",
bottomHelpMessage: "Shamrock鉴权token,如果开放公网强烈建议配置",
component: "InputPassword",
required: false,
componentProps: {
placeholder: "请输入shamrock鉴权token",
},
},
{
component: "Divider",
label: "标准输入设置"
},
{
field: "stdin_nickname",
label: "标准输入昵称",
bottomHelpMessage: "自定义标准输入的椰奶状态名称",
component: "Input",
required: true,
componentProps: {
placeholder: "请输入自定义标准输入昵称",
},
},
],
// 获取配置数据方法(用于前端填充显示数据)
getConfigData() {
return Bot.lain.cfg
},
// 设置配置的方法(前端点确定后调用的方法)
setConfigData(data, { Result }) {
const _path = Bot.lain._path + "/config.yaml"
let cfg = Yaml.parseDocument(fs.readFileSync(_path, "utf8"))
for (const key in data) {
let value = data[key]
switch (key) {
case "port":
cfg.setIn([key], Number(value))
break
case "path":
cfg.setIn([key], String(value))
break
case "autoFriend":
cfg.setIn([key], Number(value))
break
case "name":
cfg.setIn([key], String(value))
break
case "prefix":
cfg.setIn([key], Boolean(value))
break
case "forwar":
cfg.setIn([key], Boolean(value))
break
case "isLog":
cfg.setIn([key], Boolean(value))
break
case "ImageSize":
cfg.setIn([key], Number(value))
break
case "width":
cfg.setIn([key], Number(value))
break
case "quality":
cfg.setIn([key], Number(value))
break
case "recallQR":
cfg.setIn([key], Number(value))
break
case "stdin_nickname":
cfg.setIn([key], String(value))
Bot.lain.cfg.stdin_nickname = String(value)
break
default:
if (!value) break
if (!Array.isArray(value)) value = [value]
cfg.setIn([key], value)
break
}
}
fs.writeFileSync(_path, cfg.toString(), "utf8")
return Result.ok({}, "保存成功~")
},
},
}
}