@alemonjs/onebot 2.1.0-alpha.0 → 2.1.0-alpha.2
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 -0
- package/lib/config.js +13 -2
- package/lib/index.js +31 -39
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/config.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { getConfigValue } from 'alemonjs';
|
|
1
|
+
import { getConfigValue, useUserHashKey } from 'alemonjs';
|
|
2
2
|
|
|
3
3
|
const platform = 'onebot';
|
|
4
4
|
const getOneBotConfig = () => {
|
|
5
5
|
const value = getConfigValue() || {};
|
|
6
6
|
return value[platform] || {};
|
|
7
7
|
};
|
|
8
|
+
const getMaster = (UserId) => {
|
|
9
|
+
const config = getOneBotConfig();
|
|
10
|
+
const master_key = config.master_key || [];
|
|
11
|
+
const master_id = config.master_id || [];
|
|
12
|
+
const UserKey = useUserHashKey({
|
|
13
|
+
Platform: platform,
|
|
14
|
+
UserId: UserId
|
|
15
|
+
});
|
|
16
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
17
|
+
return [is, UserKey];
|
|
18
|
+
};
|
|
8
19
|
|
|
9
|
-
export { getOneBotConfig, platform };
|
|
20
|
+
export { getMaster, getOneBotConfig, platform };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { cbpPlatform,
|
|
1
|
+
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { getBufferByURL } from 'alemonjs/utils';
|
|
3
3
|
import { OneBotClient } from './sdk/wss.js';
|
|
4
4
|
import { readFileSync } from 'fs';
|
|
5
|
-
import { getOneBotConfig, platform } from './config.js';
|
|
5
|
+
import { getOneBotConfig, getMaster, platform } from './config.js';
|
|
6
6
|
export { OneBotAPI as API } from './sdk/api.js';
|
|
7
7
|
|
|
8
8
|
const MyBot = {
|
|
@@ -40,14 +40,10 @@ var index = () => {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
client.on('MESSAGES', event => {
|
|
43
|
-
const uis = config?.master_id ?? [];
|
|
44
43
|
const msg = getMessageText(event.message);
|
|
45
44
|
const UserId = String(event.user_id);
|
|
46
45
|
const UserAvatar = createUserAvatar(UserId);
|
|
47
|
-
const UserKey =
|
|
48
|
-
Platform: platform,
|
|
49
|
-
UserId
|
|
50
|
-
});
|
|
46
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
51
47
|
const groupId = String(event.group_id);
|
|
52
48
|
// 定义消
|
|
53
49
|
const e = {
|
|
@@ -55,7 +51,7 @@ var index = () => {
|
|
|
55
51
|
Platform: platform,
|
|
56
52
|
GuildId: groupId,
|
|
57
53
|
ChannelId: groupId,
|
|
58
|
-
IsMaster:
|
|
54
|
+
IsMaster: isMaster,
|
|
59
55
|
SpaceId: groupId,
|
|
60
56
|
IsBot: false,
|
|
61
57
|
UserId: UserId,
|
|
@@ -72,19 +68,15 @@ var index = () => {
|
|
|
72
68
|
cbp.send(e);
|
|
73
69
|
});
|
|
74
70
|
client.on('DIRECT_MESSAGE', event => {
|
|
75
|
-
const uis = config?.master_id ?? [];
|
|
76
71
|
const msg = getMessageText(event.message);
|
|
77
72
|
const UserId = String(event.user_id);
|
|
78
73
|
const UserAvatar = createUserAvatar(UserId);
|
|
79
|
-
const UserKey =
|
|
80
|
-
Platform: platform,
|
|
81
|
-
UserId
|
|
82
|
-
});
|
|
74
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
83
75
|
// 定义消
|
|
84
76
|
const e = {
|
|
85
77
|
name: 'private.message.create',
|
|
86
78
|
Platform: platform,
|
|
87
|
-
IsMaster:
|
|
79
|
+
IsMaster: isMaster,
|
|
88
80
|
IsBot: false,
|
|
89
81
|
UserId: UserId,
|
|
90
82
|
UserName: event.sender.nickname,
|
|
@@ -103,7 +95,7 @@ var index = () => {
|
|
|
103
95
|
client.on('ERROR', event => {
|
|
104
96
|
logger.error(event);
|
|
105
97
|
});
|
|
106
|
-
const sendGroup = async (
|
|
98
|
+
const sendGroup = async (ChannelId, val) => {
|
|
107
99
|
if (val.length < 0)
|
|
108
100
|
return [];
|
|
109
101
|
const content = val
|
|
@@ -113,7 +105,7 @@ var index = () => {
|
|
|
113
105
|
try {
|
|
114
106
|
if (content) {
|
|
115
107
|
const res = await client.sendGroupMessage({
|
|
116
|
-
group_id:
|
|
108
|
+
group_id: ChannelId,
|
|
117
109
|
message: [
|
|
118
110
|
{
|
|
119
111
|
type: 'text',
|
|
@@ -142,7 +134,7 @@ var index = () => {
|
|
|
142
134
|
data = Buffer.from(item.value, 'base64');
|
|
143
135
|
}
|
|
144
136
|
client.sendGroupMessage({
|
|
145
|
-
group_id:
|
|
137
|
+
group_id: ChannelId,
|
|
146
138
|
message: [
|
|
147
139
|
{
|
|
148
140
|
type: 'image',
|
|
@@ -165,11 +157,11 @@ var index = () => {
|
|
|
165
157
|
};
|
|
166
158
|
/**
|
|
167
159
|
*
|
|
168
|
-
* @param
|
|
160
|
+
* @param UserId
|
|
169
161
|
* @param val
|
|
170
162
|
* @returns
|
|
171
163
|
*/
|
|
172
|
-
const sendPrivate = async (
|
|
164
|
+
const sendPrivate = async (UserId, val) => {
|
|
173
165
|
if (val.length < 0)
|
|
174
166
|
return Promise.all([]);
|
|
175
167
|
const content = val
|
|
@@ -179,7 +171,7 @@ var index = () => {
|
|
|
179
171
|
try {
|
|
180
172
|
if (content) {
|
|
181
173
|
const res = await client.sendPrivateMessage({
|
|
182
|
-
user_id:
|
|
174
|
+
user_id: UserId,
|
|
183
175
|
message: [
|
|
184
176
|
{
|
|
185
177
|
type: 'text',
|
|
@@ -208,7 +200,7 @@ var index = () => {
|
|
|
208
200
|
data = Buffer.from(item.value, 'base64');
|
|
209
201
|
}
|
|
210
202
|
client.sendPrivateMessage({
|
|
211
|
-
user_id:
|
|
203
|
+
user_id: UserId,
|
|
212
204
|
message: [
|
|
213
205
|
{
|
|
214
206
|
type: 'image',
|
|
@@ -232,11 +224,11 @@ var index = () => {
|
|
|
232
224
|
const api = {
|
|
233
225
|
active: {
|
|
234
226
|
send: {
|
|
235
|
-
channel: (
|
|
236
|
-
return sendGroup(
|
|
227
|
+
channel: async (SpaceId, val) => {
|
|
228
|
+
return sendGroup(Number(SpaceId), val);
|
|
237
229
|
},
|
|
238
|
-
user: (
|
|
239
|
-
return sendPrivate(
|
|
230
|
+
user: async (OpenId, val) => {
|
|
231
|
+
return sendPrivate(Number(OpenId), val);
|
|
240
232
|
}
|
|
241
233
|
}
|
|
242
234
|
},
|
|
@@ -245,38 +237,38 @@ var index = () => {
|
|
|
245
237
|
if (val.length < 0)
|
|
246
238
|
return Promise.all([]);
|
|
247
239
|
if (event['name'] == 'private.message.create') {
|
|
248
|
-
|
|
240
|
+
const UserId = Number(event.UserId);
|
|
241
|
+
return sendPrivate(UserId, val);
|
|
249
242
|
}
|
|
250
243
|
else if (event['name'] == 'message.create') {
|
|
251
|
-
|
|
244
|
+
const GroupId = Number(event.ChannelId);
|
|
245
|
+
return sendGroup(GroupId, val);
|
|
252
246
|
}
|
|
253
247
|
return Promise.all([]);
|
|
254
248
|
},
|
|
255
249
|
mention: async (event) => {
|
|
256
|
-
const uis = config?.master_id ?? [];
|
|
257
250
|
const e = event.value;
|
|
258
|
-
|
|
251
|
+
const names = ['message.create', 'private.message.create'];
|
|
252
|
+
if (names.includes(event.name)) {
|
|
259
253
|
const Metions = [];
|
|
260
254
|
for (const item of e.message) {
|
|
261
255
|
if (item.type == 'at') {
|
|
262
256
|
let isBot = false;
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
257
|
+
const UserId = String(item.data.qq);
|
|
258
|
+
if (UserId == 'all') {
|
|
265
259
|
continue;
|
|
266
260
|
}
|
|
267
|
-
if (
|
|
261
|
+
if (UserId == MyBot.id) {
|
|
268
262
|
isBot = true;
|
|
269
263
|
}
|
|
270
|
-
const
|
|
264
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
265
|
+
const avatar = createUserAvatar(UserId);
|
|
271
266
|
Metions.push({
|
|
272
|
-
UserId:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
UserId: uid
|
|
276
|
-
}),
|
|
267
|
+
UserId: UserId,
|
|
268
|
+
IsMaster: isMaster,
|
|
269
|
+
UserKey: UserKey,
|
|
277
270
|
UserName: item.data?.nickname,
|
|
278
271
|
UserAvatar: avatar,
|
|
279
|
-
IsMaster: uis.includes(uid),
|
|
280
272
|
IsBot: isBot
|
|
281
273
|
});
|
|
282
274
|
}
|