@alemonjs/qq-bot 0.0.12 → 0.0.14
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 +27 -12
- package/dist/assets/index.css +472 -1
- package/dist/assets/index.js +11002 -14
- package/dist/index.html +1 -1
- package/lib/api.d.ts +971 -843
- package/lib/api.js +1172 -1156
- package/lib/client.d.ts +22 -22
- package/lib/client.js +201 -217
- package/lib/config.js +2 -2
- package/lib/desktop.js +3 -1
- package/lib/from.js +27 -34
- package/lib/index.d.ts +3 -3
- package/lib/index.group.js +226 -0
- package/lib/index.guild.js +320 -0
- package/lib/index.js +59 -38
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -35
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +9 -9
- package/lib/message/CHANNEL_CREATE.d.ts +15 -15
- package/lib/message/CHANNEL_DELETE.d.ts +15 -15
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -15
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -29
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -17
- package/lib/message/ERROR.d.ts +2 -2
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +10 -10
- package/lib/message/GUILD_CREATE.d.ts +15 -15
- package/lib/message/GUILD_DELETE.d.ts +15 -15
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -14
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -14
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -14
- package/lib/message/GUILD_UPDATE.d.ts +15 -15
- package/lib/message/INTERACTION_CREATE.d.ts +2 -2
- package/lib/message/MESSAGE_CREATE.d.ts +2 -2
- package/lib/message/MESSAGE_DELETE.d.ts +2 -2
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -13
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -13
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -15
- package/lib/message/READY.d.ts +6 -6
- package/lib/message.d.ts +46 -46
- package/lib/sdk/api.d.ts +847 -0
- package/lib/sdk/api.js +1184 -0
- package/lib/sdk/client.js +228 -0
- package/lib/sdk/config.js +3 -0
- package/lib/sdk/counter.js +19 -0
- package/lib/sdk/from.js +44 -0
- package/lib/sdk/intents.js +102 -0
- package/lib/sdk/typing.d.ts +56 -0
- package/lib/sdk/webhook.secret.js +53 -0
- package/lib/sdk/websoket.group.js +221 -0
- package/lib/sdk/websoket.guild.js +203 -0
- package/lib/send/index.js +97 -21
- package/lib/typing.d.ts +62 -54
- package/lib/utils.js +14 -0
- package/lib/webhook.js +46 -48
- package/package.json +4 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
|
+
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
3
|
+
import { QQBotGroupClient } from './sdk/websoket.group.js';
|
|
4
|
+
import { isGuild } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const platform = 'qq-bot';
|
|
7
|
+
var QQBotGroup = defineBot(() => {
|
|
8
|
+
let value = getConfigValue();
|
|
9
|
+
if (!value)
|
|
10
|
+
value = {};
|
|
11
|
+
const config = value[platform];
|
|
12
|
+
// intents 需要默认值
|
|
13
|
+
const client = new QQBotGroupClient({
|
|
14
|
+
app_id: config?.app_id,
|
|
15
|
+
intents: config?.intents ?? ['GROUP_AND_C2C_EVENT'],
|
|
16
|
+
is_private: config?.is_private,
|
|
17
|
+
sandbox: config?.sandbox,
|
|
18
|
+
secret: config?.secret,
|
|
19
|
+
shard: config?.shard,
|
|
20
|
+
token: config?.token,
|
|
21
|
+
mode: config?.mode
|
|
22
|
+
});
|
|
23
|
+
// 连接
|
|
24
|
+
client.connect();
|
|
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);
|
|
125
|
+
// FRIEND_ADD
|
|
126
|
+
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
|
+
};
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
export { QQBotGroup as default, platform };
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
|
+
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
3
|
+
import { QQBotGuildClient } from './sdk/websoket.guild.js';
|
|
4
|
+
import { isGuild } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const platform = 'qq-bot';
|
|
7
|
+
var QQBotGuild = defineBot(() => {
|
|
8
|
+
let value = getConfigValue();
|
|
9
|
+
if (!value)
|
|
10
|
+
value = {};
|
|
11
|
+
const config = value[platform];
|
|
12
|
+
// intents 需要默认值
|
|
13
|
+
const client = new QQBotGuildClient({
|
|
14
|
+
app_id: config?.app_id,
|
|
15
|
+
intents: config?.intents ?? [
|
|
16
|
+
'GUILDS', //频道进出
|
|
17
|
+
'GUILD_MEMBERS', //成员资料
|
|
18
|
+
'DIRECT_MESSAGE', //私信
|
|
19
|
+
'PUBLIC_GUILD_MESSAGES', //公域事件
|
|
20
|
+
'REACTIONS' // 表情表态
|
|
21
|
+
],
|
|
22
|
+
is_private: config?.is_private,
|
|
23
|
+
sandbox: config?.sandbox,
|
|
24
|
+
secret: config?.secret,
|
|
25
|
+
shard: config?.shard,
|
|
26
|
+
token: config?.token,
|
|
27
|
+
mode: config?.mode
|
|
28
|
+
});
|
|
29
|
+
// 连接
|
|
30
|
+
client.connect();
|
|
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);
|
|
219
|
+
// FRIEND_ADD
|
|
220
|
+
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
|
+
};
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
export { QQBotGuild as default, platform };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey,
|
|
2
|
-
import { QQBotClient } from './client.js';
|
|
3
|
-
import {
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
|
+
import { QQBotClient } from './sdk/client.js';
|
|
3
|
+
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
4
|
+
import QQBotGroup from './index.group.js';
|
|
5
|
+
import QQBotGuild from './index.guild.js';
|
|
6
|
+
import { isGuild } from './utils.js';
|
|
4
7
|
|
|
5
8
|
const client = new Proxy({}, {
|
|
6
9
|
get: (_, prop) => {
|
|
@@ -18,6 +21,22 @@ var index = defineBot(() => {
|
|
|
18
21
|
if (!value)
|
|
19
22
|
value = {};
|
|
20
23
|
const config = value[platform];
|
|
24
|
+
if (config.mode == 'guild') {
|
|
25
|
+
if (typeof QQBotGuild.callback == 'function') {
|
|
26
|
+
return QQBotGuild.callback();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return QQBotGuild.callback;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (config.mode == 'group') {
|
|
33
|
+
if (typeof QQBotGroup.callback == 'function') {
|
|
34
|
+
return QQBotGroup.callback();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return QQBotGroup.callback;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
21
40
|
const client = new QQBotClient({
|
|
22
41
|
secret: config?.secret,
|
|
23
42
|
app_id: config?.app_id,
|
|
@@ -79,14 +98,8 @@ var index = defineBot(() => {
|
|
|
79
98
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
80
99
|
value: null
|
|
81
100
|
};
|
|
82
|
-
// 当访问的时候获取
|
|
83
|
-
Object.defineProperty(e, 'value', {
|
|
84
|
-
get() {
|
|
85
|
-
return event;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
101
|
// 处理消息
|
|
89
|
-
|
|
102
|
+
onProcessor('message.create', e, event);
|
|
90
103
|
});
|
|
91
104
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
92
105
|
const master_key = config?.master_key ?? [];
|
|
@@ -130,14 +143,8 @@ var index = defineBot(() => {
|
|
|
130
143
|
tag: 'C2C_MESSAGE_CREATE',
|
|
131
144
|
value: null
|
|
132
145
|
};
|
|
133
|
-
// 当访问的时候获取
|
|
134
|
-
Object.defineProperty(e, 'value', {
|
|
135
|
-
get() {
|
|
136
|
-
return event;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
146
|
// 处理消息
|
|
140
|
-
|
|
147
|
+
onProcessor('private.message.create', e, event);
|
|
141
148
|
});
|
|
142
149
|
/**
|
|
143
150
|
* guild
|
|
@@ -192,14 +199,8 @@ var index = defineBot(() => {
|
|
|
192
199
|
//
|
|
193
200
|
value: null
|
|
194
201
|
};
|
|
195
|
-
// 当访问的时候获取
|
|
196
|
-
Object.defineProperty(e, 'value', {
|
|
197
|
-
get() {
|
|
198
|
-
return event;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
202
|
// 处理消息
|
|
202
|
-
|
|
203
|
+
onProcessor('private.message.create', e, event);
|
|
203
204
|
});
|
|
204
205
|
// 监听消息
|
|
205
206
|
client.on('AT_MESSAGE_CREATE', async (event) => {
|
|
@@ -251,14 +252,8 @@ var index = defineBot(() => {
|
|
|
251
252
|
//
|
|
252
253
|
value: null
|
|
253
254
|
};
|
|
254
|
-
// 当访问的时候获取
|
|
255
|
-
Object.defineProperty(e, 'value', {
|
|
256
|
-
get() {
|
|
257
|
-
return event;
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
255
|
// 处理消息
|
|
261
|
-
|
|
256
|
+
onProcessor('message.create', e, event);
|
|
262
257
|
});
|
|
263
258
|
/**
|
|
264
259
|
*
|
|
@@ -335,20 +330,46 @@ var index = defineBot(() => {
|
|
|
335
330
|
tag: 'MESSAGE_CREATE',
|
|
336
331
|
value: null
|
|
337
332
|
};
|
|
338
|
-
// 当访问的时候获取
|
|
339
|
-
Object.defineProperty(e, 'value', {
|
|
340
|
-
get() {
|
|
341
|
-
return event;
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
333
|
// 处理消息
|
|
345
|
-
|
|
334
|
+
onProcessor('message.create', e, event);
|
|
346
335
|
});
|
|
347
336
|
client.on('ERROR', console.error);
|
|
348
337
|
// FRIEND_ADD
|
|
349
338
|
global.client = client;
|
|
350
339
|
return {
|
|
340
|
+
platform,
|
|
351
341
|
api: {
|
|
342
|
+
// 主动消息
|
|
343
|
+
active: {
|
|
344
|
+
send: {
|
|
345
|
+
channel: async (channel_id, data) => {
|
|
346
|
+
if (isGuild(channel_id)) {
|
|
347
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
348
|
+
ChannelId: channel_id
|
|
349
|
+
}, data);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
// 需要message_id 。如果没有,则是主动消息,在group中,只能发送4条。
|
|
353
|
+
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
354
|
+
GuildId: channel_id
|
|
355
|
+
}, data);
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
user: async (user_id, data) => {
|
|
359
|
+
if (isGuild(user_id)) {
|
|
360
|
+
return await DIRECT_MESSAGE_CREATE(client, {
|
|
361
|
+
OpenId: user_id
|
|
362
|
+
}, data);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
return await C2C_MESSAGE_CREATE(client, {
|
|
366
|
+
OpenId: user_id
|
|
367
|
+
}, data);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
// 被动消息
|
|
352
373
|
use: {
|
|
353
374
|
send: async (event, val) => {
|
|
354
375
|
if (val.length < 0)
|