@onebots/adapter-icqq 1.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.
- package/LICENSE +21 -0
- package/README.md +208 -0
- package/lib/adapter.d.ts +93 -0
- package/lib/adapter.js +561 -0
- package/lib/bot.d.ts +178 -0
- package/lib/bot.js +593 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -0
- package/lib/types.d.ts +418 -0
- package/lib/types.js +26 -0
- package/package.json +39 -0
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ICQQ 适配器
|
|
3
|
+
* 继承 Adapter 基类,实现 ICQQ 平台功能
|
|
4
|
+
*/
|
|
5
|
+
import { Account, AdapterRegistry, AccountStatus } from "onebots";
|
|
6
|
+
import { Adapter } from "onebots";
|
|
7
|
+
import { ICQQBot, segment } from "./bot.js";
|
|
8
|
+
export class ICQQAdapter extends Adapter {
|
|
9
|
+
constructor(app) {
|
|
10
|
+
super(app, "icqq");
|
|
11
|
+
this.icon = "https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png";
|
|
12
|
+
}
|
|
13
|
+
// ============================================
|
|
14
|
+
// 消息相关方法
|
|
15
|
+
// ============================================
|
|
16
|
+
/**
|
|
17
|
+
* 发送消息
|
|
18
|
+
*/
|
|
19
|
+
async sendMessage(uin, params) {
|
|
20
|
+
const account = this.getAccount(uin);
|
|
21
|
+
if (!account)
|
|
22
|
+
throw new Error(`Account ${uin} not found`);
|
|
23
|
+
const bot = account.client;
|
|
24
|
+
const { scene_id, scene_type, message } = params;
|
|
25
|
+
// 转换消息格式
|
|
26
|
+
const icqqMessage = this.buildICQQMessage(message);
|
|
27
|
+
const targetId = parseInt(scene_id.string);
|
|
28
|
+
let result;
|
|
29
|
+
if (scene_type === 'private') {
|
|
30
|
+
result = await bot.sendPrivateMessage(targetId, icqqMessage);
|
|
31
|
+
}
|
|
32
|
+
else if (scene_type === 'group') {
|
|
33
|
+
result = await bot.sendGroupMessage(targetId, icqqMessage);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`不支持的消息类型: ${scene_type}`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
message_id: this.createId(result.message_id || result.seq?.toString() || ''),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 删除/撤回消息
|
|
44
|
+
*/
|
|
45
|
+
async deleteMessage(uin, params) {
|
|
46
|
+
const account = this.getAccount(uin);
|
|
47
|
+
if (!account)
|
|
48
|
+
throw new Error(`Account ${uin} not found`);
|
|
49
|
+
const bot = account.client;
|
|
50
|
+
await bot.recallMessage(params.message_id.string);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 获取消息
|
|
54
|
+
*/
|
|
55
|
+
async getMessage(uin, params) {
|
|
56
|
+
const account = this.getAccount(uin);
|
|
57
|
+
if (!account)
|
|
58
|
+
throw new Error(`Account ${uin} not found`);
|
|
59
|
+
const bot = account.client;
|
|
60
|
+
const msg = await bot.getMessage(params.message_id.string);
|
|
61
|
+
const isGroup = !!msg.group_id;
|
|
62
|
+
return {
|
|
63
|
+
message_id: this.createId(msg.message_id),
|
|
64
|
+
time: msg.time * 1000,
|
|
65
|
+
sender: {
|
|
66
|
+
scene_type: isGroup ? 'group' : 'private',
|
|
67
|
+
sender_id: this.createId(msg.user_id.toString()),
|
|
68
|
+
scene_id: this.createId(isGroup ? msg.group_id.toString() : msg.user_id.toString()),
|
|
69
|
+
sender_name: msg.sender?.nickname || '',
|
|
70
|
+
scene_name: '',
|
|
71
|
+
},
|
|
72
|
+
message: this.convertICQQMessageToSegments(msg.message || []),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// ============================================
|
|
76
|
+
// 用户相关方法
|
|
77
|
+
// ============================================
|
|
78
|
+
/**
|
|
79
|
+
* 获取机器人自身信息
|
|
80
|
+
*/
|
|
81
|
+
async getLoginInfo(uin) {
|
|
82
|
+
const account = this.getAccount(uin);
|
|
83
|
+
if (!account)
|
|
84
|
+
throw new Error(`Account ${uin} not found`);
|
|
85
|
+
const bot = account.client;
|
|
86
|
+
const info = bot.getLoginInfo();
|
|
87
|
+
if (!info)
|
|
88
|
+
throw new Error('Bot not ready');
|
|
89
|
+
return {
|
|
90
|
+
user_id: this.createId(info.user_id.toString()),
|
|
91
|
+
user_name: info.nickname,
|
|
92
|
+
user_displayname: info.nickname,
|
|
93
|
+
avatar: info.avatar,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 获取用户信息
|
|
98
|
+
*/
|
|
99
|
+
async getUserInfo(uin, params) {
|
|
100
|
+
const account = this.getAccount(uin);
|
|
101
|
+
if (!account)
|
|
102
|
+
throw new Error(`Account ${uin} not found`);
|
|
103
|
+
const bot = account.client;
|
|
104
|
+
const userId = parseInt(params.user_id.string);
|
|
105
|
+
const info = await bot.getStrangerInfo(userId);
|
|
106
|
+
return {
|
|
107
|
+
user_id: this.createId(info.user_id.toString()),
|
|
108
|
+
user_name: info.nickname,
|
|
109
|
+
user_displayname: info.nickname,
|
|
110
|
+
avatar: info.avatar,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// ============================================
|
|
114
|
+
// 好友相关方法
|
|
115
|
+
// ============================================
|
|
116
|
+
/**
|
|
117
|
+
* 获取好友列表
|
|
118
|
+
*/
|
|
119
|
+
async getFriendList(uin, params) {
|
|
120
|
+
const account = this.getAccount(uin);
|
|
121
|
+
if (!account)
|
|
122
|
+
throw new Error(`Account ${uin} not found`);
|
|
123
|
+
const bot = account.client;
|
|
124
|
+
const friends = await bot.getFriendList();
|
|
125
|
+
return friends.map(friend => ({
|
|
126
|
+
user_id: this.createId(friend.user_id.toString()),
|
|
127
|
+
user_name: friend.nickname,
|
|
128
|
+
remark: friend.remark,
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 获取好友信息
|
|
133
|
+
*/
|
|
134
|
+
async getFriendInfo(uin, params) {
|
|
135
|
+
const account = this.getAccount(uin);
|
|
136
|
+
if (!account)
|
|
137
|
+
throw new Error(`Account ${uin} not found`);
|
|
138
|
+
const bot = account.client;
|
|
139
|
+
const userId = parseInt(params.user_id.string);
|
|
140
|
+
const info = await bot.getStrangerInfo(userId);
|
|
141
|
+
return {
|
|
142
|
+
user_id: this.createId(info.user_id.toString()),
|
|
143
|
+
user_name: info.nickname,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
// ============================================
|
|
147
|
+
// 群组相关方法
|
|
148
|
+
// ============================================
|
|
149
|
+
/**
|
|
150
|
+
* 获取群列表
|
|
151
|
+
*/
|
|
152
|
+
async getGroupList(uin, params) {
|
|
153
|
+
const account = this.getAccount(uin);
|
|
154
|
+
if (!account)
|
|
155
|
+
throw new Error(`Account ${uin} not found`);
|
|
156
|
+
const bot = account.client;
|
|
157
|
+
const groups = await bot.getGroupList();
|
|
158
|
+
return groups.map(group => ({
|
|
159
|
+
group_id: this.createId(group.group_id.toString()),
|
|
160
|
+
group_name: group.group_name,
|
|
161
|
+
member_count: group.member_count,
|
|
162
|
+
max_member_count: group.max_member_count,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 获取群信息
|
|
167
|
+
*/
|
|
168
|
+
async getGroupInfo(uin, params) {
|
|
169
|
+
const account = this.getAccount(uin);
|
|
170
|
+
if (!account)
|
|
171
|
+
throw new Error(`Account ${uin} not found`);
|
|
172
|
+
const bot = account.client;
|
|
173
|
+
const groupId = parseInt(params.group_id.string);
|
|
174
|
+
const info = await bot.getGroupInfo(groupId);
|
|
175
|
+
if (!info)
|
|
176
|
+
throw new Error(`Group ${groupId} not found`);
|
|
177
|
+
return {
|
|
178
|
+
group_id: this.createId(info.group_id.toString()),
|
|
179
|
+
group_name: info.group_name,
|
|
180
|
+
member_count: info.member_count,
|
|
181
|
+
max_member_count: info.max_member_count,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 退出群组
|
|
186
|
+
*/
|
|
187
|
+
async leaveGroup(uin, params) {
|
|
188
|
+
const account = this.getAccount(uin);
|
|
189
|
+
if (!account)
|
|
190
|
+
throw new Error(`Account ${uin} not found`);
|
|
191
|
+
const bot = account.client;
|
|
192
|
+
const groupId = parseInt(params.group_id.string);
|
|
193
|
+
await bot.leaveGroup(groupId);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 获取群成员列表
|
|
197
|
+
*/
|
|
198
|
+
async getGroupMemberList(uin, params) {
|
|
199
|
+
const account = this.getAccount(uin);
|
|
200
|
+
if (!account)
|
|
201
|
+
throw new Error(`Account ${uin} not found`);
|
|
202
|
+
const bot = account.client;
|
|
203
|
+
const groupId = parseInt(params.group_id.string);
|
|
204
|
+
const members = await bot.getGroupMemberList(groupId);
|
|
205
|
+
return members.map(member => ({
|
|
206
|
+
group_id: params.group_id,
|
|
207
|
+
user_id: this.createId(member.user_id.toString()),
|
|
208
|
+
user_name: member.nickname,
|
|
209
|
+
card: member.card || '',
|
|
210
|
+
role: member.role || 'member',
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 获取群成员信息
|
|
215
|
+
*/
|
|
216
|
+
async getGroupMemberInfo(uin, params) {
|
|
217
|
+
const account = this.getAccount(uin);
|
|
218
|
+
if (!account)
|
|
219
|
+
throw new Error(`Account ${uin} not found`);
|
|
220
|
+
const bot = account.client;
|
|
221
|
+
const groupId = parseInt(params.group_id.string);
|
|
222
|
+
const userId = parseInt(params.user_id.string);
|
|
223
|
+
const member = await bot.getGroupMemberInfo(groupId, userId);
|
|
224
|
+
if (!member)
|
|
225
|
+
throw new Error(`Member ${userId} not found in group ${groupId}`);
|
|
226
|
+
return {
|
|
227
|
+
group_id: params.group_id,
|
|
228
|
+
user_id: params.user_id,
|
|
229
|
+
user_name: member.nickname,
|
|
230
|
+
card: member.card || '',
|
|
231
|
+
role: member.role || 'member',
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 踢出群成员
|
|
236
|
+
*/
|
|
237
|
+
async kickGroupMember(uin, params) {
|
|
238
|
+
const account = this.getAccount(uin);
|
|
239
|
+
if (!account)
|
|
240
|
+
throw new Error(`Account ${uin} not found`);
|
|
241
|
+
const bot = account.client;
|
|
242
|
+
const groupId = parseInt(params.group_id.string);
|
|
243
|
+
const userId = parseInt(params.user_id.string);
|
|
244
|
+
await bot.kickGroupMember(groupId, userId, params.reject_add_request);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* 设置群名片
|
|
248
|
+
*/
|
|
249
|
+
async setGroupCard(uin, params) {
|
|
250
|
+
const account = this.getAccount(uin);
|
|
251
|
+
if (!account)
|
|
252
|
+
throw new Error(`Account ${uin} not found`);
|
|
253
|
+
const bot = account.client;
|
|
254
|
+
const groupId = parseInt(params.group_id.string);
|
|
255
|
+
const userId = parseInt(params.user_id.string);
|
|
256
|
+
await bot.setGroupCard(groupId, userId, params.card);
|
|
257
|
+
}
|
|
258
|
+
// ============================================
|
|
259
|
+
// 系统相关方法
|
|
260
|
+
// ============================================
|
|
261
|
+
/**
|
|
262
|
+
* 获取版本信息
|
|
263
|
+
*/
|
|
264
|
+
async getVersion(uin) {
|
|
265
|
+
return {
|
|
266
|
+
app_name: 'onebots ICQQ Adapter',
|
|
267
|
+
app_version: '1.0.0',
|
|
268
|
+
impl: 'icqq',
|
|
269
|
+
version: '1.0.0',
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 获取运行状态
|
|
274
|
+
*/
|
|
275
|
+
async getStatus(uin) {
|
|
276
|
+
const account = this.getAccount(uin);
|
|
277
|
+
return {
|
|
278
|
+
online: account?.status === AccountStatus.Online,
|
|
279
|
+
good: account?.status === AccountStatus.Online,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// ============================================
|
|
283
|
+
// 账号创建
|
|
284
|
+
// ============================================
|
|
285
|
+
createAccount(config) {
|
|
286
|
+
const icqqConfig = {
|
|
287
|
+
account_id: config.account_id,
|
|
288
|
+
password: config.password,
|
|
289
|
+
protocol: config.protocol,
|
|
290
|
+
};
|
|
291
|
+
const bot = new ICQQBot(icqqConfig);
|
|
292
|
+
const account = new Account(this, bot, config);
|
|
293
|
+
// 监听 Bot 事件
|
|
294
|
+
bot.on('ready', (user) => {
|
|
295
|
+
this.logger.info(`ICQQ Bot ${user.nickname} (${user.user_id}) 已就绪`);
|
|
296
|
+
account.status = AccountStatus.Online;
|
|
297
|
+
account.nickname = user.nickname;
|
|
298
|
+
account.avatar = user.avatar;
|
|
299
|
+
});
|
|
300
|
+
bot.on('offline', (event) => {
|
|
301
|
+
this.logger.warn(`ICQQ Bot 离线: ${event.message}`);
|
|
302
|
+
account.status = AccountStatus.OffLine;
|
|
303
|
+
});
|
|
304
|
+
bot.on('qrcode', (event) => {
|
|
305
|
+
this.logger.info(`ICQQ 请扫描二维码登录`);
|
|
306
|
+
// 可以通过事件通知前端显示二维码
|
|
307
|
+
this.emit('qrcode', { account_id: config.account_id, image: event.image });
|
|
308
|
+
});
|
|
309
|
+
bot.on('slider', (event) => {
|
|
310
|
+
this.logger.info(`ICQQ 需要滑块验证: ${event.url}`);
|
|
311
|
+
// 可以通过事件通知前端进行滑块验证
|
|
312
|
+
this.emit('slider', { account_id: config.account_id, url: event.url });
|
|
313
|
+
});
|
|
314
|
+
bot.on('device', (event) => {
|
|
315
|
+
this.logger.info(`ICQQ 需要设备锁验证: ${event.url}`);
|
|
316
|
+
// 可以通过事件通知前端进行设备锁验证
|
|
317
|
+
this.emit('device', { account_id: config.account_id, url: event.url, phone: event.phone });
|
|
318
|
+
});
|
|
319
|
+
bot.on('login_error', (event) => {
|
|
320
|
+
this.logger.error(`ICQQ 登录失败:`, event);
|
|
321
|
+
account.status = AccountStatus.OffLine;
|
|
322
|
+
});
|
|
323
|
+
// 监听私聊消息
|
|
324
|
+
bot.on('private_message', (event) => {
|
|
325
|
+
// 打印消息接收日志
|
|
326
|
+
const contentPreview = event.raw_message.length > 100
|
|
327
|
+
? event.raw_message.substring(0, 100) + '...'
|
|
328
|
+
: event.raw_message;
|
|
329
|
+
this.logger.info(`[ICQQ] 收到私聊消息 | 消息ID: ${event.message_id} | ` +
|
|
330
|
+
`发送者: ${event.sender.nickname} (${event.user_id}) | 内容: ${contentPreview}`);
|
|
331
|
+
// 转换为 CommonEvent 格式
|
|
332
|
+
const commonEvent = {
|
|
333
|
+
id: this.createId(event.message_id),
|
|
334
|
+
timestamp: event.time * 1000,
|
|
335
|
+
platform: 'icqq',
|
|
336
|
+
bot_id: this.createId(config.account_id),
|
|
337
|
+
type: 'message',
|
|
338
|
+
message_type: 'private',
|
|
339
|
+
sender: {
|
|
340
|
+
id: this.createId(event.user_id.toString()),
|
|
341
|
+
name: event.sender.nickname,
|
|
342
|
+
avatar: `https://q1.qlogo.cn/g?b=qq&nk=${event.user_id}&s=640`,
|
|
343
|
+
},
|
|
344
|
+
message_id: this.createId(event.message_id),
|
|
345
|
+
raw_message: event.raw_message,
|
|
346
|
+
message: this.convertICQQMessageToSegments(event.message),
|
|
347
|
+
};
|
|
348
|
+
// 派发到协议层
|
|
349
|
+
account.dispatch(commonEvent);
|
|
350
|
+
});
|
|
351
|
+
// 监听群消息
|
|
352
|
+
bot.on('group_message', (event) => {
|
|
353
|
+
// 打印消息接收日志
|
|
354
|
+
const contentPreview = event.raw_message.length > 100
|
|
355
|
+
? event.raw_message.substring(0, 100) + '...'
|
|
356
|
+
: event.raw_message;
|
|
357
|
+
this.logger.info(`[ICQQ] 收到群消息 | 消息ID: ${event.message_id} | 群: ${event.group.group_name} (${event.group_id}) | ` +
|
|
358
|
+
`发送者: ${event.sender.nickname} (${event.user_id}) | 内容: ${contentPreview}`);
|
|
359
|
+
// 转换为 CommonEvent 格式
|
|
360
|
+
const commonEvent = {
|
|
361
|
+
id: this.createId(event.message_id),
|
|
362
|
+
timestamp: event.time * 1000,
|
|
363
|
+
platform: 'icqq',
|
|
364
|
+
bot_id: this.createId(config.account_id),
|
|
365
|
+
type: 'message',
|
|
366
|
+
message_type: 'group',
|
|
367
|
+
sender: {
|
|
368
|
+
id: this.createId(event.user_id.toString()),
|
|
369
|
+
name: event.sender.nickname,
|
|
370
|
+
avatar: `https://q1.qlogo.cn/g?b=qq&nk=${event.user_id}&s=640`,
|
|
371
|
+
},
|
|
372
|
+
group: {
|
|
373
|
+
id: this.createId(event.group_id.toString()),
|
|
374
|
+
name: event.group.group_name,
|
|
375
|
+
},
|
|
376
|
+
message_id: this.createId(event.message_id),
|
|
377
|
+
raw_message: event.raw_message,
|
|
378
|
+
message: this.convertICQQMessageToSegments(event.message),
|
|
379
|
+
};
|
|
380
|
+
// 派发到协议层
|
|
381
|
+
account.dispatch(commonEvent);
|
|
382
|
+
});
|
|
383
|
+
// 监听群成员增加
|
|
384
|
+
bot.on('group_increase', (event) => {
|
|
385
|
+
const noticeEvent = {
|
|
386
|
+
id: this.createId(`${event.group_id}_${event.user_id}_${event.time}`),
|
|
387
|
+
timestamp: event.time * 1000,
|
|
388
|
+
platform: 'icqq',
|
|
389
|
+
bot_id: this.createId(config.account_id),
|
|
390
|
+
type: 'notice',
|
|
391
|
+
notice_type: 'group_increase',
|
|
392
|
+
sub_type: event.operator_id === event.user_id ? 'approve' : 'invite',
|
|
393
|
+
group: {
|
|
394
|
+
id: this.createId(event.group_id.toString()),
|
|
395
|
+
},
|
|
396
|
+
user: {
|
|
397
|
+
id: this.createId(event.user_id.toString()),
|
|
398
|
+
},
|
|
399
|
+
operator: event.operator_id ? {
|
|
400
|
+
id: this.createId(event.operator_id.toString()),
|
|
401
|
+
} : undefined,
|
|
402
|
+
};
|
|
403
|
+
account.dispatch(noticeEvent);
|
|
404
|
+
});
|
|
405
|
+
// 监听群成员减少
|
|
406
|
+
bot.on('group_decrease', (event) => {
|
|
407
|
+
const noticeEvent = {
|
|
408
|
+
id: this.createId(`${event.group_id}_${event.user_id}_${event.time}`),
|
|
409
|
+
timestamp: event.time * 1000,
|
|
410
|
+
platform: 'icqq',
|
|
411
|
+
bot_id: this.createId(config.account_id),
|
|
412
|
+
type: 'notice',
|
|
413
|
+
notice_type: 'group_decrease',
|
|
414
|
+
sub_type: event.sub_type,
|
|
415
|
+
group: {
|
|
416
|
+
id: this.createId(event.group_id.toString()),
|
|
417
|
+
},
|
|
418
|
+
user: {
|
|
419
|
+
id: this.createId(event.user_id.toString()),
|
|
420
|
+
},
|
|
421
|
+
operator: event.operator_id ? {
|
|
422
|
+
id: this.createId(event.operator_id.toString()),
|
|
423
|
+
} : undefined,
|
|
424
|
+
};
|
|
425
|
+
account.dispatch(noticeEvent);
|
|
426
|
+
});
|
|
427
|
+
// 启动时初始化 Bot
|
|
428
|
+
account.on('start', async () => {
|
|
429
|
+
try {
|
|
430
|
+
await bot.start();
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
this.logger.error(`启动 ICQQ Bot 失败:`, error);
|
|
434
|
+
account.status = AccountStatus.OffLine;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
account.on('stop', async () => {
|
|
438
|
+
await bot.stop();
|
|
439
|
+
account.status = AccountStatus.OffLine;
|
|
440
|
+
});
|
|
441
|
+
return account;
|
|
442
|
+
}
|
|
443
|
+
// ============================================
|
|
444
|
+
// 消息转换
|
|
445
|
+
// ============================================
|
|
446
|
+
/**
|
|
447
|
+
* 构建 ICQQ 消息
|
|
448
|
+
*/
|
|
449
|
+
buildICQQMessage(message) {
|
|
450
|
+
const result = [];
|
|
451
|
+
for (const seg of message) {
|
|
452
|
+
if (typeof seg === 'string') {
|
|
453
|
+
result.push(seg);
|
|
454
|
+
}
|
|
455
|
+
else if (seg.type === 'text') {
|
|
456
|
+
result.push(seg.data.text || '');
|
|
457
|
+
}
|
|
458
|
+
else if (seg.type === 'at') {
|
|
459
|
+
const qq = seg.data.qq || seg.data.id || seg.data.user_id;
|
|
460
|
+
if (qq === 'all') {
|
|
461
|
+
result.push(segment.at('all'));
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
result.push(segment.at(parseInt(qq)));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else if (seg.type === 'image') {
|
|
468
|
+
const file = seg.data.url || seg.data.file;
|
|
469
|
+
if (file) {
|
|
470
|
+
result.push(segment.image(file));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
else if (seg.type === 'face') {
|
|
474
|
+
const id = seg.data.id;
|
|
475
|
+
if (id !== undefined) {
|
|
476
|
+
result.push(segment.face(parseInt(id)));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
else if (seg.type === 'record' || seg.type === 'audio') {
|
|
480
|
+
const file = seg.data.url || seg.data.file;
|
|
481
|
+
if (file) {
|
|
482
|
+
result.push(segment.record(file));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
else if (seg.type === 'video') {
|
|
486
|
+
const file = seg.data.url || seg.data.file;
|
|
487
|
+
if (file) {
|
|
488
|
+
result.push(segment.video(file));
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
else if (seg.type === 'reply') {
|
|
492
|
+
const id = seg.data.id;
|
|
493
|
+
if (id) {
|
|
494
|
+
result.push({ type: 'reply', id });
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
else if (seg.type === 'share') {
|
|
498
|
+
result.push(segment.share(seg.data.url || '', seg.data.title || '', seg.data.content, seg.data.image));
|
|
499
|
+
}
|
|
500
|
+
else if (seg.type === 'json') {
|
|
501
|
+
result.push(segment.json(seg.data.data || ''));
|
|
502
|
+
}
|
|
503
|
+
else if (seg.type === 'xml') {
|
|
504
|
+
result.push(segment.xml(seg.data.data || ''));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* 转换 ICQQ 消息到 Segment
|
|
511
|
+
*/
|
|
512
|
+
convertICQQMessageToSegments(message) {
|
|
513
|
+
const result = [];
|
|
514
|
+
for (const elem of message) {
|
|
515
|
+
switch (elem.type) {
|
|
516
|
+
case 'text':
|
|
517
|
+
result.push({ type: 'text', data: { text: elem.text } });
|
|
518
|
+
break;
|
|
519
|
+
case 'face':
|
|
520
|
+
result.push({ type: 'face', data: { id: elem.id.toString() } });
|
|
521
|
+
break;
|
|
522
|
+
case 'image':
|
|
523
|
+
result.push({ type: 'image', data: { url: elem.url || elem.file, file: elem.file } });
|
|
524
|
+
break;
|
|
525
|
+
case 'record':
|
|
526
|
+
result.push({ type: 'record', data: { url: elem.url || elem.file, file: elem.file } });
|
|
527
|
+
break;
|
|
528
|
+
case 'video':
|
|
529
|
+
result.push({ type: 'video', data: { url: elem.url || elem.file, file: elem.file } });
|
|
530
|
+
break;
|
|
531
|
+
case 'at':
|
|
532
|
+
result.push({ type: 'at', data: { qq: elem.qq.toString() } });
|
|
533
|
+
break;
|
|
534
|
+
case 'share':
|
|
535
|
+
result.push({ type: 'share', data: { url: elem.url, title: elem.title, content: elem.content, image: elem.image } });
|
|
536
|
+
break;
|
|
537
|
+
case 'json':
|
|
538
|
+
result.push({ type: 'json', data: { data: elem.data } });
|
|
539
|
+
break;
|
|
540
|
+
case 'xml':
|
|
541
|
+
result.push({ type: 'xml', data: { data: elem.data } });
|
|
542
|
+
break;
|
|
543
|
+
case 'reply':
|
|
544
|
+
result.push({ type: 'reply', data: { id: elem.id } });
|
|
545
|
+
break;
|
|
546
|
+
default:
|
|
547
|
+
result.push({ type: 'text', data: { text: `[${elem.type}]` } });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
AdapterRegistry.register('icqq', ICQQAdapter, {
|
|
554
|
+
name: 'icqq',
|
|
555
|
+
displayName: 'ICQQ 机器人',
|
|
556
|
+
description: '基于 ICQQ 协议的 QQ 机器人适配器,支持扫码登录和密码登录',
|
|
557
|
+
icon: 'https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png',
|
|
558
|
+
homepage: 'https://github.com/icqqjs/icqq',
|
|
559
|
+
author: '凉菜',
|
|
560
|
+
});
|
|
561
|
+
//# sourceMappingURL=adapter.js.map
|