@karinjs/adapter-qqbot 1.2.10 → 1.3.1
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/README.md +869 -84
- package/dist/chunk-PYOUSZ6B.js +1501 -0
- package/dist/index.d.ts +499 -0
- package/dist/index.js +100 -0
- package/dist/web.config.d.ts +25 -0
- package/dist/web.config.js +224 -0
- package/package.json +22 -15
- package/config/comment/config.json +0 -3
- package/config/config/config.yaml +0 -53
- package/lib/cli/pr.d.ts +0 -2
- package/lib/cli/pr.js +0 -73
- package/lib/core/adapter/adapter.d.ts +0 -91
- package/lib/core/adapter/adapter.js +0 -144
- package/lib/core/adapter/handler.d.ts +0 -49
- package/lib/core/adapter/handler.js +0 -140
- package/lib/core/adapter/markdown.d.ts +0 -38
- package/lib/core/adapter/markdown.js +0 -220
- package/lib/core/adapter/normal.d.ts +0 -30
- package/lib/core/adapter/normal.js +0 -263
- package/lib/core/api/index.d.ts +0 -167
- package/lib/core/api/index.js +0 -180
- package/lib/core/api/sign.d.ts +0 -22
- package/lib/core/api/sign.js +0 -40
- package/lib/core/api/types.d.ts +0 -236
- package/lib/core/api/types.js +0 -1
- package/lib/core/event/conver.d.ts +0 -10
- package/lib/core/event/conver.js +0 -57
- package/lib/core/event/index.d.ts +0 -9
- package/lib/core/event/index.js +0 -98
- package/lib/core/event/message.d.ts +0 -27
- package/lib/core/event/message.js +0 -95
- package/lib/core/event/notice.d.ts +0 -50
- package/lib/core/event/notice.js +0 -133
- package/lib/core/event/types.d.ts +0 -473
- package/lib/core/event/types.js +0 -1
- package/lib/core/internal/axios.d.ts +0 -25
- package/lib/core/internal/axios.js +0 -46
- package/lib/core/internal/sign.d.ts +0 -22
- package/lib/core/internal/sign.js +0 -40
- package/lib/core/webhook/c2c.d.ts +0 -2
- package/lib/core/webhook/c2c.js +0 -14
- package/lib/core/webhook/http.d.ts +0 -2
- package/lib/core/webhook/http.js +0 -35
- package/lib/core/webhook/index.d.ts +0 -17
- package/lib/core/webhook/index.js +0 -87
- package/lib/core/webhook/ws.d.ts +0 -2
- package/lib/core/webhook/ws.js +0 -79
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -5
- package/lib/root.d.ts +0 -5
- package/lib/root.js +0 -9
- package/lib/types/config.d.ts +0 -53
- package/lib/types/config.js +0 -1
- package/lib/utils/common.d.ts +0 -80
- package/lib/utils/common.js +0 -198
- package/lib/utils/config.d.ts +0 -9
- package/lib/utils/config.js +0 -54
- package/lib/utils/dir.d.ts +0 -1
- package/lib/utils/dir.js +0 -1
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +0 -4
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Contact, SendMsgResults } from 'node-karin';
|
|
2
|
-
import type { QQSend, Grouping, Options, GuildSend } from '@/core/adapter/adapter';
|
|
3
|
-
import { AdapterQQBotMarkdown } from '@/core/adapter/markdown';
|
|
4
|
-
export interface RawMarkdown {
|
|
5
|
-
/**
|
|
6
|
-
* 频道场景原生Markdown
|
|
7
|
-
* @param type 场景类型
|
|
8
|
-
* @param ctx 适配器实例
|
|
9
|
-
* @param list 分类列表
|
|
10
|
-
* @param contact 发送目标
|
|
11
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
12
|
-
* @param send 发送消息函数
|
|
13
|
-
*/
|
|
14
|
-
(type: 'guild', ctx: AdapterQQBotMarkdown, list: Grouping<'guild'>, contact: Contact<'guild' | 'direct'>, pasmsg: (item: Options<'guild'>) => void, send: GuildSend): Promise<SendMsgResults>;
|
|
15
|
-
/**
|
|
16
|
-
* QQ场景原生Markdown
|
|
17
|
-
* @param type 场景类型
|
|
18
|
-
* @param ctx 适配器实例
|
|
19
|
-
* @param list 分类列表
|
|
20
|
-
* @param contact 发送目标
|
|
21
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
22
|
-
* @param send 发送消息函数
|
|
23
|
-
*/
|
|
24
|
-
(type: 'qq', ctx: AdapterQQBotMarkdown, list: Grouping<'qq'>, contact: Contact<'friend' | 'group'>, pasmsg: (item: Options<'qq'>) => void, send: QQSend): Promise<SendMsgResults>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 原生Markdown
|
|
28
|
-
* @param ctx 适配器实例
|
|
29
|
-
* @param list 分类列表
|
|
30
|
-
* @param contact 发送目标
|
|
31
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
32
|
-
* @param send 发送函数
|
|
33
|
-
*/
|
|
34
|
-
export declare const rawMarkdown: RawMarkdown;
|
|
35
|
-
/**
|
|
36
|
-
* 图文模板
|
|
37
|
-
* @param ctx 适配器实例
|
|
38
|
-
* @param list 分类列表
|
|
39
|
-
* @param contact 发送目标
|
|
40
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
41
|
-
* @param send 发送函数
|
|
42
|
-
*/
|
|
43
|
-
export declare const GraphicTemplateMarkdown: RawMarkdown;
|
|
44
|
-
/**
|
|
45
|
-
* 纯文模板
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* 自定义处理
|
|
49
|
-
*/
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { escapeMarkdown, getImageSize } from '@/utils/common';
|
|
2
|
-
import { common, fileToUrl, segment } from 'node-karin';
|
|
3
|
-
/**
|
|
4
|
-
* 原生Markdown
|
|
5
|
-
* @param ctx 适配器实例
|
|
6
|
-
* @param list 分类列表
|
|
7
|
-
* @param contact 发送目标
|
|
8
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
9
|
-
* @param send 发送函数
|
|
10
|
-
*/
|
|
11
|
-
export const rawMarkdown = async (type, ctx, list, contact, pasmsg, send) => {
|
|
12
|
-
await Promise.all(list.image.map(async (file) => {
|
|
13
|
-
if (file.startsWith('http')) {
|
|
14
|
-
const { width, height } = await getImageSize(file);
|
|
15
|
-
list.content.push(``);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const { url, width, height } = await fileToUrl('image', file, 'image.jpg');
|
|
19
|
-
list.content.push(``);
|
|
20
|
-
}));
|
|
21
|
-
/** 将文本转为markdown */
|
|
22
|
-
list.markdown.push(segment.markdown(list.content.join('')));
|
|
23
|
-
/** 处理Markdown、按钮 */
|
|
24
|
-
list.markdownToButton(type, list);
|
|
25
|
-
/** 返回值 */
|
|
26
|
-
const rawData = ctx.initSendMsgResults();
|
|
27
|
-
if (type === 'qq') {
|
|
28
|
-
if (!list.list.length) {
|
|
29
|
-
const options = ctx.super.QQdMsgOptions('text', '不支持发送的消息类型');
|
|
30
|
-
list.list.push(options);
|
|
31
|
-
}
|
|
32
|
-
for (const item of list.list) {
|
|
33
|
-
pasmsg(item);
|
|
34
|
-
const res = await send(contact.peer, item);
|
|
35
|
-
rawData.rawData.push(res);
|
|
36
|
-
}
|
|
37
|
-
return ctx.handleResponse(rawData);
|
|
38
|
-
}
|
|
39
|
-
if (!list.list.length) {
|
|
40
|
-
const options = ctx.super.GuildMsgOptions('text', '不支持发送的消息类型');
|
|
41
|
-
list.list.push(options);
|
|
42
|
-
}
|
|
43
|
-
for (const item of list.list) {
|
|
44
|
-
pasmsg(item);
|
|
45
|
-
const res = await send(contact.peer, contact.subPeer, item);
|
|
46
|
-
rawData.rawData.push(res);
|
|
47
|
-
}
|
|
48
|
-
return ctx.handleResponse(rawData);
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* 图文模板
|
|
52
|
-
* @param ctx 适配器实例
|
|
53
|
-
* @param list 分类列表
|
|
54
|
-
* @param contact 发送目标
|
|
55
|
-
* @param pasmsg 将消息转为被动消息 主动事件无法使用
|
|
56
|
-
* @param send 发送函数
|
|
57
|
-
*/
|
|
58
|
-
export const GraphicTemplateMarkdown = async (type, ctx, list, contact, pasmsg, send) => {
|
|
59
|
-
/**
|
|
60
|
-
* 构建模板键值对
|
|
61
|
-
* @param index 索引
|
|
62
|
-
* @param value 值
|
|
63
|
-
*/
|
|
64
|
-
const KV = (index, value) => {
|
|
65
|
-
return { key: kv[index], values: [value] };
|
|
66
|
-
};
|
|
67
|
-
/** 构建模板 */
|
|
68
|
-
const tpl = (content, desc, url) => {
|
|
69
|
-
if (desc && url) {
|
|
70
|
-
return segment.markdownTpl(id, [KV(0, content), KV(1, desc), KV(2, url)]);
|
|
71
|
-
}
|
|
72
|
-
if (desc) {
|
|
73
|
-
return segment.markdownTpl(id, [KV(1, content), KV(2, desc)]);
|
|
74
|
-
}
|
|
75
|
-
return segment.markdownTpl(id, [KV(0, content)]);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* 图片转换
|
|
79
|
-
* @param file 图片文件
|
|
80
|
-
* @returns 图片链接 | 图片宽度 | 图片高度
|
|
81
|
-
*/
|
|
82
|
-
const imageHandler = async (file) => {
|
|
83
|
-
if (file.startsWith('http')) {
|
|
84
|
-
const { width, height } = await getImageSize(file);
|
|
85
|
-
return { url: file, width, height };
|
|
86
|
-
}
|
|
87
|
-
const data = await fileToUrl('image', file, 'image.jpg');
|
|
88
|
-
return data;
|
|
89
|
-
};
|
|
90
|
-
const { kv, id } = ctx._config.markdown;
|
|
91
|
-
/** 文本内容 */
|
|
92
|
-
const content = escapeMarkdown(list.content.join(''));
|
|
93
|
-
/** 处理第一张图片 一段文本可以跟一个图片 */
|
|
94
|
-
const img = list.image.shift();
|
|
95
|
-
if (img) {
|
|
96
|
-
const { url, width, height } = await imageHandler(img);
|
|
97
|
-
list.markdownTpl.push(tpl(content, `karin #${width}px #${height}px`, url));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
list.markdownTpl.push(tpl(content));
|
|
101
|
-
}
|
|
102
|
-
/** 处理剩下的图片 单独发送 */
|
|
103
|
-
await Promise.all(list.image.map(async (file, index) => {
|
|
104
|
-
await common.sleep(index * 100); // 简单的睡眠 防止乱序
|
|
105
|
-
const { url, width, height } = await imageHandler(file);
|
|
106
|
-
list.markdownTpl.push(tpl(`karin #${width}px #${height}px`, url));
|
|
107
|
-
}));
|
|
108
|
-
/** 处理Markdown、按钮 */
|
|
109
|
-
list.markdownToButton(type, list);
|
|
110
|
-
/** 返回值 */
|
|
111
|
-
const rawData = ctx.initSendMsgResults();
|
|
112
|
-
if (type === 'qq') {
|
|
113
|
-
if (!list.list.length) {
|
|
114
|
-
const options = ctx.super.QQdMsgOptions('text', '不支持发送的消息类型');
|
|
115
|
-
list.list.push(options);
|
|
116
|
-
}
|
|
117
|
-
for (const item of list.list) {
|
|
118
|
-
pasmsg(item);
|
|
119
|
-
const res = await send(contact.peer, item);
|
|
120
|
-
rawData.rawData.push(res);
|
|
121
|
-
}
|
|
122
|
-
return ctx.handleResponse(rawData);
|
|
123
|
-
}
|
|
124
|
-
if (!list.list.length) {
|
|
125
|
-
const options = ctx.super.GuildMsgOptions('text', '不支持发送的消息类型');
|
|
126
|
-
list.list.push(options);
|
|
127
|
-
}
|
|
128
|
-
for (const item of list.list) {
|
|
129
|
-
pasmsg(item);
|
|
130
|
-
const res = await send(contact.peer, contact.subPeer, item);
|
|
131
|
-
rawData.rawData.push(res);
|
|
132
|
-
}
|
|
133
|
-
return ctx.handleResponse(rawData);
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* 纯文模板
|
|
137
|
-
*/
|
|
138
|
-
/**
|
|
139
|
-
* 自定义处理
|
|
140
|
-
*/
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AdapterQQBot } from '@/core/adapter/adapter';
|
|
2
|
-
import type { QQBotApi } from '@/core/api';
|
|
3
|
-
import type { Contact, ElementTypes, Message, SendMsgResults } from 'node-karin';
|
|
4
|
-
import type { RawMarkdown } from '@/core/adapter/handler';
|
|
5
|
-
import type { Config } from '@/types/config';
|
|
6
|
-
type Cfg = Config[string];
|
|
7
|
-
/** markdown */
|
|
8
|
-
export declare class AdapterQQBotMarkdown extends AdapterQQBot {
|
|
9
|
-
_config: Cfg;
|
|
10
|
-
markdown: RawMarkdown;
|
|
11
|
-
constructor(QQBot: QQBotApi, markdown: RawMarkdown, config: Cfg);
|
|
12
|
-
srcReply(e: Message, elements: ElementTypes[]): Promise<SendMsgResults>;
|
|
13
|
-
sendMsg(contact: Contact, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
14
|
-
/**
|
|
15
|
-
* 处理文本 将文本中的链接转为二维码
|
|
16
|
-
* @param text 文本
|
|
17
|
-
* @returns 处理后的文本和二维码 二维码为不带`base64://`的字符串
|
|
18
|
-
*/
|
|
19
|
-
hendleText(text: string): Promise<{
|
|
20
|
-
text: string;
|
|
21
|
-
qr: string | null;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* 发送QQ私聊、群聊消息
|
|
25
|
-
* @param contact 联系人
|
|
26
|
-
* @param elements 消息元素
|
|
27
|
-
* @param retryCount 重试次数
|
|
28
|
-
*/
|
|
29
|
-
sendQQMsg(contact: Contact<'friend'> | Contact<'group'>, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
30
|
-
/**
|
|
31
|
-
* 发送频道消息
|
|
32
|
-
* @param contact 联系人
|
|
33
|
-
* @param elements 消息元素
|
|
34
|
-
* @param retryCount 重试次数
|
|
35
|
-
*/
|
|
36
|
-
sendGuildMsg(contact: Contact<'guild' | 'direct'>, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import FormData from 'form-data';
|
|
2
|
-
import { handleUrl, qrs, textToButton } from '@/utils/common';
|
|
3
|
-
import { common, fileToUrl, buttonHandle } from 'node-karin';
|
|
4
|
-
import { AdapterQQBot } from '@/core/adapter/adapter';
|
|
5
|
-
/** markdown */
|
|
6
|
-
export class AdapterQQBotMarkdown extends AdapterQQBot {
|
|
7
|
-
_config;
|
|
8
|
-
markdown;
|
|
9
|
-
constructor(QQBot, markdown, config) {
|
|
10
|
-
super(QQBot);
|
|
11
|
-
this.markdown = markdown;
|
|
12
|
-
this._config = config;
|
|
13
|
-
}
|
|
14
|
-
async srcReply(e, elements) {
|
|
15
|
-
const list = await buttonHandle(e.msg, { e });
|
|
16
|
-
return this.sendMsg(e.contact, [...elements, ...list]);
|
|
17
|
-
}
|
|
18
|
-
async sendMsg(contact, elements, retryCount) {
|
|
19
|
-
if (contact.scene === 'direct' || contact.scene === 'guild') {
|
|
20
|
-
return this.sendGuildMsg(contact, elements, retryCount);
|
|
21
|
-
}
|
|
22
|
-
else if (contact.scene === 'group' || contact.scene === 'friend') {
|
|
23
|
-
return this.sendQQMsg(contact, elements, retryCount);
|
|
24
|
-
}
|
|
25
|
-
throw new Error('不支持的消息类型');
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 处理文本 将文本中的链接转为二维码
|
|
29
|
-
* @param text 文本
|
|
30
|
-
* @returns 处理后的文本和二维码 二维码为不带`base64://`的字符串
|
|
31
|
-
*/
|
|
32
|
-
async hendleText(text) {
|
|
33
|
-
const urls = handleUrl(text);
|
|
34
|
-
if (!urls.length)
|
|
35
|
-
return { text, qr: null };
|
|
36
|
-
urls.forEach((url) => {
|
|
37
|
-
text = text.replace(new RegExp(url, 'g'), '[请扫码查看]');
|
|
38
|
-
});
|
|
39
|
-
const list = await qrs(urls);
|
|
40
|
-
if (list.length === 1)
|
|
41
|
-
return { text, qr: list[0] };
|
|
42
|
-
const result = await common.mergeImage(list, 3);
|
|
43
|
-
return { text, qr: result.base64 };
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 发送QQ私聊、群聊消息
|
|
47
|
-
* @param contact 联系人
|
|
48
|
-
* @param elements 消息元素
|
|
49
|
-
* @param retryCount 重试次数
|
|
50
|
-
*/
|
|
51
|
-
async sendQQMsg(contact, elements, retryCount) {
|
|
52
|
-
const list = this.initList('qq');
|
|
53
|
-
/** 上传富媒体的目标 */
|
|
54
|
-
const target = contact.scene === 'friend' ? 'user' : 'group';
|
|
55
|
-
for (const v of elements) {
|
|
56
|
-
if (v.type === 'text') {
|
|
57
|
-
const { text, buttons } = textToButton(v.text, contact.scene === 'friend');
|
|
58
|
-
list.content.push(text);
|
|
59
|
-
if (buttons)
|
|
60
|
-
list.button.push(...buttons);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (v.type === 'at') {
|
|
64
|
-
if (contact.scene === 'friend')
|
|
65
|
-
continue;
|
|
66
|
-
list.content.push(v.targetId === 'all' ? '<qqbot-at-everyone />' : `<qqbot-at-user id="${v.targetId}" />`);
|
|
67
|
-
}
|
|
68
|
-
if (v.type === 'image') {
|
|
69
|
-
list.image.push(v.file);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (v.type === 'pasmsg') {
|
|
73
|
-
if (v.source === 'event')
|
|
74
|
-
list.pasmsg.type = 'event';
|
|
75
|
-
list.pasmsg.msg_id = v.id;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (v.type === 'keyboard') {
|
|
79
|
-
list.keyboard.push(v);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (v.type === 'button') {
|
|
83
|
-
list.button.push(v);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (v.type === 'markdown') {
|
|
87
|
-
list.markdown.push(v);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (v.type === 'markdownTpl') {
|
|
91
|
-
list.markdownTpl.push(v);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (v.type === 'video' || v.type === 'record') {
|
|
95
|
-
let url;
|
|
96
|
-
if (v.file.startsWith('http')) {
|
|
97
|
-
url = v.file;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const data = await fileToUrl(v.type, v.file, `${v.type}.${v.type === 'record' ? 'mp3' : 'mp4'}`);
|
|
101
|
-
url = data.url;
|
|
102
|
-
}
|
|
103
|
-
const res = await this.super.uploadMedia(target, contact.peer, v.type, url, false);
|
|
104
|
-
list.list.push(this.super.QQdMsgOptions('media', res.file_info));
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
this.logger('debug', `[QQBot][${v.type}] 不支持发送的消息类型`);
|
|
108
|
-
}
|
|
109
|
-
/** 处理被动消息 */
|
|
110
|
-
const pasmsg = (() => {
|
|
111
|
-
if (!list.pasmsg.msg_id)
|
|
112
|
-
return () => '';
|
|
113
|
-
list.pasmsg.msg_seq++;
|
|
114
|
-
if (list.pasmsg.type === 'msg') {
|
|
115
|
-
return (item) => {
|
|
116
|
-
item.msg_seq = list.pasmsg.msg_seq;
|
|
117
|
-
item.msg_id = list.pasmsg.msg_id;
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return (item) => {
|
|
121
|
-
item.msg_seq = list.pasmsg.msg_seq;
|
|
122
|
-
item.event_id = list.pasmsg.msg_id;
|
|
123
|
-
};
|
|
124
|
-
})();
|
|
125
|
-
/** 发送消息 */
|
|
126
|
-
const send = (() => {
|
|
127
|
-
if (contact.scene === 'friend') {
|
|
128
|
-
return (peer, item) => this.super.sendFriendMsg(peer, item);
|
|
129
|
-
}
|
|
130
|
-
return (peer, item) => this.super.sendGroupMsg(peer, item);
|
|
131
|
-
})();
|
|
132
|
-
return this.markdown('qq', this, list, contact, pasmsg, send);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 发送频道消息
|
|
136
|
-
* @param contact 联系人
|
|
137
|
-
* @param elements 消息元素
|
|
138
|
-
* @param retryCount 重试次数
|
|
139
|
-
*/
|
|
140
|
-
async sendGuildMsg(contact, elements, retryCount) {
|
|
141
|
-
const list = this.initList('guild');
|
|
142
|
-
for (const v of elements) {
|
|
143
|
-
if (v.type === 'text') {
|
|
144
|
-
const { text, buttons } = textToButton(v.text, contact.scene === 'direct');
|
|
145
|
-
list.content.push(text);
|
|
146
|
-
if (buttons)
|
|
147
|
-
list.button.push(...buttons);
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (v.type === 'image') {
|
|
151
|
-
list.image.push(v.file);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (v.type === 'at') {
|
|
155
|
-
if (contact.scene === 'guild') {
|
|
156
|
-
list.content.push(v.targetId === 'all' ? '<qqbot-at-everyone />' : `<qqbot-at-user id="${v.targetId}" />`);
|
|
157
|
-
}
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (v.type === 'pasmsg') {
|
|
161
|
-
if (v.source === 'event')
|
|
162
|
-
list.pasmsg.type = 'event';
|
|
163
|
-
list.pasmsg.msg_id = v.id;
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (v.type === 'reply') {
|
|
167
|
-
list.reply.message_id = v.messageId;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (v.type === 'face') {
|
|
171
|
-
list.content.push(`<emoji:${v.id}>`);
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (v.type === 'keyboard') {
|
|
175
|
-
list.keyboard.push(v);
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (v.type === 'button') {
|
|
179
|
-
list.button.push(v);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (v.type === 'markdown') {
|
|
183
|
-
list.markdown.push(v);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (v.type === 'markdownTpl') {
|
|
187
|
-
list.markdownTpl.push(v);
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
this.logger('debug', `[QQBot][${v.type}] 不支持发送的消息类型`);
|
|
191
|
-
}
|
|
192
|
-
/** 发送消息 */
|
|
193
|
-
const send = (() => {
|
|
194
|
-
if (contact.scene === 'guild') {
|
|
195
|
-
return (peer, subPeer, item) => this.super.sendChannelMsg(subPeer, item);
|
|
196
|
-
}
|
|
197
|
-
return (peer, subPeer, item) => this.super.sendDmsMsg(peer, item);
|
|
198
|
-
})();
|
|
199
|
-
/** 处理被动消息 */
|
|
200
|
-
const pasmsg = (() => {
|
|
201
|
-
if (!list.pasmsg.msg_id)
|
|
202
|
-
return () => '';
|
|
203
|
-
if (list.pasmsg.type === 'msg') {
|
|
204
|
-
return (item) => {
|
|
205
|
-
if (item instanceof FormData) {
|
|
206
|
-
return item.append('msg_id', list.pasmsg.msg_id);
|
|
207
|
-
}
|
|
208
|
-
item.msg_id = list.pasmsg.msg_id;
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
return (item) => {
|
|
212
|
-
if (item instanceof FormData) {
|
|
213
|
-
return item.append('event_id', list.pasmsg.msg_id);
|
|
214
|
-
}
|
|
215
|
-
item.event_id = list.pasmsg.msg_id;
|
|
216
|
-
};
|
|
217
|
-
})();
|
|
218
|
-
return this.markdown('guild', this, list, contact, pasmsg, send);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { AdapterQQBot } from '@/core/adapter/adapter';
|
|
2
|
-
import type { Contact, ElementTypes, Message, SendMsgResults } from 'node-karin';
|
|
3
|
-
/** 正常发送消息 */
|
|
4
|
-
export declare class AdapterQQBotNormal extends AdapterQQBot {
|
|
5
|
-
srcReply(e: Message, elements: ElementTypes[]): Promise<SendMsgResults>;
|
|
6
|
-
sendMsg(contact: Contact, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
7
|
-
/**
|
|
8
|
-
* 处理文本 将文本中的链接转为二维码
|
|
9
|
-
* @param text 文本
|
|
10
|
-
* @returns 处理后的文本和二维码 二维码为不带`base64://`的字符串
|
|
11
|
-
*/
|
|
12
|
-
hendleText(text: string): Promise<{
|
|
13
|
-
text: string;
|
|
14
|
-
qr: string | null;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* 发送QQ私聊、群聊消息
|
|
18
|
-
* @param contact 联系人
|
|
19
|
-
* @param elements 消息元素
|
|
20
|
-
* @param retryCount 重试次数
|
|
21
|
-
*/
|
|
22
|
-
sendQQMsg(contact: Contact<'friend'> | Contact<'group'>, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
23
|
-
/**
|
|
24
|
-
* 发送频道消息
|
|
25
|
-
* @param contact 联系人
|
|
26
|
-
* @param elements 消息元素
|
|
27
|
-
* @param retryCount 重试次数
|
|
28
|
-
*/
|
|
29
|
-
sendGuildMsg(contact: Contact<'guild' | 'direct'>, elements: Array<ElementTypes>, retryCount?: number): Promise<SendMsgResults>;
|
|
30
|
-
}
|