@alemonjs/qq-bot 0.0.19 → 0.0.20
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 +6 -10
- package/lib/index.d.ts +2 -2
- package/lib/index.group.js +6 -203
- package/lib/index.guild.js +22 -297
- package/lib/index.js +40 -403
- package/lib/index.webhook.js +26 -0
- package/lib/register.d.ts +3 -0
- package/lib/register.js +405 -0
- package/lib/sdk/api.d.ts +5 -10
- package/lib/sdk/api.js +5 -10
- package/lib/sdk/client.websoket.js +221 -0
- package/lib/sdk/intents.js +12 -23
- package/package.json +1 -1
- package/lib/api.d.ts +0 -975
- package/lib/api.js +0 -1188
- package/lib/client.d.ts +0 -26
- package/lib/client.js +0 -212
- package/lib/config.js +0 -3
- package/lib/from.js +0 -37
- package/lib/message/AT_MESSAGE_CREATE.d.ts +0 -37
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/CHANNEL_CREATE.d.ts +0 -17
- package/lib/message/CHANNEL_DELETE.d.ts +0 -22
- package/lib/message/CHANNEL_UPDATE.d.ts +0 -22
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +0 -36
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +0 -24
- package/lib/message/ERROR.d.ts +0 -3
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +0 -16
- package/lib/message/GUILD_CREATE.d.ts +0 -22
- package/lib/message/GUILD_DELETE.d.ts +0 -22
- package/lib/message/GUILD_MEMBER_ADD.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +0 -21
- package/lib/message/GUILD_UPDATE.d.ts +0 -22
- package/lib/message/INTERACTION_CREATE.d.ts +0 -8
- package/lib/message/MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +0 -15
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +0 -15
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +0 -21
- package/lib/message/READY.d.ts +0 -11
- package/lib/message.d.ts +0 -49
- package/lib/typing.d.ts +0 -73
- package/lib/webhook.js +0 -51
- /package/lib/sdk/{websoket.group.js → client.websoket.group.js} +0 -0
- /package/lib/sdk/{websoket.guild.js → client.websoket.guild.js} +0 -0
package/README.md
CHANGED
|
@@ -22,28 +22,24 @@ qq-bot:
|
|
|
22
22
|
token: ''
|
|
23
23
|
# 密钥
|
|
24
24
|
secret: ''
|
|
25
|
-
# 模式(可选,置空将启用webhook模式)
|
|
26
|
-
mode: 'group'
|
|
27
25
|
```
|
|
28
26
|
|
|
29
|
-
> 默认使用
|
|
27
|
+
> 默认使用 1)websocket 模式,配置 route 可选择 webhook 模式
|
|
30
28
|
|
|
31
|
-
> 配置 webhook 需 ip
|
|
29
|
+
> 配置 webhook 需 ip/域名,一旦生效官方将禁用 websocket 模式
|
|
32
30
|
|
|
33
31
|
```sh
|
|
34
32
|
qq-bot:
|
|
35
|
-
master_key:
|
|
36
|
-
- ''
|
|
37
33
|
# 频道沙盒,默认false
|
|
38
34
|
sandbox: false
|
|
39
35
|
# 1)websocket 模式
|
|
40
|
-
# mode: 'all' # 暂未支持
|
|
41
36
|
# mode: 'guild'
|
|
42
|
-
mode: 'group'
|
|
37
|
+
# mode: 'group'
|
|
43
38
|
# 2)webhook 模式
|
|
44
39
|
# 推荐nginx进行代理 http://localhost:17157/webhook
|
|
45
|
-
#
|
|
46
|
-
|
|
40
|
+
# 填写将启动 webhook模式
|
|
41
|
+
port: 17157
|
|
42
|
+
route: '/webhook'
|
|
47
43
|
# 当配置ws的时候,会连接另一台webhook机器人的消息。不会再启动本地端口。
|
|
48
44
|
# 假设代理后的地址为 https://qqbotjs.com
|
|
49
45
|
# ws: 'wss://qqbotjs.com/websocket'
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as alemonjs from 'alemonjs';
|
|
2
2
|
import { QQBotAPI } from './sdk/api.js';
|
|
3
|
+
export { platform } from './register.js';
|
|
3
4
|
export { useMode } from './hook.js';
|
|
4
5
|
|
|
5
6
|
type Client = typeof QQBotAPI.prototype;
|
|
6
7
|
declare const client: Client;
|
|
7
|
-
declare const platform = "qq-bot";
|
|
8
8
|
|
|
9
9
|
declare const _default: alemonjs.DefinePlatformValue;
|
|
10
10
|
|
|
11
|
-
export { type Client, client, _default as default
|
|
11
|
+
export { type Client, client, _default as default };
|
package/lib/index.group.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { getConfigValue
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isGuild } from './utils.js';
|
|
1
|
+
import { getConfigValue } from 'alemonjs';
|
|
2
|
+
import { QQBotGroupClient } from './sdk/client.websoket.group.js';
|
|
3
|
+
import { platform, register, createClientAPI } from './register.js';
|
|
5
4
|
|
|
6
|
-
const platform = 'qq-bot';
|
|
7
5
|
var QQBotGroup = definePlatform(() => {
|
|
8
6
|
let value = getConfigValue();
|
|
9
7
|
if (!value)
|
|
@@ -22,205 +20,10 @@ var QQBotGroup = definePlatform(() => {
|
|
|
22
20
|
});
|
|
23
21
|
// 连接
|
|
24
22
|
client.connect(config?.gatewayURL);
|
|
25
|
-
|
|
26
|
-
* group
|
|
27
|
-
*
|
|
28
|
-
* GROUP_AT_MESSAGE_CREATE
|
|
29
|
-
* C2C_MESSAGE_CREATE
|
|
30
|
-
*/
|
|
31
|
-
// 监听消息
|
|
32
|
-
client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
|
|
33
|
-
const master_key = config?.master_key ?? [];
|
|
34
|
-
const isMaster = master_key.includes(event.author.id);
|
|
35
|
-
const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`;
|
|
36
|
-
const UserAvatar = {
|
|
37
|
-
toBuffer: async () => {
|
|
38
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
39
|
-
return Buffer.from(arrayBuffer);
|
|
40
|
-
},
|
|
41
|
-
toBase64: async () => {
|
|
42
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
43
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
44
|
-
},
|
|
45
|
-
toURL: async () => {
|
|
46
|
-
return url;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const UserId = event.author.id;
|
|
50
|
-
const UserKey = useUserHashKey({
|
|
51
|
-
Platform: platform,
|
|
52
|
-
UserId: UserId
|
|
53
|
-
});
|
|
54
|
-
// 定义消
|
|
55
|
-
const e = {
|
|
56
|
-
name: 'message.create',
|
|
57
|
-
// 事件类型
|
|
58
|
-
Platform: platform,
|
|
59
|
-
// guild
|
|
60
|
-
GuildId: event.group_id,
|
|
61
|
-
ChannelId: event.group_id,
|
|
62
|
-
// 用户Id
|
|
63
|
-
UserId: event.author.id,
|
|
64
|
-
UserKey,
|
|
65
|
-
UserAvatar: UserAvatar,
|
|
66
|
-
IsMaster: isMaster,
|
|
67
|
-
IsBot: false,
|
|
68
|
-
// 格式化数据
|
|
69
|
-
MessageId: event.id,
|
|
70
|
-
MessageText: event.content?.trim(),
|
|
71
|
-
OpenId: event.author.member_openid,
|
|
72
|
-
CreateAt: Date.now(),
|
|
73
|
-
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
74
|
-
value: null
|
|
75
|
-
};
|
|
76
|
-
// 处理消息
|
|
77
|
-
onProcessor('message.create', e, event);
|
|
78
|
-
});
|
|
79
|
-
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
80
|
-
const master_key = config?.master_key ?? [];
|
|
81
|
-
const isMaster = master_key.includes(event.author.id);
|
|
82
|
-
const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`;
|
|
83
|
-
const UserAvatar = {
|
|
84
|
-
toBuffer: async () => {
|
|
85
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
86
|
-
return Buffer.from(arrayBuffer);
|
|
87
|
-
},
|
|
88
|
-
toBase64: async () => {
|
|
89
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
90
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
91
|
-
},
|
|
92
|
-
toURL: async () => {
|
|
93
|
-
return url;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const UserId = event.author.id;
|
|
97
|
-
const UserKey = useUserHashKey({
|
|
98
|
-
Platform: platform,
|
|
99
|
-
UserId: UserId
|
|
100
|
-
});
|
|
101
|
-
// 定义消
|
|
102
|
-
const e = {
|
|
103
|
-
name: 'private.message.create',
|
|
104
|
-
// 事件类型
|
|
105
|
-
Platform: platform,
|
|
106
|
-
// 用户Id
|
|
107
|
-
UserId: event.author.id,
|
|
108
|
-
UserKey,
|
|
109
|
-
UserAvatar: UserAvatar,
|
|
110
|
-
IsMaster: isMaster,
|
|
111
|
-
IsBot: false,
|
|
112
|
-
// 格式化数据
|
|
113
|
-
MessageId: event.id,
|
|
114
|
-
MessageText: event.content?.trim(),
|
|
115
|
-
CreateAt: Date.now(),
|
|
116
|
-
OpenId: event.author.user_openid,
|
|
117
|
-
//
|
|
118
|
-
tag: 'C2C_MESSAGE_CREATE',
|
|
119
|
-
value: null
|
|
120
|
-
};
|
|
121
|
-
// 处理消息
|
|
122
|
-
onProcessor('private.message.create', e, event);
|
|
123
|
-
});
|
|
124
|
-
client.on('ERROR', console.error);
|
|
23
|
+
register(client);
|
|
125
24
|
// FRIEND_ADD
|
|
126
25
|
global.client = client;
|
|
127
|
-
return
|
|
128
|
-
platform,
|
|
129
|
-
api: {
|
|
130
|
-
// 主动消息
|
|
131
|
-
active: {
|
|
132
|
-
send: {
|
|
133
|
-
channel: async (channel_id, data) => {
|
|
134
|
-
if (isGuild(channel_id)) {
|
|
135
|
-
return await AT_MESSAGE_CREATE(client, {
|
|
136
|
-
ChannelId: channel_id
|
|
137
|
-
}, data);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
// 需要message_id 。如果没有,则是主动消息,在group中,只能发送4条。
|
|
141
|
-
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
142
|
-
GuildId: channel_id
|
|
143
|
-
}, data);
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
user: async (user_id, data) => {
|
|
147
|
-
if (isGuild(user_id)) {
|
|
148
|
-
return await DIRECT_MESSAGE_CREATE(client, {
|
|
149
|
-
OpenId: user_id
|
|
150
|
-
}, data);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
154
|
-
OpenId: user_id
|
|
155
|
-
}, data);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
use: {
|
|
161
|
-
send: async (event, val) => {
|
|
162
|
-
if (val.length < 0)
|
|
163
|
-
;
|
|
164
|
-
// 打 tag
|
|
165
|
-
const tag = event.tag;
|
|
166
|
-
try {
|
|
167
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
168
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
169
|
-
}
|
|
170
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
171
|
-
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
172
|
-
}
|
|
173
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
174
|
-
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
175
|
-
}
|
|
176
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
177
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
178
|
-
}
|
|
179
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
180
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
181
|
-
}
|
|
182
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
183
|
-
return await MESSAGE_CREATE(client, event, val);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
return [error];
|
|
188
|
-
}
|
|
189
|
-
return [];
|
|
190
|
-
},
|
|
191
|
-
mention: async (e) => {
|
|
192
|
-
const event = e.value;
|
|
193
|
-
const tag = e.tag;
|
|
194
|
-
// const event = e.value
|
|
195
|
-
const Metions = [];
|
|
196
|
-
// group
|
|
197
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE' || 'C2C_MESSAGE_CREATE')
|
|
198
|
-
return Metions;
|
|
199
|
-
// guild
|
|
200
|
-
if (event.mentions) {
|
|
201
|
-
const mentions = e.value['mentions'];
|
|
202
|
-
// 艾特消息处理
|
|
203
|
-
const MessageMention = mentions.map(item => {
|
|
204
|
-
return {
|
|
205
|
-
UserId: item.id,
|
|
206
|
-
IsMaster: false,
|
|
207
|
-
UserName: item.username,
|
|
208
|
-
IsBot: item.bot,
|
|
209
|
-
UserKey: useUserHashKey({
|
|
210
|
-
Platform: 'qq-guild-bot',
|
|
211
|
-
UserId: item.id
|
|
212
|
-
})
|
|
213
|
-
};
|
|
214
|
-
}) ?? [];
|
|
215
|
-
return MessageMention;
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
return Metions;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
26
|
+
return createClientAPI(client);
|
|
224
27
|
});
|
|
225
28
|
|
|
226
|
-
export { QQBotGroup as default
|
|
29
|
+
export { QQBotGroup as default };
|
package/lib/index.guild.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getConfigValue
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { getConfigValue } from 'alemonjs';
|
|
2
|
+
import { register } from 'module';
|
|
3
|
+
import { platform, createClientAPI } from './register.js';
|
|
4
|
+
import { QQBotGuildClient } from './sdk/client.websoket.guild.js';
|
|
5
5
|
|
|
6
|
-
const platform = 'qq-bot';
|
|
7
6
|
var QQBotGuild = definePlatform(() => {
|
|
8
7
|
let value = getConfigValue();
|
|
9
8
|
if (!value)
|
|
@@ -12,12 +11,21 @@ var QQBotGuild = definePlatform(() => {
|
|
|
12
11
|
// intents 需要默认值
|
|
13
12
|
const client = new QQBotGuildClient({
|
|
14
13
|
app_id: config?.app_id,
|
|
15
|
-
intents: config?.intents ?? [
|
|
16
|
-
'GUILDS',
|
|
17
|
-
'GUILD_MEMBERS',
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
14
|
+
intents: config?.intents ?? config?.is_private ? [
|
|
15
|
+
'GUILDS', // base
|
|
16
|
+
'GUILD_MEMBERS', // base
|
|
17
|
+
'GUILD_MESSAGES',
|
|
18
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
19
|
+
'DIRECT_MESSAGE',
|
|
20
|
+
'INTERACTION',
|
|
21
|
+
'FORUMS_EVENT',
|
|
22
|
+
] : [
|
|
23
|
+
'GUILDS', // base
|
|
24
|
+
'GUILD_MEMBERS', // base
|
|
25
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
26
|
+
'DIRECT_MESSAGE',
|
|
27
|
+
'INTERACTION',
|
|
28
|
+
'PUBLIC_GUILD_MESSAGES',
|
|
21
29
|
],
|
|
22
30
|
is_private: config?.is_private ?? false,
|
|
23
31
|
sandbox: config?.sandbox ?? false,
|
|
@@ -28,293 +36,10 @@ var QQBotGuild = definePlatform(() => {
|
|
|
28
36
|
});
|
|
29
37
|
// 连接
|
|
30
38
|
client.connect(config?.gatewayURL);
|
|
31
|
-
|
|
32
|
-
* guild
|
|
33
|
-
*/
|
|
34
|
-
client.on('DIRECT_MESSAGE_CREATE', async (event) => {
|
|
35
|
-
// 屏蔽其他机器人的消息
|
|
36
|
-
if (event?.author?.bot)
|
|
37
|
-
return;
|
|
38
|
-
const master_key = config?.master_key ?? [];
|
|
39
|
-
const isMaster = master_key.includes(event.author.id);
|
|
40
|
-
let msg = event?.content ?? '';
|
|
41
|
-
const UserAvatar = {
|
|
42
|
-
toBuffer: async () => {
|
|
43
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
44
|
-
return Buffer.from(arrayBuffer);
|
|
45
|
-
},
|
|
46
|
-
toBase64: async () => {
|
|
47
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
48
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
49
|
-
},
|
|
50
|
-
toURL: async () => {
|
|
51
|
-
return event?.author?.avatar;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const UserId = event.author.id;
|
|
55
|
-
const UserKey = useUserHashKey({
|
|
56
|
-
Platform: platform,
|
|
57
|
-
UserId: UserId
|
|
58
|
-
});
|
|
59
|
-
// 定义消
|
|
60
|
-
const e = {
|
|
61
|
-
name: 'private.message.create',
|
|
62
|
-
// 事件类型
|
|
63
|
-
Platform: platform,
|
|
64
|
-
//
|
|
65
|
-
// GuildId: event.guild_id,
|
|
66
|
-
// ChannelId: event.channel_id,
|
|
67
|
-
// 用户Id
|
|
68
|
-
UserId: event?.author?.id ?? '',
|
|
69
|
-
UserKey,
|
|
70
|
-
UserName: event?.author?.username ?? '',
|
|
71
|
-
UserAvatar: UserAvatar,
|
|
72
|
-
IsMaster: isMaster,
|
|
73
|
-
IsBot: event.author?.bot,
|
|
74
|
-
// message
|
|
75
|
-
MessageId: event.id,
|
|
76
|
-
MessageText: msg?.trim(),
|
|
77
|
-
OpenId: event.guild_id,
|
|
78
|
-
CreateAt: Date.now(),
|
|
79
|
-
//
|
|
80
|
-
tag: 'DIRECT_MESSAGE_CREATE',
|
|
81
|
-
//
|
|
82
|
-
value: null
|
|
83
|
-
};
|
|
84
|
-
// 处理消息
|
|
85
|
-
onProcessor('private.message.create', e, event);
|
|
86
|
-
});
|
|
87
|
-
// 监听消息
|
|
88
|
-
client.on('AT_MESSAGE_CREATE', async (event) => {
|
|
89
|
-
// 屏蔽其他机器人的消息
|
|
90
|
-
if (event?.author?.bot)
|
|
91
|
-
return;
|
|
92
|
-
const master_key = config?.master_key ?? [];
|
|
93
|
-
const isMaster = master_key.includes(event.author.id);
|
|
94
|
-
let msg = getMessageContent(event);
|
|
95
|
-
const UserAvatar = {
|
|
96
|
-
toBuffer: async () => {
|
|
97
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
98
|
-
return Buffer.from(arrayBuffer);
|
|
99
|
-
},
|
|
100
|
-
toBase64: async () => {
|
|
101
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
102
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
103
|
-
},
|
|
104
|
-
toURL: async () => {
|
|
105
|
-
return event?.author?.avatar;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const UserId = event.author.id;
|
|
109
|
-
const UserKey = useUserHashKey({
|
|
110
|
-
Platform: platform,
|
|
111
|
-
UserId: UserId
|
|
112
|
-
});
|
|
113
|
-
// 定义消
|
|
114
|
-
const e = {
|
|
115
|
-
name: 'message.create',
|
|
116
|
-
// 事件类型
|
|
117
|
-
Platform: platform,
|
|
118
|
-
GuildId: event.guild_id,
|
|
119
|
-
ChannelId: event.channel_id,
|
|
120
|
-
IsMaster: isMaster,
|
|
121
|
-
// 用户Id
|
|
122
|
-
UserId: event?.author?.id ?? '',
|
|
123
|
-
UserKey,
|
|
124
|
-
UserName: event?.author?.username ?? '',
|
|
125
|
-
UserAvatar: UserAvatar,
|
|
126
|
-
IsBot: event.author?.bot,
|
|
127
|
-
// message
|
|
128
|
-
MessageId: event.id,
|
|
129
|
-
MessageText: msg?.trim(),
|
|
130
|
-
OpenId: event.guild_id,
|
|
131
|
-
CreateAt: Date.now(),
|
|
132
|
-
//
|
|
133
|
-
tag: 'AT_MESSAGE_CREATE',
|
|
134
|
-
//
|
|
135
|
-
value: null
|
|
136
|
-
};
|
|
137
|
-
// 处理消息
|
|
138
|
-
onProcessor('message.create', e, event);
|
|
139
|
-
});
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
* @param event
|
|
143
|
-
* @returns
|
|
144
|
-
*/
|
|
145
|
-
const getMessageContent = event => {
|
|
146
|
-
let msg = event?.content ?? '';
|
|
147
|
-
// 艾特消息处理
|
|
148
|
-
const at_users = [];
|
|
149
|
-
if (event.mentions) {
|
|
150
|
-
// 去掉@ 转为纯消息
|
|
151
|
-
for (const item of event.mentions) {
|
|
152
|
-
at_users.push({
|
|
153
|
-
id: item.id
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
// 循环删除文本中的at信息并去除前后空格
|
|
157
|
-
at_users.forEach(item => {
|
|
158
|
-
msg = msg.replace(`<@!${item.id}>`, '').trim();
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
return msg;
|
|
162
|
-
};
|
|
163
|
-
// 私域 -
|
|
164
|
-
client.on('MESSAGE_CREATE', async (event) => {
|
|
165
|
-
// 屏蔽其他机器人的消息
|
|
166
|
-
if (event.author?.bot)
|
|
167
|
-
return;
|
|
168
|
-
// 撤回消息
|
|
169
|
-
if (new RegExp(/DELETE$/).test(event.eventType))
|
|
170
|
-
return;
|
|
171
|
-
const master_key = config?.master_key ?? [];
|
|
172
|
-
const UserId = event.author.id;
|
|
173
|
-
const isMaster = master_key.includes(UserId);
|
|
174
|
-
const msg = getMessageContent(event);
|
|
175
|
-
const UserAvatar = {
|
|
176
|
-
toBuffer: async () => {
|
|
177
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
178
|
-
return Buffer.from(arrayBuffer);
|
|
179
|
-
},
|
|
180
|
-
toBase64: async () => {
|
|
181
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
182
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
183
|
-
},
|
|
184
|
-
toURL: async () => {
|
|
185
|
-
return event?.author?.avatar;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const UserKey = useUserHashKey({
|
|
189
|
-
Platform: platform,
|
|
190
|
-
UserId: UserId
|
|
191
|
-
});
|
|
192
|
-
// 定义消
|
|
193
|
-
const e = {
|
|
194
|
-
name: 'message.create',
|
|
195
|
-
// 事件类型
|
|
196
|
-
Platform: platform,
|
|
197
|
-
//
|
|
198
|
-
GuildId: event.guild_id,
|
|
199
|
-
ChannelId: event.channel_id,
|
|
200
|
-
UserId: event?.author?.id ?? '',
|
|
201
|
-
UserKey,
|
|
202
|
-
UserName: event?.author?.username ?? '',
|
|
203
|
-
UserAvatar: UserAvatar,
|
|
204
|
-
IsMaster: isMaster,
|
|
205
|
-
IsBot: false,
|
|
206
|
-
// message
|
|
207
|
-
MessageId: event.id,
|
|
208
|
-
MessageText: msg?.trim(),
|
|
209
|
-
OpenId: event.guild_id,
|
|
210
|
-
CreateAt: Date.now(),
|
|
211
|
-
//
|
|
212
|
-
tag: 'MESSAGE_CREATE',
|
|
213
|
-
value: null
|
|
214
|
-
};
|
|
215
|
-
// 处理消息
|
|
216
|
-
onProcessor('message.create', e, event);
|
|
217
|
-
});
|
|
218
|
-
client.on('ERROR', console.error);
|
|
39
|
+
register(client);
|
|
219
40
|
// FRIEND_ADD
|
|
220
41
|
global.client = client;
|
|
221
|
-
return
|
|
222
|
-
platform,
|
|
223
|
-
api: {
|
|
224
|
-
// 主动消息
|
|
225
|
-
active: {
|
|
226
|
-
send: {
|
|
227
|
-
channel: async (channel_id, data) => {
|
|
228
|
-
if (isGuild(channel_id)) {
|
|
229
|
-
return await AT_MESSAGE_CREATE(client, {
|
|
230
|
-
ChannelId: channel_id
|
|
231
|
-
}, data);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
// 需要message_id 。如果没有,则是主动消息,在group中,只能发送4条。
|
|
235
|
-
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
236
|
-
GuildId: channel_id
|
|
237
|
-
}, data);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
user: async (user_id, data) => {
|
|
241
|
-
if (isGuild(user_id)) {
|
|
242
|
-
return await DIRECT_MESSAGE_CREATE(client, {
|
|
243
|
-
OpenId: user_id
|
|
244
|
-
}, data);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
248
|
-
OpenId: user_id
|
|
249
|
-
}, data);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
use: {
|
|
255
|
-
send: async (event, val) => {
|
|
256
|
-
if (val.length < 0)
|
|
257
|
-
;
|
|
258
|
-
// 打 tag
|
|
259
|
-
const tag = event.tag;
|
|
260
|
-
try {
|
|
261
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
262
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
263
|
-
}
|
|
264
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
265
|
-
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
266
|
-
}
|
|
267
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
268
|
-
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
269
|
-
}
|
|
270
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
271
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
272
|
-
}
|
|
273
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
274
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
275
|
-
}
|
|
276
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
277
|
-
return await MESSAGE_CREATE(client, event, val);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (error) {
|
|
281
|
-
return [error];
|
|
282
|
-
}
|
|
283
|
-
return [];
|
|
284
|
-
},
|
|
285
|
-
mention: async (e) => {
|
|
286
|
-
const event = e.value;
|
|
287
|
-
const tag = e.tag;
|
|
288
|
-
// const event = e.value
|
|
289
|
-
const Metions = [];
|
|
290
|
-
// group
|
|
291
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE' || 'C2C_MESSAGE_CREATE')
|
|
292
|
-
return Metions;
|
|
293
|
-
// guild
|
|
294
|
-
if (event.mentions) {
|
|
295
|
-
const mentions = e.value['mentions'];
|
|
296
|
-
// 艾特消息处理
|
|
297
|
-
const MessageMention = mentions.map(item => {
|
|
298
|
-
return {
|
|
299
|
-
UserId: item.id,
|
|
300
|
-
IsMaster: false,
|
|
301
|
-
UserName: item.username,
|
|
302
|
-
IsBot: item.bot,
|
|
303
|
-
UserKey: useUserHashKey({
|
|
304
|
-
Platform: 'qq-guild-bot',
|
|
305
|
-
UserId: item.id
|
|
306
|
-
})
|
|
307
|
-
};
|
|
308
|
-
}) ?? [];
|
|
309
|
-
return MessageMention;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
return Metions;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
};
|
|
42
|
+
return createClientAPI(client);
|
|
318
43
|
});
|
|
319
44
|
|
|
320
|
-
export { QQBotGuild as default
|
|
45
|
+
export { QQBotGuild as default };
|