@alemonjs/discord 2.1.0-alpha.16 → 2.1.0-alpha.18
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/lib/index.js +12 -0
- package/lib/sdk/api.js +57 -33
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -284,6 +284,18 @@ const mainProcess = () => {
|
|
|
284
284
|
if (process.send) {
|
|
285
285
|
process.send(JSON.stringify({ type: 'ready' }));
|
|
286
286
|
}
|
|
287
|
+
process.on('message', msg => {
|
|
288
|
+
try {
|
|
289
|
+
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
290
|
+
if (data?.type === 'start') {
|
|
291
|
+
main();
|
|
292
|
+
}
|
|
293
|
+
else if (data?.type === 'stop') {
|
|
294
|
+
process.exit(0);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch { }
|
|
298
|
+
});
|
|
287
299
|
};
|
|
288
300
|
mainProcess();
|
|
289
301
|
|
package/lib/sdk/api.js
CHANGED
|
@@ -6,6 +6,36 @@ import { createPicFrom } from './createPicFrom.js';
|
|
|
6
6
|
|
|
7
7
|
const API_URL = 'https://discord.com/api/v10';
|
|
8
8
|
const CDN_URL = 'https://cdn.discordapp.com';
|
|
9
|
+
function filterHeaders(headers) {
|
|
10
|
+
if (!headers) {
|
|
11
|
+
return headers;
|
|
12
|
+
}
|
|
13
|
+
const filtered = {};
|
|
14
|
+
const sensitiveKeys = [
|
|
15
|
+
/^authorization$/i,
|
|
16
|
+
/^cookie$/i,
|
|
17
|
+
/^set-cookie$/i,
|
|
18
|
+
/token/i,
|
|
19
|
+
/key/i,
|
|
20
|
+
/jwt/i,
|
|
21
|
+
/^session[-_]id$/i,
|
|
22
|
+
/^uid$/i,
|
|
23
|
+
/^user[-_]id$/i
|
|
24
|
+
];
|
|
25
|
+
for (const key in headers) {
|
|
26
|
+
if (/^_/.test(key)) {
|
|
27
|
+
continue; // 跳过 _ 开头
|
|
28
|
+
}
|
|
29
|
+
// 如果是敏感字段全部替换为 ******
|
|
30
|
+
if (sensitiveKeys.some(re => re.test(key))) {
|
|
31
|
+
filtered[key] = '******';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
filtered[key] = headers[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return filtered;
|
|
38
|
+
}
|
|
9
39
|
/**
|
|
10
40
|
* api接口
|
|
11
41
|
*/
|
|
@@ -33,18 +63,12 @@ class DCAPI {
|
|
|
33
63
|
});
|
|
34
64
|
return new Promise((resolve, reject) => {
|
|
35
65
|
service(options)
|
|
36
|
-
.then(res => resolve(res?.data
|
|
66
|
+
.then(res => resolve(res?.data ?? {}))
|
|
37
67
|
.catch(err => {
|
|
38
|
-
logger.error(err);
|
|
39
68
|
// 错误时的请求头
|
|
40
69
|
logger.error('[axios] error', {
|
|
41
70
|
config: {
|
|
42
|
-
|
|
43
|
-
// 如果存在 token 要隐藏调。
|
|
44
|
-
headers: {
|
|
45
|
-
...err?.config?.headers,
|
|
46
|
-
Authorization: `Bot ${value.token ? '******' : value.token}`
|
|
47
|
-
},
|
|
71
|
+
headers: filterHeaders(err?.config?.headers),
|
|
48
72
|
params: err?.config?.params,
|
|
49
73
|
data: err?.config?.data
|
|
50
74
|
},
|
|
@@ -928,7 +952,7 @@ class DCAPI {
|
|
|
928
952
|
getChannelInvites(channel_id) {
|
|
929
953
|
return this.request({
|
|
930
954
|
method: 'get',
|
|
931
|
-
url: `/channels
|
|
955
|
+
url: `/channels/${channel_id}/invites`
|
|
932
956
|
});
|
|
933
957
|
}
|
|
934
958
|
/**
|
|
@@ -939,7 +963,7 @@ class DCAPI {
|
|
|
939
963
|
createChannelInvites(channel_id) {
|
|
940
964
|
return this.request({
|
|
941
965
|
method: 'POST',
|
|
942
|
-
url: `/channels
|
|
966
|
+
url: `/channels/${channel_id}/invites`
|
|
943
967
|
});
|
|
944
968
|
}
|
|
945
969
|
/**
|
|
@@ -950,7 +974,7 @@ class DCAPI {
|
|
|
950
974
|
deleteChannelInvites(channel_id) {
|
|
951
975
|
return this.request({
|
|
952
976
|
method: 'POST',
|
|
953
|
-
url: `/channels
|
|
977
|
+
url: `/channels/${channel_id}/invites`
|
|
954
978
|
});
|
|
955
979
|
}
|
|
956
980
|
/**
|
|
@@ -961,7 +985,7 @@ class DCAPI {
|
|
|
961
985
|
triggerTypingIndicator(channel_id) {
|
|
962
986
|
return this.request({
|
|
963
987
|
method: 'POST',
|
|
964
|
-
url: `/channels
|
|
988
|
+
url: `/channels/${channel_id}/typing`
|
|
965
989
|
});
|
|
966
990
|
}
|
|
967
991
|
/**
|
|
@@ -972,7 +996,7 @@ class DCAPI {
|
|
|
972
996
|
groupDMAddRecipient(channel_id, user_id) {
|
|
973
997
|
return this.request({
|
|
974
998
|
method: 'put',
|
|
975
|
-
url: `/channels
|
|
999
|
+
url: `/channels/${channel_id}/recipients/${user_id}`
|
|
976
1000
|
});
|
|
977
1001
|
}
|
|
978
1002
|
/**
|
|
@@ -983,7 +1007,7 @@ class DCAPI {
|
|
|
983
1007
|
groupDMdeleteRecipient(channel_id, user_id) {
|
|
984
1008
|
return this.request({
|
|
985
1009
|
method: 'delete',
|
|
986
|
-
url: `/channels
|
|
1010
|
+
url: `/channels/${channel_id}/recipients/${user_id}`
|
|
987
1011
|
});
|
|
988
1012
|
}
|
|
989
1013
|
/**
|
|
@@ -994,7 +1018,7 @@ class DCAPI {
|
|
|
994
1018
|
startThreadfromMessage(channel_id, message_id) {
|
|
995
1019
|
return this.request({
|
|
996
1020
|
method: 'post',
|
|
997
|
-
url: `/channels/${channel_id}
|
|
1021
|
+
url: `/channels/${channel_id}/messages/${message_id}/threads`
|
|
998
1022
|
});
|
|
999
1023
|
}
|
|
1000
1024
|
/**
|
|
@@ -1136,7 +1160,7 @@ class DCAPI {
|
|
|
1136
1160
|
editChannelPermissions(channel_id, overwrite_id) {
|
|
1137
1161
|
return this.request({
|
|
1138
1162
|
method: 'PATCH',
|
|
1139
|
-
url: `/channels
|
|
1163
|
+
url: `/channels/${channel_id}/permissions/${overwrite_id}`
|
|
1140
1164
|
});
|
|
1141
1165
|
}
|
|
1142
1166
|
/**
|
|
@@ -1147,7 +1171,7 @@ class DCAPI {
|
|
|
1147
1171
|
deleteChannelPermissions(channel_id, overwrite_id) {
|
|
1148
1172
|
return this.request({
|
|
1149
1173
|
method: 'delete',
|
|
1150
|
-
url: `/channels
|
|
1174
|
+
url: `/channels/${channel_id}/permissions/${overwrite_id}`
|
|
1151
1175
|
});
|
|
1152
1176
|
}
|
|
1153
1177
|
/**
|
|
@@ -1196,7 +1220,7 @@ class DCAPI {
|
|
|
1196
1220
|
crosspostmessages(channel_id, message_id) {
|
|
1197
1221
|
return this.request({
|
|
1198
1222
|
method: 'POST',
|
|
1199
|
-
url: `/channels
|
|
1223
|
+
url: `/channels/${channel_id}/messages/${message_id}/crosspost`
|
|
1200
1224
|
});
|
|
1201
1225
|
}
|
|
1202
1226
|
/**
|
|
@@ -1207,7 +1231,7 @@ class DCAPI {
|
|
|
1207
1231
|
createareaction(channel_id, message_id, emoji) {
|
|
1208
1232
|
return this.request({
|
|
1209
1233
|
method: 'PUT',
|
|
1210
|
-
url: `/channels
|
|
1234
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions/${emoji}/@me`
|
|
1211
1235
|
});
|
|
1212
1236
|
}
|
|
1213
1237
|
/**
|
|
@@ -1218,7 +1242,7 @@ class DCAPI {
|
|
|
1218
1242
|
deleteownreaction(channel_id, message_id, emoji) {
|
|
1219
1243
|
return this.request({
|
|
1220
1244
|
method: 'DELETE',
|
|
1221
|
-
url: `/channels
|
|
1245
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions/${emoji}/@me`
|
|
1222
1246
|
});
|
|
1223
1247
|
}
|
|
1224
1248
|
/**
|
|
@@ -1229,7 +1253,7 @@ class DCAPI {
|
|
|
1229
1253
|
deleteareuserction(channel_id, message_id, emoji, user_id) {
|
|
1230
1254
|
return this.request({
|
|
1231
1255
|
method: 'DELETE',
|
|
1232
|
-
url: `/channels
|
|
1256
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions/${emoji}/${user_id}`
|
|
1233
1257
|
});
|
|
1234
1258
|
}
|
|
1235
1259
|
/**
|
|
@@ -1240,7 +1264,7 @@ class DCAPI {
|
|
|
1240
1264
|
getownreaction(channel_id, message_id, emoji) {
|
|
1241
1265
|
return this.request({
|
|
1242
1266
|
method: 'get',
|
|
1243
|
-
url: `/channels
|
|
1267
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions/${emoji}`
|
|
1244
1268
|
});
|
|
1245
1269
|
}
|
|
1246
1270
|
/**
|
|
@@ -1251,7 +1275,7 @@ class DCAPI {
|
|
|
1251
1275
|
deleteAllreaction(channel_id, message_id) {
|
|
1252
1276
|
return this.request({
|
|
1253
1277
|
method: 'DELETE',
|
|
1254
|
-
url: `/channels
|
|
1278
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions`
|
|
1255
1279
|
});
|
|
1256
1280
|
}
|
|
1257
1281
|
/**
|
|
@@ -1262,7 +1286,7 @@ class DCAPI {
|
|
|
1262
1286
|
deleteAllreactionforEmoji(channel_id, message_id, emoji) {
|
|
1263
1287
|
return this.request({
|
|
1264
1288
|
method: 'DELETE',
|
|
1265
|
-
url: `/channels
|
|
1289
|
+
url: `/channels/${channel_id}/messages/${message_id}/reactions/${emoji}`
|
|
1266
1290
|
});
|
|
1267
1291
|
}
|
|
1268
1292
|
/**
|
|
@@ -1326,7 +1350,7 @@ class DCAPI {
|
|
|
1326
1350
|
followAnnouncementChannel(channel_id) {
|
|
1327
1351
|
return this.request({
|
|
1328
1352
|
method: 'POST',
|
|
1329
|
-
url: `/channels
|
|
1353
|
+
url: `/channels/${channel_id}/followers`
|
|
1330
1354
|
});
|
|
1331
1355
|
}
|
|
1332
1356
|
/**
|
|
@@ -1342,7 +1366,7 @@ class DCAPI {
|
|
|
1342
1366
|
getPinnedMessages(channel_id) {
|
|
1343
1367
|
return this.request({
|
|
1344
1368
|
method: 'get',
|
|
1345
|
-
url: `/channels
|
|
1369
|
+
url: `/channels/${channel_id}/pins`
|
|
1346
1370
|
});
|
|
1347
1371
|
}
|
|
1348
1372
|
/**
|
|
@@ -1353,7 +1377,7 @@ class DCAPI {
|
|
|
1353
1377
|
pinMessage(channel_id, message_id) {
|
|
1354
1378
|
return this.request({
|
|
1355
1379
|
method: 'put',
|
|
1356
|
-
url: `/channels
|
|
1380
|
+
url: `/channels/${channel_id}/${message_id}`
|
|
1357
1381
|
});
|
|
1358
1382
|
}
|
|
1359
1383
|
/**
|
|
@@ -1364,7 +1388,7 @@ class DCAPI {
|
|
|
1364
1388
|
deletepinMessage(channel_id, message_id) {
|
|
1365
1389
|
return this.request({
|
|
1366
1390
|
method: 'delete',
|
|
1367
|
-
url: `/channels
|
|
1391
|
+
url: `/channels/${channel_id}/${message_id}`
|
|
1368
1392
|
});
|
|
1369
1393
|
}
|
|
1370
1394
|
/**
|
|
@@ -1462,7 +1486,7 @@ class DCAPI {
|
|
|
1462
1486
|
listGuildEmojis(guild_id) {
|
|
1463
1487
|
return this.request({
|
|
1464
1488
|
method: 'get',
|
|
1465
|
-
url: `/guilds
|
|
1489
|
+
url: `/guilds/${guild_id}/emojis`
|
|
1466
1490
|
});
|
|
1467
1491
|
}
|
|
1468
1492
|
/**
|
|
@@ -1473,7 +1497,7 @@ class DCAPI {
|
|
|
1473
1497
|
getGuildEmoji(guild_id, emoji_id) {
|
|
1474
1498
|
return this.request({
|
|
1475
1499
|
method: 'get',
|
|
1476
|
-
url: `/guilds
|
|
1500
|
+
url: `/guilds/${guild_id}/emojis/${emoji_id}`
|
|
1477
1501
|
});
|
|
1478
1502
|
}
|
|
1479
1503
|
/**
|
|
@@ -1484,7 +1508,7 @@ class DCAPI {
|
|
|
1484
1508
|
createGuildEmoji(guild_id) {
|
|
1485
1509
|
return this.request({
|
|
1486
1510
|
method: 'post',
|
|
1487
|
-
url: `/guilds
|
|
1511
|
+
url: `/guilds/${guild_id}/emojis`
|
|
1488
1512
|
});
|
|
1489
1513
|
}
|
|
1490
1514
|
/**
|
|
@@ -1495,7 +1519,7 @@ class DCAPI {
|
|
|
1495
1519
|
modifyGuildEmoji(guild_id, emoji_id) {
|
|
1496
1520
|
return this.request({
|
|
1497
1521
|
method: 'PATCH',
|
|
1498
|
-
url: `/guilds
|
|
1522
|
+
url: `/guilds/${guild_id}/emojis/${emoji_id}`
|
|
1499
1523
|
});
|
|
1500
1524
|
}
|
|
1501
1525
|
/**
|
|
@@ -1506,7 +1530,7 @@ class DCAPI {
|
|
|
1506
1530
|
deleteGuildEmoji(guild_id, emoji_id) {
|
|
1507
1531
|
return this.request({
|
|
1508
1532
|
method: 'delete',
|
|
1509
|
-
url: `/guilds
|
|
1533
|
+
url: `/guilds/${guild_id}/emojis/${emoji_id}`
|
|
1510
1534
|
});
|
|
1511
1535
|
}
|
|
1512
1536
|
/**
|