@karinjs/adapter-qqbot 1.2.10 → 2.0.0

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.
Files changed (65) hide show
  1. package/README.md +326 -85
  2. package/dist/apps/login.d.ts +20 -0
  3. package/dist/apps/login.js +57 -0
  4. package/dist/config-H7LrvlNU.js +197 -0
  5. package/dist/index.d.ts +670 -0
  6. package/dist/index.js +2847 -0
  7. package/dist/onboard-BX8g8Wik.js +249 -0
  8. package/dist/utils-DO4gEkVN.js +3 -0
  9. package/dist/web.config.d.ts +22 -0
  10. package/dist/web.config.js +173 -0
  11. package/package.json +34 -21
  12. package/config/comment/config.json +0 -3
  13. package/config/config/config.yaml +0 -53
  14. package/lib/cli/pr.d.ts +0 -2
  15. package/lib/cli/pr.js +0 -73
  16. package/lib/core/adapter/adapter.d.ts +0 -91
  17. package/lib/core/adapter/adapter.js +0 -144
  18. package/lib/core/adapter/handler.d.ts +0 -49
  19. package/lib/core/adapter/handler.js +0 -140
  20. package/lib/core/adapter/markdown.d.ts +0 -38
  21. package/lib/core/adapter/markdown.js +0 -220
  22. package/lib/core/adapter/normal.d.ts +0 -30
  23. package/lib/core/adapter/normal.js +0 -263
  24. package/lib/core/api/index.d.ts +0 -167
  25. package/lib/core/api/index.js +0 -180
  26. package/lib/core/api/sign.d.ts +0 -22
  27. package/lib/core/api/sign.js +0 -40
  28. package/lib/core/api/types.d.ts +0 -236
  29. package/lib/core/api/types.js +0 -1
  30. package/lib/core/event/conver.d.ts +0 -10
  31. package/lib/core/event/conver.js +0 -57
  32. package/lib/core/event/index.d.ts +0 -9
  33. package/lib/core/event/index.js +0 -98
  34. package/lib/core/event/message.d.ts +0 -27
  35. package/lib/core/event/message.js +0 -95
  36. package/lib/core/event/notice.d.ts +0 -50
  37. package/lib/core/event/notice.js +0 -133
  38. package/lib/core/event/types.d.ts +0 -473
  39. package/lib/core/event/types.js +0 -1
  40. package/lib/core/internal/axios.d.ts +0 -25
  41. package/lib/core/internal/axios.js +0 -46
  42. package/lib/core/internal/sign.d.ts +0 -22
  43. package/lib/core/internal/sign.js +0 -40
  44. package/lib/core/webhook/c2c.d.ts +0 -2
  45. package/lib/core/webhook/c2c.js +0 -14
  46. package/lib/core/webhook/http.d.ts +0 -2
  47. package/lib/core/webhook/http.js +0 -35
  48. package/lib/core/webhook/index.d.ts +0 -17
  49. package/lib/core/webhook/index.js +0 -87
  50. package/lib/core/webhook/ws.d.ts +0 -2
  51. package/lib/core/webhook/ws.js +0 -79
  52. package/lib/index.d.ts +0 -1
  53. package/lib/index.js +0 -5
  54. package/lib/root.d.ts +0 -5
  55. package/lib/root.js +0 -9
  56. package/lib/types/config.d.ts +0 -53
  57. package/lib/types/config.js +0 -1
  58. package/lib/utils/common.d.ts +0 -80
  59. package/lib/utils/common.js +0 -198
  60. package/lib/utils/config.d.ts +0 -9
  61. package/lib/utils/config.js +0 -54
  62. package/lib/utils/dir.d.ts +0 -1
  63. package/lib/utils/dir.js +0 -1
  64. package/lib/utils/index.d.ts +0 -4
  65. package/lib/utils/index.js +0 -4
@@ -1,91 +0,0 @@
1
- import FormData from 'form-data';
2
- import { QQBotApi } from '@/core/api';
3
- import { AdapterBase } from 'node-karin';
4
- import type { SendGuildMsg, SendGuildResponse, SendQQMsg, SendQQMsgResponse } from '@/core/api/types';
5
- import type { LoggerLevel, ButtonElement, KeyboardElement, MarkdownElement, MarkdownTplElement, SendMsgResults, Contact } from 'node-karin';
6
- /** 发送函数所需参数 */
7
- export type Options<T extends 'qq' | 'guild'> = T extends 'qq' ? SendQQMsg : SendGuildMsg | FormData;
8
- /** QQ发送消息函数类型 */
9
- export type QQSend = (peer: string, item: SendQQMsg) => Promise<SendQQMsgResponse>;
10
- /** 频道发送消息函数类型 */
11
- export type GuildSend = (peer: string, subPeer: string, item: SendGuildMsg | FormData) => Promise<SendGuildResponse>;
12
- export type Pasmsg<T extends 'qq' | 'guild'> = {
13
- type: 'msg' | 'event';
14
- msg_id: string;
15
- msg_seq: T extends 'qq' ? number : never;
16
- };
17
- export interface Grouping<T extends 'qq' | 'guild'> {
18
- /** 文本 */
19
- content: string[];
20
- /** 图片 QQ专属 */
21
- image: string[];
22
- /** 单行按钮 */
23
- button: ButtonElement[];
24
- /** 多行按钮 */
25
- keyboard: KeyboardElement[];
26
- /** markdown */
27
- markdown: MarkdownElement[];
28
- /** markdown模板 */
29
- markdownTpl: MarkdownTplElement[];
30
- /** 频道专属 图片url */
31
- imageUrls: string[];
32
- /** 频道专属 图片file */
33
- imageFiles: string[];
34
- /** 引用回复 频道专属 */
35
- reply: {
36
- message_id: string;
37
- };
38
- /** pasmsg */
39
- pasmsg: Pasmsg<T>;
40
- /** 代发送列表 */
41
- list: Array<Options<T>>;
42
- /**
43
- * 处理按钮、markdown
44
- * 统一格式后推入待发送消息列表
45
- * @param type 构建类型
46
- * @param list 分类列表
47
- * @returns
48
- */
49
- markdownToButton: (type: T, list: Grouping<T>) => void;
50
- }
51
- export declare abstract class AdapterQQBot extends AdapterBase {
52
- super: QQBotApi;
53
- constructor(QQBot: QQBotApi);
54
- logger(level: LoggerLevel, ...args: any[]): void;
55
- /**
56
- * 被动消息结构
57
- * @param type 消息类型
58
- */
59
- pasmsg<T extends 'qq' | 'guild'>(type: T): Pasmsg<T>;
60
- /**
61
- * 撤回消息
62
- * @param contact 联系人
63
- * @param messageId 消息id
64
- * @returns 撤回结果
65
- */
66
- recallMsg(contact: Contact, messageId: string): Promise<boolean>;
67
- /**
68
- * 初始化消息分类对象
69
- */
70
- initList<T extends 'qq' | 'guild'>(type: T): Grouping<T>;
71
- /**
72
- * 初始化发送消息返回值
73
- */
74
- initSendMsgResults(): SendMsgResults;
75
- /**
76
- * 处理返回值
77
- * @param data 返回值
78
- */
79
- handleResponse(data: SendMsgResults): SendMsgResults;
80
- /**
81
- * - 处理按钮、markdown
82
- * - 统一格式后推入待发送消息列表
83
- * @param type 消息类型
84
- * @param button 按钮
85
- * @param keyboard 键盘
86
- * @param markdown markdown
87
- * @param markdownTpl markdown模板
88
- * @returns 消息列表
89
- */
90
- markdownToButton<T extends 'qq' | 'guild'>(type: T, list: Grouping<T>): void;
91
- }
@@ -1,144 +0,0 @@
1
- import { random } from '@/utils/common';
2
- import { AdapterBase, logger, karinToQQBot } from 'node-karin';
3
- export class AdapterQQBot extends AdapterBase {
4
- super;
5
- constructor(QQBot) {
6
- super();
7
- this.super = QQBot;
8
- this.adapter.name = '@karinjs/qqbot';
9
- this.adapter.protocol = 'qqbot';
10
- this.adapter.platform = 'qq';
11
- this.adapter.standard = 'other';
12
- }
13
- logger(level, ...args) {
14
- logger.bot(level, this.selfId, ...args);
15
- }
16
- /**
17
- * 被动消息结构
18
- * @param type 消息类型
19
- */
20
- pasmsg(type) {
21
- if (type === 'qq') {
22
- return { type: 'msg', msg_id: '', msg_seq: random(1, 9999999) };
23
- }
24
- return { type: 'msg', msg_id: '' };
25
- }
26
- /**
27
- * 撤回消息
28
- * @param contact 联系人
29
- * @param messageId 消息id
30
- * @returns 撤回结果
31
- */
32
- async recallMsg(contact, messageId) {
33
- try {
34
- if (contact.scene === 'friend') {
35
- await this.super.recallMsg('user', contact.peer, messageId);
36
- return true;
37
- }
38
- if (contact.scene === 'group') {
39
- await this.super.recallMsg('group', contact.peer, messageId);
40
- return true;
41
- }
42
- if (contact.scene === 'direct') {
43
- await this.super.recallMsg('dms', contact.peer, messageId);
44
- return true;
45
- }
46
- if (contact.scene === 'guild') {
47
- await this.super.recallMsg('channels', contact.peer, messageId);
48
- return true;
49
- }
50
- return true;
51
- }
52
- catch {
53
- return false;
54
- }
55
- }
56
- /**
57
- * 初始化消息分类对象
58
- */
59
- initList(type) {
60
- const list = {
61
- content: [],
62
- image: [],
63
- button: [],
64
- keyboard: [],
65
- markdown: [],
66
- markdownTpl: [],
67
- imageUrls: [],
68
- imageFiles: [],
69
- reply: { message_id: '' },
70
- pasmsg: this.pasmsg(type),
71
- list: [],
72
- markdownToButton: (type, list) => this.markdownToButton(type, list)
73
- };
74
- return list;
75
- }
76
- /**
77
- * 初始化发送消息返回值
78
- */
79
- initSendMsgResults() {
80
- return {
81
- messageId: '',
82
- message_id: '',
83
- time: 0,
84
- messageTime: 0,
85
- rawData: []
86
- };
87
- }
88
- /**
89
- * 处理返回值
90
- * @param data 返回值
91
- */
92
- handleResponse(data) {
93
- const { id, timestamp } = data.rawData[0];
94
- data.messageId = id;
95
- data.message_id = id;
96
- data.messageTime = timestamp;
97
- data.messageTime = typeof timestamp === 'string' ? new Date(timestamp).getTime() : timestamp;
98
- return data;
99
- }
100
- /**
101
- * - 处理按钮、markdown
102
- * - 统一格式后推入待发送消息列表
103
- * @param type 消息类型
104
- * @param button 按钮
105
- * @param keyboard 键盘
106
- * @param markdown markdown
107
- * @param markdownTpl markdown模板
108
- * @returns 消息列表
109
- */
110
- markdownToButton(type, list) {
111
- /** 统一按钮 */
112
- const rows = [];
113
- if (list.button.length) {
114
- list.button.forEach((v) => {
115
- rows.push(...karinToQQBot(v));
116
- });
117
- }
118
- if (list.keyboard.length) {
119
- list.keyboard.forEach((v) => {
120
- rows.push(...karinToQQBot(v));
121
- });
122
- }
123
- list.markdown.forEach((v) => {
124
- const item = type === 'guild' ? this.super.GuildMsgOptions('markdown', { content: v.markdown }) : this.super.QQdMsgOptions('markdown', { content: v.markdown });
125
- if (rows.length)
126
- item.keyboard = { content: { rows } };
127
- list.list.push(item);
128
- });
129
- list.markdownTpl.forEach((v) => {
130
- const item = type === 'guild'
131
- ? this.super.GuildMsgOptions('markdown', {
132
- custom_template_id: v.templateId,
133
- params: v.params
134
- })
135
- : this.super.QQdMsgOptions('markdown', {
136
- custom_template_id: v.templateId,
137
- params: v.params
138
- });
139
- if (rows.length)
140
- item.keyboard = { content: { rows } };
141
- list.list.push(item);
142
- });
143
- }
144
- }
@@ -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(`![karin #${width}px #${height}px](${file})`);
16
- return;
17
- }
18
- const { url, width, height } = await fileToUrl('image', file, 'image.jpg');
19
- list.content.push(`![karin #${width}px #${height}px](${url})`);
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
- }