@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
package/lib/core/api/types.d.ts
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import type { karinToQQBot } from 'node-karin';
|
|
2
|
-
/** 上传富媒体文件场景 */
|
|
3
|
-
export type Scene = 'user' | 'group';
|
|
4
|
-
/** 上传富媒体文件类型 */
|
|
5
|
-
export type MediaType = 'image' | 'video' | 'record' | 'file';
|
|
6
|
-
/** 发送QQ消息请求参数基类 */
|
|
7
|
-
export interface SendQQMessageRequest {
|
|
8
|
-
/** 消息类型:0 是文本,2 是 markdown, 3 ark,4 embed,7 media 富媒体 */
|
|
9
|
-
msg_type: 0 | 2 | 3 | 4 | 7;
|
|
10
|
-
}
|
|
11
|
-
/** 发送QQ被动消息参数 */
|
|
12
|
-
export interface QQMessageID {
|
|
13
|
-
/** 前置收到的事件 ID,用于发送被动消息,支持事件:"INTERACTION_CREATE"、"C2C_MSG_RECEIVE"、"FRIEND_ADD" */
|
|
14
|
-
event_id?: string;
|
|
15
|
-
/** 前置收到的用户发送过来的消息 ID,用于发送被动(回复)消息 */
|
|
16
|
-
msg_id?: string;
|
|
17
|
-
/** 回复消息的序号,与 msg_id 联合使用,避免相同消息id回复重复发送,不填默认是1。相同的 msg_id + msg_seq 重复发送会失败。 */
|
|
18
|
-
msg_seq?: number;
|
|
19
|
-
}
|
|
20
|
-
/** 发送QQ文本消息请求参数 */
|
|
21
|
-
export interface SendQQTextMessageRequest extends SendQQMessageRequest, QQMessageID {
|
|
22
|
-
msg_type: 0;
|
|
23
|
-
/**
|
|
24
|
-
* 消息内容 支持如下内嵌格式
|
|
25
|
-
* - `<qqbot-at-user id="" />` `@用户` **注意双引号不能省略**
|
|
26
|
-
* - `<qqbot-at-everyone />` `@所有人`
|
|
27
|
-
*/
|
|
28
|
-
content: string;
|
|
29
|
-
}
|
|
30
|
-
/** markdown消息结构 */
|
|
31
|
-
export type Markdown = {
|
|
32
|
-
/** markdown 文本 */
|
|
33
|
-
content: string;
|
|
34
|
-
} | {
|
|
35
|
-
/** markdown 模版id,申请模版后获得 */
|
|
36
|
-
custom_template_id: string;
|
|
37
|
-
/** 模版内变量与填充值的kv映射 */
|
|
38
|
-
params: {
|
|
39
|
-
key: string;
|
|
40
|
-
values: string[];
|
|
41
|
-
}[];
|
|
42
|
-
};
|
|
43
|
-
/** 按钮消息结构 */
|
|
44
|
-
export type Keyboard = {
|
|
45
|
-
content: {
|
|
46
|
-
rows: ReturnType<typeof karinToQQBot>;
|
|
47
|
-
};
|
|
48
|
-
} | {
|
|
49
|
-
/** 按钮模版id */
|
|
50
|
-
id: string;
|
|
51
|
-
};
|
|
52
|
-
/** 发送QQ Markdown 消息请求参数 */
|
|
53
|
-
export interface SendQQMarkdownMessageRequest extends SendQQMessageRequest, QQMessageID {
|
|
54
|
-
msg_type: 2;
|
|
55
|
-
/**
|
|
56
|
-
* markdown 消息内容 支持如下内嵌格式
|
|
57
|
-
* - `<qqbot-cmd-enter text="xxx" />` `回车按钮: 点击后,文本直接发送`
|
|
58
|
-
* - `<qqbot-cmd-input text="xxx" show="xxx" reference="false" />` `点击后,文本输入框弹出`
|
|
59
|
-
* - `text 用户点击后插入输入框的文本,参数必填,最大限制 100 字符,传值时需要 urlencode`
|
|
60
|
-
* - `show 用户在消息内看到的文本,参数选填,默认取 text 值,最大限制 100 字符,传值时需要 urlencode。`
|
|
61
|
-
* - `reference 插入输入框时是否带消息原文回复引用,参数选填,默认为 false,填入 true 时则带引用回复到输入框中。`
|
|
62
|
-
*
|
|
63
|
-
* {@link https://bot.q.qq.com/wiki/develop/api-v2/server-inter/message/trans/text-chain.html}
|
|
64
|
-
*/
|
|
65
|
-
markdown: Markdown;
|
|
66
|
-
/** 按钮 */
|
|
67
|
-
keyboard?: Keyboard;
|
|
68
|
-
}
|
|
69
|
-
/** 发送QQ Ark 消息请求参数 */
|
|
70
|
-
export interface SendQQArkMessageRequest extends SendQQMessageRequest, QQMessageID {
|
|
71
|
-
msg_type: 3;
|
|
72
|
-
/** ark 消息内容 */
|
|
73
|
-
ark: {
|
|
74
|
-
/** ark 模版id */
|
|
75
|
-
template_id: number;
|
|
76
|
-
/** 模版内变量与填充值的kv映射 tips: 未经测试 先any */
|
|
77
|
-
kv: any[];
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/** 发送QQ Embed 消息请求参数 文档没看到发送接口 */
|
|
81
|
-
/** 发送QQ Media 消息请求参数 */
|
|
82
|
-
export interface SendQQMediaMessageRequest extends SendQQMessageRequest, QQMessageID {
|
|
83
|
-
msg_type: 7;
|
|
84
|
-
/** media 消息内容 */
|
|
85
|
-
media: {
|
|
86
|
-
/** 文件信息,用于发消息接口的 media 字段使用 */
|
|
87
|
-
file_info: string;
|
|
88
|
-
};
|
|
89
|
-
/** 当 msg_type = 7 时,content 字段需要填入一个值,譬如一个空格 “ ”,后续版本会修复该问题。 */
|
|
90
|
-
content: string;
|
|
91
|
-
}
|
|
92
|
-
/** 发送QQ消息请求参数 */
|
|
93
|
-
export type SendQQMsg = SendQQTextMessageRequest | SendQQMarkdownMessageRequest | SendQQArkMessageRequest | SendQQMediaMessageRequest;
|
|
94
|
-
/** 发送频道被动消息参数 */
|
|
95
|
-
export interface SendGuildMessageID {
|
|
96
|
-
/** 消息ID */
|
|
97
|
-
msg_id?: string;
|
|
98
|
-
/** 事件id */
|
|
99
|
-
event_id?: string;
|
|
100
|
-
}
|
|
101
|
-
/** 发送频道引用消息参数 */
|
|
102
|
-
export interface SendGuildQuoteMessage {
|
|
103
|
-
/** 引用消息的ID */
|
|
104
|
-
message_id?: string;
|
|
105
|
-
/** 是否忽略获取引用消息详情错误,默认否 */
|
|
106
|
-
ignore_get_message_error?: boolean;
|
|
107
|
-
}
|
|
108
|
-
/** 发送频道消息请求参数基类 */
|
|
109
|
-
export interface SendGuildMessageRequest {
|
|
110
|
-
/** 单独加一个类型 用于区分不同的消息类型 */
|
|
111
|
-
type: 'text' | 'image' | 'embed' | 'ark' | 'markdown';
|
|
112
|
-
}
|
|
113
|
-
/** 发送频道 文本 消息请求参数 */
|
|
114
|
-
export interface SendGuildTextMessageRequest extends SendGuildMessageID, SendGuildQuoteMessage, SendGuildMessageRequest {
|
|
115
|
-
type: 'text';
|
|
116
|
-
/**
|
|
117
|
-
* 消息内容 支持如下内嵌格式
|
|
118
|
-
* - `<@user_id>` `@用户`
|
|
119
|
-
* - `@everyone` `@所有人`
|
|
120
|
-
* - `<#channel_id>` `#子频道`
|
|
121
|
-
* - `<emoji:id>` `表情`
|
|
122
|
-
*/
|
|
123
|
-
content: string;
|
|
124
|
-
/** 图片url地址 */
|
|
125
|
-
image?: string;
|
|
126
|
-
}
|
|
127
|
-
/** 发送频道 图片 消息请求参数 */
|
|
128
|
-
export interface SendGuildImageMessageRequest extends SendGuildMessageID, SendGuildQuoteMessage, SendGuildMessageRequest {
|
|
129
|
-
type: 'image';
|
|
130
|
-
/** 图片url地址 */
|
|
131
|
-
image: string;
|
|
132
|
-
}
|
|
133
|
-
/** embeds消息结构 */
|
|
134
|
-
export interface Embeds {
|
|
135
|
-
/** 标题 */
|
|
136
|
-
title: string;
|
|
137
|
-
/** 消息弹窗内容 */
|
|
138
|
-
prompt: string;
|
|
139
|
-
/** 缩略图 */
|
|
140
|
-
thumbnail: {
|
|
141
|
-
/** 图片地址 */
|
|
142
|
-
url: string;
|
|
143
|
-
};
|
|
144
|
-
/** embed 字段数据 */
|
|
145
|
-
fields: Record<string, any>[];
|
|
146
|
-
}
|
|
147
|
-
/** 发送频道 embed 消息请求参数 */
|
|
148
|
-
export interface SendGuildEmbedMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
|
|
149
|
-
type: 'embed';
|
|
150
|
-
/** embed 消息内容 */
|
|
151
|
-
embed: Embeds;
|
|
152
|
-
}
|
|
153
|
-
/** ark消息结构 */
|
|
154
|
-
export interface Ark {
|
|
155
|
-
/** 模版id */
|
|
156
|
-
template_id: number;
|
|
157
|
-
/** 模版内变量与填充值的kv映射 */
|
|
158
|
-
kv: {
|
|
159
|
-
key: string;
|
|
160
|
-
value: string;
|
|
161
|
-
/** 这个嵌套是认真的嘛... */
|
|
162
|
-
obj: {
|
|
163
|
-
obj_kv: {
|
|
164
|
-
key: string;
|
|
165
|
-
value: string;
|
|
166
|
-
}[];
|
|
167
|
-
}[];
|
|
168
|
-
}[];
|
|
169
|
-
}
|
|
170
|
-
/** 发送频道 ark 消息请求参数 */
|
|
171
|
-
export interface SendGuildArkMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
|
|
172
|
-
type: 'ark';
|
|
173
|
-
/** ark 消息内容 */
|
|
174
|
-
ark: Ark;
|
|
175
|
-
}
|
|
176
|
-
/** 发送频道 markdown 消息请求参数 */
|
|
177
|
-
export interface SendGuildMarkdownMessageRequest extends SendGuildMessageID, SendGuildMessageRequest {
|
|
178
|
-
type: 'markdown';
|
|
179
|
-
/** markdown 消息内容 */
|
|
180
|
-
markdown: Markdown;
|
|
181
|
-
/** 按钮 */
|
|
182
|
-
keyboard?: Keyboard;
|
|
183
|
-
}
|
|
184
|
-
/** 发送频道消息请求参数 */
|
|
185
|
-
export type SendGuildMsg = SendGuildTextMessageRequest | SendGuildImageMessageRequest | SendGuildEmbedMessageRequest | SendGuildArkMessageRequest | SendGuildMarkdownMessageRequest;
|
|
186
|
-
/** 获取当前机器人详情接口响应 */
|
|
187
|
-
export interface GetMeResponse {
|
|
188
|
-
/** 机器人的频道ID */
|
|
189
|
-
id: string;
|
|
190
|
-
/** 机器人的昵称 */
|
|
191
|
-
username: string;
|
|
192
|
-
/** 用户头像 */
|
|
193
|
-
avatar: string;
|
|
194
|
-
/** 特殊关联应用的 openid */
|
|
195
|
-
union_openid: string;
|
|
196
|
-
/** 机器人关联的互联应用的用户信息 */
|
|
197
|
-
union_user_account: string;
|
|
198
|
-
/** 机器人的分享url */
|
|
199
|
-
share_url: string;
|
|
200
|
-
/** 机器人介绍 */
|
|
201
|
-
welcome_msg: string;
|
|
202
|
-
}
|
|
203
|
-
/** 创建私信会话接口响应 */
|
|
204
|
-
export interface DmsResponse {
|
|
205
|
-
/** 频道ID 用于私信会话使用 */
|
|
206
|
-
guild_id: string;
|
|
207
|
-
/** 子频道ID 用于私信会话使用 */
|
|
208
|
-
channel_id: string;
|
|
209
|
-
/** 创建时间 */
|
|
210
|
-
create_time: string;
|
|
211
|
-
}
|
|
212
|
-
/** 发送QQ消息后响应 */
|
|
213
|
-
export interface SendQQMsgResponse {
|
|
214
|
-
/** 消息唯一 ID */
|
|
215
|
-
id: string;
|
|
216
|
-
/** 发送时间 */
|
|
217
|
-
timestamp: number;
|
|
218
|
-
}
|
|
219
|
-
/** 发送频道消息后响应 */
|
|
220
|
-
export interface SendGuildResponse {
|
|
221
|
-
/** 消息唯一 ID */
|
|
222
|
-
id: string;
|
|
223
|
-
/** 发送时间 ISO8601 timestamp */
|
|
224
|
-
timestamp: string;
|
|
225
|
-
}
|
|
226
|
-
/** 上传富媒体文件响应 */
|
|
227
|
-
export interface UploadMediaResponse {
|
|
228
|
-
/** 文件 ID */
|
|
229
|
-
file_uuid: string;
|
|
230
|
-
/** 文件信息,用于发消息接口的 media 字段使用 */
|
|
231
|
-
file_info: string;
|
|
232
|
-
/** 有效期,表示剩余多少秒到期,到期后 file_info 失效,当等于 0 时,表示可长期使用 */
|
|
233
|
-
ttl: number;
|
|
234
|
-
/** 发送消息的唯一ID,当srv_send_msg设置为true时返回 */
|
|
235
|
-
id: string;
|
|
236
|
-
}
|
package/lib/core/api/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ElementTypes } from 'node-karin';
|
|
2
|
-
import type { DirectMsgEvent, GuildMsgEvent, C2CMsgEvent, GroupMsgEvent } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* QQBot群、私聊转karin消息端
|
|
5
|
-
* @param appid 应用ID
|
|
6
|
-
* @param event 事件
|
|
7
|
-
* @param subBotID 机器人ID 也就是跟用户一样的ID 并非appid
|
|
8
|
-
* @return karin格式消息
|
|
9
|
-
*/
|
|
10
|
-
export declare const QQBotConvertKarin: (appid: string, event: C2CMsgEvent | GroupMsgEvent | GuildMsgEvent | DirectMsgEvent, subBotID: string) => Array<ElementTypes>;
|
package/lib/core/event/conver.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { segment } from 'node-karin';
|
|
2
|
-
import { config } from '@/utils/config';
|
|
3
|
-
/**
|
|
4
|
-
* QQBot群、私聊转karin消息端
|
|
5
|
-
* @param appid 应用ID
|
|
6
|
-
* @param event 事件
|
|
7
|
-
* @param subBotID 机器人ID 也就是跟用户一样的ID 并非appid
|
|
8
|
-
* @return karin格式消息
|
|
9
|
-
*/
|
|
10
|
-
export const QQBotConvertKarin = (appid, event, subBotID) => {
|
|
11
|
-
const elements = [];
|
|
12
|
-
const data = event.d;
|
|
13
|
-
const mentions = {};
|
|
14
|
-
if (event.t === "MESSAGE_CREATE" /* EventEnum.MESSAGE_CREATE */ || event.t === "AT_MESSAGE_CREATE" /* EventEnum.AT_MESSAGE_CREATE */) {
|
|
15
|
-
event.d.mentions?.forEach(v => {
|
|
16
|
-
mentions[v.id] = v;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
for (const v of data.attachments || []) {
|
|
20
|
-
if (v.content_type === 'file') {
|
|
21
|
-
console.log(v);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const url = v.url.startsWith('http') ? v.url : `https://${v.url}`;
|
|
25
|
-
elements.push(segment.image(url, {
|
|
26
|
-
subType: v.content_type.split('/')[1],
|
|
27
|
-
name: v.filename,
|
|
28
|
-
width: v.width,
|
|
29
|
-
height: v.height,
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
const regex = /<faceType=\d+,faceId="\d+",ext="[^"]+">|<@!\d+>|[^<]+/g;
|
|
33
|
-
const result = data?.content?.match(regex) || [];
|
|
34
|
-
result.forEach(v => {
|
|
35
|
-
if (v.startsWith('<faceType=')) {
|
|
36
|
-
const Match = v.match(/faceId="(\d+)"/);
|
|
37
|
-
elements.push(segment.face(Number(Match[1])));
|
|
38
|
-
}
|
|
39
|
-
if (v.startsWith('<@!')) {
|
|
40
|
-
const id = v.replace(/^<@!|>$/g, '');
|
|
41
|
-
const name = mentions[id]?.username || '';
|
|
42
|
-
elements.push(segment.at(id === subBotID ? appid : id, name));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const regex = config()?.[appid]?.regex || [];
|
|
46
|
-
for (const r of regex) {
|
|
47
|
-
const reg = r.reg instanceof RegExp ? r.reg : new RegExp(r.reg);
|
|
48
|
-
v = v.trim().replace(reg, r.rep);
|
|
49
|
-
}
|
|
50
|
-
elements.push(segment.text(v));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (event.t === "GROUP_AT_MESSAGE_CREATE" /* EventEnum.GROUP_AT_MESSAGE_CREATE */) {
|
|
54
|
-
elements.unshift(segment.at(appid));
|
|
55
|
-
}
|
|
56
|
-
return elements;
|
|
57
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AdapterQQBotNormal } from '@/core/adapter/normal';
|
|
2
|
-
import { AdapterQQBotMarkdown } from '@/core/adapter/markdown';
|
|
3
|
-
import type { Event } from '@/core/event/types';
|
|
4
|
-
/**
|
|
5
|
-
* 创建事件
|
|
6
|
-
* @param client 机器人实例
|
|
7
|
-
* @param event 事件
|
|
8
|
-
*/
|
|
9
|
-
export declare const createEvent: (client: AdapterQQBotNormal | AdapterQQBotMarkdown, event: Event) => void;
|
package/lib/core/event/index.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { URL } from 'url';
|
|
2
|
-
import { QQBotApi } from '@/core/api';
|
|
3
|
-
import { event } from '@/utils/common';
|
|
4
|
-
import { config, pkg } from '@/utils/config';
|
|
5
|
-
import { logger, registerBot } from 'node-karin';
|
|
6
|
-
import { createC2CWebhook } from '@/core/webhook/c2c';
|
|
7
|
-
import { createHttpWebhook } from '@/core/webhook/http';
|
|
8
|
-
import { createWebSocketWebhook } from '@/core/webhook/ws';
|
|
9
|
-
import { AdapterQQBotNormal } from '@/core/adapter/normal';
|
|
10
|
-
import { AdapterQQBotMarkdown } from '@/core/adapter/markdown';
|
|
11
|
-
import { createAxiosInstance, getAccessToken } from '@/core/internal/axios';
|
|
12
|
-
import { GraphicTemplateMarkdown, rawMarkdown } from '@/core/adapter/handler';
|
|
13
|
-
import { onChannelMsg, onDirectMsg, onFriendMsg, onGroupMsg } from '@/core/event/message';
|
|
14
|
-
import { onGroupAddRobot, onGroupDelRobot } from '@/core/event/notice';
|
|
15
|
-
const main = async () => {
|
|
16
|
-
const cfg = config();
|
|
17
|
-
for (const [key, value] of Object.entries(cfg)) {
|
|
18
|
-
if (!key || key === 'default')
|
|
19
|
-
continue;
|
|
20
|
-
const bot = Object.assign(cfg.default, value);
|
|
21
|
-
const appId = String(bot.appId);
|
|
22
|
-
await getAccessToken(bot.tokenApi, appId, bot.secret);
|
|
23
|
-
const url = bot.sandbox ? bot.sandboxApi : bot.prodApi;
|
|
24
|
-
const axios = createAxiosInstance(url, appId);
|
|
25
|
-
const api = new QQBotApi(axios);
|
|
26
|
-
const data = await api.getMe();
|
|
27
|
-
const { id, username, avatar } = data;
|
|
28
|
-
const client = createClient(bot, api);
|
|
29
|
-
client.account.name = username;
|
|
30
|
-
client.account.avatar = avatar;
|
|
31
|
-
client.account.selfId = appId;
|
|
32
|
-
const qq = new URL(data.share_url).searchParams.get('robot_uin');
|
|
33
|
-
client.account.subId.id = id;
|
|
34
|
-
client.account.subId.qq = qq;
|
|
35
|
-
client.account.subId.appid = appId;
|
|
36
|
-
client.account.subId.union_openid = data.union_openid;
|
|
37
|
-
event.on(appId, (event) => createEvent(client, event));
|
|
38
|
-
createC2CWebhook();
|
|
39
|
-
createHttpWebhook();
|
|
40
|
-
createWebSocketWebhook();
|
|
41
|
-
// 注册Bot
|
|
42
|
-
client.adapter.address = url;
|
|
43
|
-
client.adapter.secret = bot.secret;
|
|
44
|
-
client.adapter.version = pkg().version;
|
|
45
|
-
client.adapter.index = registerBot('http', client);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* 创建QQBot客户端
|
|
50
|
-
* @param bot 机器人配置
|
|
51
|
-
* @param api 机器人API
|
|
52
|
-
*/
|
|
53
|
-
const createClient = (bot, api) => {
|
|
54
|
-
if (Number(bot.markdown?.mode) === 0) {
|
|
55
|
-
return new AdapterQQBotNormal(api);
|
|
56
|
-
}
|
|
57
|
-
if (Number(bot.markdown?.mode) === 1) {
|
|
58
|
-
return new AdapterQQBotMarkdown(api, rawMarkdown, bot);
|
|
59
|
-
}
|
|
60
|
-
if (Number(bot.markdown?.mode) === 3) {
|
|
61
|
-
return new AdapterQQBotMarkdown(api, GraphicTemplateMarkdown, bot);
|
|
62
|
-
}
|
|
63
|
-
if (Number(bot.markdown?.mode) === 4) {
|
|
64
|
-
return new AdapterQQBotMarkdown(api, GraphicTemplateMarkdown, bot);
|
|
65
|
-
}
|
|
66
|
-
if (Number(bot.markdown?.mode) === 5) {
|
|
67
|
-
return new AdapterQQBotMarkdown(api, GraphicTemplateMarkdown, bot);
|
|
68
|
-
}
|
|
69
|
-
/** 默认返回0 */
|
|
70
|
-
return new AdapterQQBotNormal(api);
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* 创建事件
|
|
74
|
-
* @param client 机器人实例
|
|
75
|
-
* @param event 事件
|
|
76
|
-
*/
|
|
77
|
-
export const createEvent = (client, event) => {
|
|
78
|
-
if (event.t === "GROUP_AT_MESSAGE_CREATE" /* EventEnum.GROUP_AT_MESSAGE_CREATE */) {
|
|
79
|
-
return onGroupMsg(client, event);
|
|
80
|
-
}
|
|
81
|
-
if (event.t === "C2C_MESSAGE_CREATE" /* EventEnum.C2C_MESSAGE_CREATE */) {
|
|
82
|
-
return onFriendMsg(client, event);
|
|
83
|
-
}
|
|
84
|
-
if (event.t === "MESSAGE_CREATE" /* EventEnum.MESSAGE_CREATE */ || event.t === "AT_MESSAGE_CREATE" /* EventEnum.AT_MESSAGE_CREATE */) {
|
|
85
|
-
return onChannelMsg(client, event);
|
|
86
|
-
}
|
|
87
|
-
if (event.t === "DIRECT_MESSAGE_CREATE" /* EventEnum.DIRECT_MESSAGE_CREATE */) {
|
|
88
|
-
return onDirectMsg(client, event);
|
|
89
|
-
}
|
|
90
|
-
if (event.t === "GROUP_ADD_ROBOT" /* EventEnum.GROUP_ADD_ROBOT */) {
|
|
91
|
-
return onGroupAddRobot(client, event);
|
|
92
|
-
}
|
|
93
|
-
if (event.t === "GROUP_DEL_ROBOT" /* EventEnum.GROUP_DEL_ROBOT */) {
|
|
94
|
-
return onGroupDelRobot(client, event);
|
|
95
|
-
}
|
|
96
|
-
logger.error(`未知事件类型: ${JSON.stringify(event)}`);
|
|
97
|
-
};
|
|
98
|
-
main();
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { AdapterQQBotNormal } from '../adapter/normal';
|
|
2
|
-
import type { AdapterQQBotMarkdown } from '../adapter/markdown';
|
|
3
|
-
import type { C2CMsgEvent, DirectMsgEvent, GroupMsgEvent, GuildMsgEvent } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* 创建群消息事件
|
|
6
|
-
* @param client 机器人实例
|
|
7
|
-
* @param event 事件
|
|
8
|
-
*/
|
|
9
|
-
export declare const onGroupMsg: (client: AdapterQQBotMarkdown | AdapterQQBotNormal, event: GroupMsgEvent) => void;
|
|
10
|
-
/**
|
|
11
|
-
* 创建好友消息事件
|
|
12
|
-
* @param client 机器人实例
|
|
13
|
-
* @param event 事件
|
|
14
|
-
*/
|
|
15
|
-
export declare const onFriendMsg: (client: AdapterQQBotMarkdown | AdapterQQBotNormal, event: C2CMsgEvent) => void;
|
|
16
|
-
/**
|
|
17
|
-
* 创建频道消息事件
|
|
18
|
-
* @param client 机器人实例
|
|
19
|
-
* @param event 事件
|
|
20
|
-
*/
|
|
21
|
-
export declare const onChannelMsg: (client: AdapterQQBotMarkdown | AdapterQQBotNormal, event: GuildMsgEvent) => void;
|
|
22
|
-
/**
|
|
23
|
-
* 创建频道私信事件
|
|
24
|
-
* @param client 机器人实例
|
|
25
|
-
* @param event 事件
|
|
26
|
-
*/
|
|
27
|
-
export declare const onDirectMsg: (client: AdapterQQBotMarkdown | AdapterQQBotNormal, event: DirectMsgEvent) => void;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { QQBotConvertKarin } from './conver';
|
|
2
|
-
import { karin, createGroupMessage, createFriendMessage, segment, createGuildMessage, createDirectMessage } from 'node-karin';
|
|
3
|
-
/**
|
|
4
|
-
* 创建群消息事件
|
|
5
|
-
* @param client 机器人实例
|
|
6
|
-
* @param event 事件
|
|
7
|
-
*/
|
|
8
|
-
export const onGroupMsg = (client, event) => {
|
|
9
|
-
const selfId = client.selfId;
|
|
10
|
-
const userId = event.d.author.member_openid;
|
|
11
|
-
const contact = karin.contactGroup(event.d.group_id);
|
|
12
|
-
const sender = karin.groupSender(userId, 'unknown');
|
|
13
|
-
const e = createGroupMessage({
|
|
14
|
-
bot: client,
|
|
15
|
-
elements: QQBotConvertKarin(selfId, event, client.selfSubId('id')),
|
|
16
|
-
eventId: event.id,
|
|
17
|
-
messageId: event.d.id,
|
|
18
|
-
messageSeq: 0,
|
|
19
|
-
rawEvent: event,
|
|
20
|
-
time: Number(event.d.timestamp),
|
|
21
|
-
contact,
|
|
22
|
-
sender,
|
|
23
|
-
srcReply: (elements) => client.srcReply(e, [...elements, segment.pasmsg(event.d.id)])
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* 创建好友消息事件
|
|
28
|
-
* @param client 机器人实例
|
|
29
|
-
* @param event 事件
|
|
30
|
-
*/
|
|
31
|
-
export const onFriendMsg = (client, event) => {
|
|
32
|
-
const selfId = client.selfId;
|
|
33
|
-
const userId = event.d.author.user_openid;
|
|
34
|
-
const contact = karin.contactFriend(userId);
|
|
35
|
-
const sender = karin.friendSender(userId, '');
|
|
36
|
-
const e = createFriendMessage({
|
|
37
|
-
bot: client,
|
|
38
|
-
elements: QQBotConvertKarin(selfId, event, client.selfSubId('id')),
|
|
39
|
-
eventId: event.id,
|
|
40
|
-
messageId: event.d.id,
|
|
41
|
-
messageSeq: 0,
|
|
42
|
-
rawEvent: event,
|
|
43
|
-
time: Number(event.d.timestamp),
|
|
44
|
-
contact,
|
|
45
|
-
sender,
|
|
46
|
-
srcReply: (elements) => client.srcReply(e, [...elements, segment.pasmsg(event.d.id)])
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* 创建频道消息事件
|
|
51
|
-
* @param client 机器人实例
|
|
52
|
-
* @param event 事件
|
|
53
|
-
*/
|
|
54
|
-
export const onChannelMsg = (client, event) => {
|
|
55
|
-
const selfId = client.selfId;
|
|
56
|
-
const userId = event.d.author.id;
|
|
57
|
-
const contact = karin.contact('guild', event.d.guild_id, event.d.channel_id);
|
|
58
|
-
const sender = karin.groupSender(userId, 'unknown', event.d.author.username);
|
|
59
|
-
const e = createGuildMessage({
|
|
60
|
-
bot: client,
|
|
61
|
-
elements: QQBotConvertKarin(selfId, event, client.selfSubId('id')),
|
|
62
|
-
eventId: event.id,
|
|
63
|
-
messageId: event.d.id,
|
|
64
|
-
messageSeq: 0,
|
|
65
|
-
rawEvent: event,
|
|
66
|
-
time: Number(event.d.timestamp),
|
|
67
|
-
contact,
|
|
68
|
-
sender,
|
|
69
|
-
srcReply: (elements) => client.srcReply(e, [...elements, segment.pasmsg(event.d.id)])
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* 创建频道私信事件
|
|
74
|
-
* @param client 机器人实例
|
|
75
|
-
* @param event 事件
|
|
76
|
-
*/
|
|
77
|
-
export const onDirectMsg = (client, event) => {
|
|
78
|
-
const selfId = client.selfId;
|
|
79
|
-
const userId = event.d.author.id;
|
|
80
|
-
const contact = karin.contact('direct', event.d.guild_id, event.d.channel_id);
|
|
81
|
-
const sender = karin.friendSender(userId, event.d.author.username);
|
|
82
|
-
const e = createDirectMessage({
|
|
83
|
-
bot: client,
|
|
84
|
-
elements: QQBotConvertKarin(selfId, event, client.selfSubId('id')),
|
|
85
|
-
eventId: event.id,
|
|
86
|
-
messageId: event.d.id,
|
|
87
|
-
messageSeq: 0,
|
|
88
|
-
rawEvent: event,
|
|
89
|
-
time: Number(event.d.timestamp),
|
|
90
|
-
contact,
|
|
91
|
-
sender,
|
|
92
|
-
srcGuildId: event.d.src_guild_id,
|
|
93
|
-
srcReply: (elements) => client.srcReply(e, [...elements, segment.pasmsg(event.d.id)]),
|
|
94
|
-
});
|
|
95
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { AdapterQQBot } from '@/core/adapter/adapter';
|
|
2
|
-
import type { GroupAddRobotEvent, GroupDelRobotEvent, GroupMsgRejectEvent, GroupMsgReceiveEvent, FriendAddEvent, FriendDelEvent, C2CMsgRejectEvent, C2CMsgReceiveEvent } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* 机器人加入群聊事件
|
|
5
|
-
* @param client 机器人实例
|
|
6
|
-
* @param event 事件
|
|
7
|
-
*/
|
|
8
|
-
export declare const onGroupAddRobot: (client: AdapterQQBot, event: GroupAddRobotEvent) => void;
|
|
9
|
-
/**
|
|
10
|
-
* 机器人退出群聊事件
|
|
11
|
-
* @param client 机器人实例
|
|
12
|
-
* @param event 事件
|
|
13
|
-
*/
|
|
14
|
-
export declare const onGroupDelRobot: (client: AdapterQQBot, event: GroupDelRobotEvent) => void;
|
|
15
|
-
/**
|
|
16
|
-
* 群聊接受机器人主动消息
|
|
17
|
-
* @param client 机器人实例
|
|
18
|
-
* @param event 事件
|
|
19
|
-
*/
|
|
20
|
-
export declare const onGroupMsgReceive: (client: AdapterQQBot, event: GroupMsgReceiveEvent) => void;
|
|
21
|
-
/**
|
|
22
|
-
* 群聊拒绝机器人主动消息
|
|
23
|
-
* @param client 机器人实例
|
|
24
|
-
* @param event 事件
|
|
25
|
-
*/
|
|
26
|
-
export declare const onGroupMsgReject: (client: AdapterQQBot, event: GroupMsgRejectEvent) => void;
|
|
27
|
-
/**
|
|
28
|
-
* 好友添加事件
|
|
29
|
-
* @param client 机器人实例
|
|
30
|
-
* @param event 事件
|
|
31
|
-
*/
|
|
32
|
-
export declare const onFriendAdd: (client: AdapterQQBot, event: FriendAddEvent) => void;
|
|
33
|
-
/**
|
|
34
|
-
* 好友删除事件
|
|
35
|
-
* @param client 机器人实例
|
|
36
|
-
* @param event 事件
|
|
37
|
-
*/
|
|
38
|
-
export declare const onFriendDel: (client: AdapterQQBot, event: FriendDelEvent) => void;
|
|
39
|
-
/**
|
|
40
|
-
* 好友接受机器人主动消息
|
|
41
|
-
* @param client 机器人实例
|
|
42
|
-
* @param event 事件
|
|
43
|
-
*/
|
|
44
|
-
export declare const onC2CMsgReceive: (client: AdapterQQBot, event: C2CMsgReceiveEvent) => void;
|
|
45
|
-
/**
|
|
46
|
-
* 好友拒绝机器人主动消息
|
|
47
|
-
* @param client 机器人实例
|
|
48
|
-
* @param event 事件
|
|
49
|
-
*/
|
|
50
|
-
export declare const onC2CMsgReject: (client: AdapterQQBot, event: C2CMsgRejectEvent) => void;
|