@karinjs/adapter-qqbot 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +7 -6
- package/lib/core/markdown.js +17 -3
- package/lib/utils/common.d.ts +7 -0
- package/lib/utils/common.js +12 -0
- package/lib/utils/config.d.ts +1 -1
- package/lib/utils/config.js +14 -14
- package/package.json +1 -1
package/lib/core/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class AdapterQQBot implements KarinAdapter {
|
|
|
37
37
|
message_id: string;
|
|
38
38
|
}>;
|
|
39
39
|
getAvatarUrl(user_id: string, size?: number): string;
|
|
40
|
-
|
|
40
|
+
getGroupAvatarUrl(): string;
|
|
41
41
|
GetCurrentAccount(): Promise<{
|
|
42
42
|
account_uid: string;
|
|
43
43
|
account_uin: string;
|
package/lib/core/index.js
CHANGED
|
@@ -163,11 +163,12 @@ export class AdapterQQBot {
|
|
|
163
163
|
elements.push(segment.face(Number(Match[1])));
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
166
|
-
const
|
|
167
|
-
for (const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
const { regex } = Config.getBotConfig(this.account.uid) || { regex: [] };
|
|
167
|
+
for (const r of regex) {
|
|
168
|
+
const reg = r.reg;
|
|
169
|
+
if (typeof reg !== 'string')
|
|
170
|
+
continue;
|
|
171
|
+
v = v.replace(reg, r.rep);
|
|
171
172
|
}
|
|
172
173
|
elements.push(segment.text(v));
|
|
173
174
|
}
|
|
@@ -274,7 +275,7 @@ export class AdapterQQBot {
|
|
|
274
275
|
return this.super.avatar;
|
|
275
276
|
return `https://q.qlogo.cn/qqapp/${this.account.uid}/${user_id}/${size}`;
|
|
276
277
|
}
|
|
277
|
-
|
|
278
|
+
getGroupAvatarUrl() {
|
|
278
279
|
return 'https://p.qlogo.cn/gh/967068507/967068507/0';
|
|
279
280
|
}
|
|
280
281
|
async GetCurrentAccount() {
|
package/lib/core/markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { common, common as Common } from '../utils/common.js';
|
|
3
|
-
import { handler, common as karinCommon, } from 'node-karin';
|
|
3
|
+
import { handler, common as karinCommon, segment, } from 'node-karin';
|
|
4
4
|
/**
|
|
5
5
|
* 图文模板
|
|
6
6
|
*/
|
|
@@ -26,8 +26,9 @@ export async function markdownTemplate(Opt) {
|
|
|
26
26
|
const textFn = async () => {
|
|
27
27
|
text.sort((a, b) => a.index - b.index);
|
|
28
28
|
const data = Common.getQQBotButton(text.map(v => v.data.text).join(''));
|
|
29
|
+
const val = type === "users" /* PathType.Friends */ ? Common.formatText(data.text, true) : Common.formatText(data.text);
|
|
29
30
|
/** 去除at全体 */
|
|
30
|
-
params.push({ key: bot.markdown.oldTemplate.textStartKey, values: [
|
|
31
|
+
params.push({ key: bot.markdown.oldTemplate.textStartKey, values: [val] });
|
|
31
32
|
/** 按钮 */
|
|
32
33
|
buttons.push(...data.data);
|
|
33
34
|
};
|
|
@@ -50,6 +51,12 @@ export async function markdownTemplate(Opt) {
|
|
|
50
51
|
case 'image':
|
|
51
52
|
image.push({ index, data });
|
|
52
53
|
break;
|
|
54
|
+
case 'at': {
|
|
55
|
+
if (type === "users" /* PathType.Friends */)
|
|
56
|
+
break;
|
|
57
|
+
text.push({ index, data: segment.text(`<qqbot-at-user id="${data.uid || data.uin}" />`) });
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
53
60
|
case 'record': {
|
|
54
61
|
const file = await common.voiceToSilk(data.file);
|
|
55
62
|
list.push(mediaFn(file, type, '0.silk', 3 /* FileType.Record */));
|
|
@@ -176,12 +183,19 @@ export async function markdownRaw(Opt) {
|
|
|
176
183
|
/** 先提取掉url 随后放出按钮中 */
|
|
177
184
|
const res = Common.getQQBotButton(data.text);
|
|
178
185
|
buttons.push(...res.data);
|
|
179
|
-
|
|
186
|
+
const text = type === "users" /* PathType.Friends */ ? Common.formatText(res.text, true) : Common.formatText(res.text);
|
|
187
|
+
message.push({ index, data: text });
|
|
180
188
|
break;
|
|
181
189
|
}
|
|
182
190
|
case 'image':
|
|
183
191
|
imageFn(index, data);
|
|
184
192
|
break;
|
|
193
|
+
case 'at': {
|
|
194
|
+
if (type === "users" /* PathType.Friends */)
|
|
195
|
+
break;
|
|
196
|
+
message.push({ index, data: `<qqbot-at-user id="${data.uid || data.uin}" />` });
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
185
199
|
case 'record': {
|
|
186
200
|
const file = await common.voiceToSilk(data.file);
|
|
187
201
|
list.push(mediaFn(file, type, '0.silk', 3 /* FileType.Record */));
|
package/lib/utils/common.d.ts
CHANGED
|
@@ -54,6 +54,13 @@ declare class Common {
|
|
|
54
54
|
text: string;
|
|
55
55
|
data: ButtonElement[];
|
|
56
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* 传入文本 将文本一些特殊字符转义去除 用于处理markdown
|
|
59
|
+
* @param text - 文本
|
|
60
|
+
* @param isC2C - 是否是C2C
|
|
61
|
+
* @returns 处理后的文本
|
|
62
|
+
*/
|
|
63
|
+
formatText(text: string, isC2C?: boolean): string;
|
|
57
64
|
}
|
|
58
65
|
export declare const common: Common;
|
|
59
66
|
export {};
|
package/lib/utils/common.js
CHANGED
|
@@ -194,5 +194,17 @@ class Common {
|
|
|
194
194
|
data,
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* 传入文本 将文本一些特殊字符转义去除 用于处理markdown
|
|
199
|
+
* @param text - 文本
|
|
200
|
+
* @param isC2C - 是否是C2C
|
|
201
|
+
* @returns 处理后的文本
|
|
202
|
+
*/
|
|
203
|
+
formatText(text, isC2C = false) {
|
|
204
|
+
text = text.replace(/everyone/g, '').replace(/\n/g, '\r');
|
|
205
|
+
if (isC2C)
|
|
206
|
+
text = text.replace(/<qqbot-at-user id=".+" \/>/gm, '').replace(/<@.+>/gm, '');
|
|
207
|
+
return text;
|
|
208
|
+
}
|
|
197
209
|
}
|
|
198
210
|
export const common = new Common();
|
package/lib/utils/config.d.ts
CHANGED
package/lib/utils/config.js
CHANGED
|
@@ -107,12 +107,24 @@ class Cfg {
|
|
|
107
107
|
const botCfg = allCfg.accounts[appID];
|
|
108
108
|
/** 全局默认配置 */
|
|
109
109
|
const defCfg = allCfg.default;
|
|
110
|
-
|
|
110
|
+
/** 对regex进行处理 */
|
|
111
|
+
const regex = Array.isArray(botCfg.regex) ? botCfg.regex : defCfg.regex;
|
|
112
|
+
/** 对表达式进行new RegExp处理 */
|
|
113
|
+
const regexData = regex.map(({ reg, rep }) => {
|
|
114
|
+
return {
|
|
115
|
+
reg: reg instanceof RegExp ? reg : new RegExp(reg),
|
|
116
|
+
rep,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
const data = {
|
|
111
120
|
...defCfg,
|
|
112
121
|
...botCfg,
|
|
113
122
|
sendMode: Number(botCfg.sendMode) || defCfg.sendMode,
|
|
114
|
-
regex:
|
|
123
|
+
regex: regexData,
|
|
115
124
|
};
|
|
125
|
+
/** 缓存 */
|
|
126
|
+
this.change.set(key, data);
|
|
127
|
+
return data;
|
|
116
128
|
}
|
|
117
129
|
/**
|
|
118
130
|
* package
|
|
@@ -153,18 +165,6 @@ class Cfg {
|
|
|
153
165
|
watcher.on('change', () => {
|
|
154
166
|
this.change.delete(key);
|
|
155
167
|
logger.mark(`[修改配置文件][${type}][${name}]`);
|
|
156
|
-
/** 文件修改后调用对应的方法 请自行使用 */
|
|
157
|
-
// switch (`change_${name}`) {
|
|
158
|
-
// case 'change_App':
|
|
159
|
-
// this.change_App()
|
|
160
|
-
// break
|
|
161
|
-
// case 'change_config':
|
|
162
|
-
// this.change_config()
|
|
163
|
-
// break
|
|
164
|
-
// case 'change_group':
|
|
165
|
-
// this.change_group()
|
|
166
|
-
// break
|
|
167
|
-
// }
|
|
168
168
|
});
|
|
169
169
|
/** 缓存 防止重复监听 */
|
|
170
170
|
this.watcher.set(key, watcher);
|