@imaentity/selfjs 2.9.11 → 3.1.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/README.md +6 -2
- package/changelog.log +25 -1
- package/docs.md +470 -91
- package/package.json +1 -1
- package/self.js +230 -585
package/self.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @name SelfJS
|
|
3
3
|
* @description Breaking Discord's TOS to bot user accounts.
|
|
4
4
|
* @author Эмберс
|
|
5
|
-
* @version
|
|
5
|
+
* @version 3.1.0
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const https = require("https");
|
|
@@ -21,7 +21,6 @@ module.exports = {
|
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
status: {
|
|
24
|
-
DEFAULT: -1,
|
|
25
24
|
PLAYING: 0,
|
|
26
25
|
STREAMING: 1,
|
|
27
26
|
LISTENING: 2,
|
|
@@ -47,36 +46,67 @@ module.exports = {
|
|
|
47
46
|
},
|
|
48
47
|
|
|
49
48
|
sendWebhookMessage: function(webhookID, webhookToken, inputData) {
|
|
50
|
-
|
|
51
|
-
let msgData = null;
|
|
49
|
+
const boundary = "X-SELFJS-BOUNDARY";
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
let contentType = "application/json";
|
|
52
|
+
if(inputData.attachments && inputData.attachments.length > 0)
|
|
53
|
+
contentType = `multipart/form-data; boundary=${boundary}`;
|
|
54
|
+
|
|
55
|
+
const webID = inputData ? webhookID : webhookID.split("//")[1].split('/')[3];
|
|
56
|
+
const webTok = inputData ? webhookToken : webhookID.split("//")[1].split('/')[4];
|
|
57
|
+
const inData = inputData ? inputData : webhookToken;
|
|
58
|
+
|
|
59
|
+
let msgData = Buffer.from(module.exports.jsonEncode(inData));
|
|
60
|
+
|
|
61
|
+
if(inputData.attachments && inputData.attachments.length > 0) {
|
|
62
|
+
let msgFiles = [...inData.files];
|
|
63
|
+
|
|
64
|
+
delete inData.files;
|
|
65
|
+
msgData = Buffer.from(module.exports.jsonEncode(inData));
|
|
66
|
+
|
|
67
|
+
msgData = Buffer.concat([Buffer.from("Content-Type: application/json\r\n\r\n"), msgData]);
|
|
68
|
+
msgData = Buffer.concat([Buffer.from('Content-Disposition: form-data; name="payload_json"\r\n'), msgData]);
|
|
69
|
+
msgData = Buffer.concat([Buffer.from(`--${boundary}\r\n`), msgData]);
|
|
70
|
+
msgData = Buffer.concat([msgData, Buffer.from("\r\n")]);
|
|
71
|
+
|
|
72
|
+
for(const i in inData.attachments) {
|
|
73
|
+
const attach = inData.attachments[i];
|
|
74
|
+
|
|
75
|
+
msgData = Buffer.concat([msgData, Buffer.from(`--${boundary}\r\n`)]);
|
|
76
|
+
msgData = Buffer.concat([msgData, Buffer.from(`Content-Disposition: form-data; name="files[${i}]"; filename="${attach.filename}"\r\n`)]);
|
|
77
|
+
msgData = Buffer.concat([msgData, Buffer.from(`Content-Type: ${attach.content_type}\r\n\r\n`)]);
|
|
78
|
+
msgData = Buffer.concat([msgData, fs.existsSync(msgFiles[i]) ? fs.readFileSync(msgFiles[i], "") : Buffer.from("")]);
|
|
79
|
+
msgData = Buffer.concat([msgData, Buffer.from("\r\n")]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
msgData = Buffer.concat([msgData, Buffer.from(`--${boundary}--`)]);
|
|
75
83
|
}
|
|
76
84
|
|
|
85
|
+
const options = {
|
|
86
|
+
...module.exports.APIBaseOpt,
|
|
87
|
+
method: "POST",
|
|
88
|
+
path: `/api/webhooks/${webID}/${webTok}`,
|
|
89
|
+
headers: {
|
|
90
|
+
"Content-Type": contentType,
|
|
91
|
+
"Content-Length": Buffer.byteLength(msgData)
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
77
95
|
return new Promise(function(resolve) {
|
|
78
96
|
const req = https.request(options, function(res) {
|
|
79
|
-
|
|
97
|
+
const chunks = [];
|
|
98
|
+
|
|
99
|
+
res.on("data", function(chunk) {
|
|
100
|
+
chunks.push(chunk);
|
|
101
|
+
}).on("end", function() {
|
|
102
|
+
const data = Buffer.concat(chunks);
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
resolve(JSON.parse(data));
|
|
106
|
+
} catch(e) {
|
|
107
|
+
resolve({});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
80
110
|
});
|
|
81
111
|
|
|
82
112
|
req.write(msgData);
|
|
@@ -213,6 +243,41 @@ module.exports = {
|
|
|
213
243
|
}.bind(this));
|
|
214
244
|
}
|
|
215
245
|
|
|
246
|
+
makeRequest(options = {}, base = module.exports.APIBaseOpt) {
|
|
247
|
+
const path = options.path || '/';
|
|
248
|
+
const method = options.method || "GET";
|
|
249
|
+
const headers = options.headers || {};
|
|
250
|
+
const body = options.body || undefined;
|
|
251
|
+
|
|
252
|
+
const strBody = module.exports.jsonEncode(body) ?? "";
|
|
253
|
+
|
|
254
|
+
headers["Authorization"] = this.token;
|
|
255
|
+
headers["Content-Type"] = "application/json";
|
|
256
|
+
headers["Content-Length"] = strBody.length;
|
|
257
|
+
|
|
258
|
+
const reqOptions = {
|
|
259
|
+
...base,
|
|
260
|
+
path,
|
|
261
|
+
method,
|
|
262
|
+
headers
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
return new Promise(function(resolve) {
|
|
266
|
+
const req = https.request(reqOptions, function(res) {
|
|
267
|
+
const chunks = [];
|
|
268
|
+
|
|
269
|
+
res.on("data", function(chunk) {
|
|
270
|
+
chunks.push(chunk);
|
|
271
|
+
}).on("end", function() {
|
|
272
|
+
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if(strBody) req.write(strBody);
|
|
277
|
+
req.end();
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
216
281
|
onMessage(msgFunc) {
|
|
217
282
|
this.onMessageFunction = msgFunc;
|
|
218
283
|
}
|
|
@@ -229,58 +294,21 @@ module.exports = {
|
|
|
229
294
|
this.statusUpdateFunction = statusFunc;
|
|
230
295
|
}
|
|
231
296
|
|
|
232
|
-
getDMChannel(userID) {
|
|
233
|
-
|
|
234
|
-
const options = {
|
|
235
|
-
...module.exports.APIBaseOpt,
|
|
297
|
+
async getDMChannel(userID) {
|
|
298
|
+
return await this.makeRequest({
|
|
236
299
|
method: "POST",
|
|
237
300
|
path: "/api/v10/users/@me/channels",
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
"Content-Type": "application/json",
|
|
241
|
-
"Content-Length": channelData.length
|
|
301
|
+
body: {
|
|
302
|
+
recipients: [userID]
|
|
242
303
|
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
return new Promise(function(resolve) {
|
|
246
|
-
const req = https.request(options, function(res) {
|
|
247
|
-
const chunks = [];
|
|
248
|
-
|
|
249
|
-
res.on("data", function(chunk) {
|
|
250
|
-
chunks.push(chunk);
|
|
251
|
-
}).on("end", function() {
|
|
252
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
req.write(channelData);
|
|
257
|
-
req.end();
|
|
258
304
|
});
|
|
259
305
|
}
|
|
260
306
|
|
|
261
|
-
getRoles(serverID, userID) {
|
|
262
|
-
|
|
263
|
-
...module.exports.APIBaseOpt,
|
|
307
|
+
async getRoles(serverID, userID) {
|
|
308
|
+
return (await this.makeRequest({
|
|
264
309
|
method: "GET",
|
|
265
|
-
path: `/api/v10/
|
|
266
|
-
|
|
267
|
-
"Authorization": this.token
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
return new Promise(function(resolve) {
|
|
272
|
-
const req = https.request(options, function(res) {
|
|
273
|
-
const chunks = [];
|
|
274
|
-
|
|
275
|
-
res.on("data", function(chunk) {
|
|
276
|
-
chunks.push(chunk);
|
|
277
|
-
}).on("end", function() {
|
|
278
|
-
resolve(JSON.parse(Buffer.concat(chunks)).guild_member.roles);
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
req.end();
|
|
283
|
-
});
|
|
310
|
+
path: `/api/v10/guilds/${serverID}/members/${userID}`,
|
|
311
|
+
})).guild_member.roles;
|
|
284
312
|
}
|
|
285
313
|
|
|
286
314
|
uploadFile(channelID, fileName, isSpoiled = false, msgContent = "", messageID = null) {
|
|
@@ -425,7 +453,7 @@ module.exports = {
|
|
|
425
453
|
}.bind(this));
|
|
426
454
|
}
|
|
427
455
|
|
|
428
|
-
search(channelID, options) {
|
|
456
|
+
async search(channelID, options) {
|
|
429
457
|
options = options || {};
|
|
430
458
|
|
|
431
459
|
const pinned = options.pinned ?? null;
|
|
@@ -448,346 +476,136 @@ module.exports = {
|
|
|
448
476
|
if(mentions != null) path += mentions.map((e) => `mentions=${e}`).join('&') + '&';
|
|
449
477
|
if(has != null) path += has.map((e) => `has=${e}`).join('&');
|
|
450
478
|
|
|
451
|
-
|
|
452
|
-
...module.exports.APIBaseOpt,
|
|
479
|
+
return await this.makeRequest({
|
|
453
480
|
method: "GET",
|
|
454
|
-
path
|
|
455
|
-
headers: {
|
|
456
|
-
"Authorization": this.token
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
return new Promise(function(resolve) {
|
|
461
|
-
const req = https.request(requestOptions, function(res) {
|
|
462
|
-
const chunks = [];
|
|
463
|
-
|
|
464
|
-
res.on("data", function(chunk) {
|
|
465
|
-
chunks.push(chunk);
|
|
466
|
-
}).on("end", function() {
|
|
467
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
req.end();
|
|
481
|
+
path: path
|
|
472
482
|
});
|
|
473
483
|
}
|
|
474
484
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
...module.exports.APIBaseOpt,
|
|
485
|
+
async getUserProfile(userID) {
|
|
486
|
+
return await this.makeRequest({
|
|
478
487
|
method: "GET",
|
|
479
|
-
path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
return new Promise(function(resolve) {
|
|
486
|
-
const req = https.request(options, function(res) {
|
|
487
|
-
const chunks = [];
|
|
488
|
-
|
|
489
|
-
res.on("data", function(chunk) {
|
|
490
|
-
chunks.push(chunk);
|
|
491
|
-
}).on("end", function() {
|
|
492
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
493
|
-
});
|
|
494
|
-
});
|
|
488
|
+
path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false`
|
|
489
|
+
});
|
|
490
|
+
}
|
|
495
491
|
|
|
496
|
-
|
|
492
|
+
async getUserData(userID) {
|
|
493
|
+
return await this.makeRequest({
|
|
494
|
+
method: "GET",
|
|
495
|
+
path: `/api/v10/users/${userID}`
|
|
497
496
|
});
|
|
498
497
|
}
|
|
499
498
|
|
|
500
|
-
setRolesForMemeber(serverID, userID, roleIDs) {
|
|
501
|
-
|
|
502
|
-
const options = {
|
|
503
|
-
...module.exports.APIBaseOpt,
|
|
499
|
+
async setRolesForMemeber(serverID, userID, roleIDs) {
|
|
500
|
+
return await this.makeRequest({
|
|
504
501
|
method: "PATCH",
|
|
505
502
|
path: `/api/v10/guilds/${serverID}/members/${userID}`,
|
|
506
|
-
|
|
507
|
-
"Content-Type": "application/json",
|
|
508
|
-
"Content-Length": roleData.length,
|
|
509
|
-
"Authorization": this.token
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
return new Promise(function(resolve) {
|
|
514
|
-
const req = https.request(options, function(res) {
|
|
515
|
-
res.on("end", resolve);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
req.write(roleData);
|
|
519
|
-
req.end();
|
|
503
|
+
body: roleIDs
|
|
520
504
|
});
|
|
521
505
|
}
|
|
522
506
|
|
|
523
|
-
sendMessage(channelID, message) {
|
|
524
|
-
|
|
525
|
-
const options = {
|
|
526
|
-
...module.exports.APIBaseOpt,
|
|
507
|
+
async sendMessage(channelID, message) {
|
|
508
|
+
return await this.makeRequest({
|
|
527
509
|
method: "POST",
|
|
528
510
|
path: `/api/v10/channels/${channelID}/messages`,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
"Content-Type": "application/json",
|
|
532
|
-
"Content-Length": msgData.length
|
|
511
|
+
body: {
|
|
512
|
+
content: message
|
|
533
513
|
}
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
return new Promise(function(resolve) {
|
|
537
|
-
const req = https.request(options, function(res) {
|
|
538
|
-
const chunks = [];
|
|
539
|
-
|
|
540
|
-
res.on("data", function(chunk) {
|
|
541
|
-
chunks.push(chunk);
|
|
542
|
-
}).on("end", function() {
|
|
543
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
req.write(msgData);
|
|
548
|
-
req.end();
|
|
549
514
|
});
|
|
550
515
|
}
|
|
551
516
|
|
|
552
|
-
replyToMessage(channelID, messageID, message) {
|
|
553
|
-
|
|
554
|
-
const options = {
|
|
555
|
-
...module.exports.APIBaseOpt,
|
|
517
|
+
async replyToMessage(channelID, messageID, message) {
|
|
518
|
+
return await this.makeRequest({
|
|
556
519
|
method: "POST",
|
|
557
520
|
path: `/api/v10/channels/${channelID}/messages`,
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
521
|
+
body: {
|
|
522
|
+
content: message,
|
|
523
|
+
message_reference: {
|
|
524
|
+
channel_id: channelID,
|
|
525
|
+
message_id: messageID
|
|
526
|
+
}
|
|
562
527
|
}
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
return new Promise(function(resolve) {
|
|
566
|
-
const req = https.request(options, function(res) {
|
|
567
|
-
const chunks = [];
|
|
568
|
-
|
|
569
|
-
res.on("data", function(chunk) {
|
|
570
|
-
chunks.push(chunk);
|
|
571
|
-
}).on("end", function() {
|
|
572
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
req.write(msgData);
|
|
577
|
-
req.end();
|
|
578
528
|
});
|
|
579
529
|
}
|
|
580
530
|
|
|
581
|
-
createChannel(guildID, name, type, parentID = null) {
|
|
582
|
-
|
|
583
|
-
const options = {
|
|
584
|
-
...module.exports.APIBaseOpt,
|
|
531
|
+
async createChannel(guildID, name, type, parentID = null) {
|
|
532
|
+
return await this.makeRequest({
|
|
585
533
|
method: "POST",
|
|
586
534
|
path: `/api/v10/guilds/${guildID}/channels`,
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
535
|
+
body: {
|
|
536
|
+
name,
|
|
537
|
+
type,
|
|
538
|
+
parent_id: parentID
|
|
591
539
|
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
return new Promise(function(resolve) {
|
|
595
|
-
const req = https.request(options, function(res) {
|
|
596
|
-
const chunks = [];
|
|
597
|
-
|
|
598
|
-
res.on("data", function(chunk) {
|
|
599
|
-
chunks.push(chunk);
|
|
600
|
-
}).on("end", function() {
|
|
601
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
req.write(channelData);
|
|
606
|
-
req.end();
|
|
607
540
|
});
|
|
608
541
|
}
|
|
609
542
|
|
|
610
|
-
setChannelPermissions(channelID, userID, allow, deny) {
|
|
611
|
-
|
|
612
|
-
const options = {
|
|
613
|
-
...module.exports.APIBaseOpt,
|
|
543
|
+
async setChannelPermissions(channelID, userID, allow, deny) {
|
|
544
|
+
return await this.makeRequest({
|
|
614
545
|
method: "PUT",
|
|
615
546
|
path: `/api/v10/channels/${channelID}/permissions/${userID}`,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
547
|
+
body: {
|
|
548
|
+
id: userID,
|
|
549
|
+
allow,
|
|
550
|
+
deny,
|
|
551
|
+
type: 1
|
|
620
552
|
}
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
return new Promise(function(resolve) {
|
|
624
|
-
const req = https.request(options, function(res) {
|
|
625
|
-
const chunks = [];
|
|
626
|
-
|
|
627
|
-
res.on("data", function(chunk) {
|
|
628
|
-
chunks.push(chunk);
|
|
629
|
-
}).on("end", function() {
|
|
630
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
631
|
-
});
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
req.write(permissionData);
|
|
635
|
-
req.end();
|
|
636
553
|
});
|
|
637
554
|
}
|
|
638
555
|
|
|
639
|
-
getMessages(channelID, limit) {
|
|
640
|
-
|
|
641
|
-
...module.exports.APIBaseOpt,
|
|
556
|
+
async getMessages(channelID, limit) {
|
|
557
|
+
return await this.makeRequest({
|
|
642
558
|
method: "GET",
|
|
643
|
-
path: `/api/v10/channels/${channelID}/messages?limit=${limit}
|
|
644
|
-
headers: {
|
|
645
|
-
"Authorization": this.token
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
return new Promise(function(resolve) {
|
|
650
|
-
const req = https.request(options, function(res) {
|
|
651
|
-
const chunks = [];
|
|
652
|
-
|
|
653
|
-
res.on("data", function(chunk) {
|
|
654
|
-
chunks.push(chunk);
|
|
655
|
-
}).on("end", function() {
|
|
656
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
req.end();
|
|
559
|
+
path: `/api/v10/channels/${channelID}/messages?limit=${limit}`
|
|
661
560
|
});
|
|
662
561
|
}
|
|
663
562
|
|
|
664
|
-
getUsers(guildID) {
|
|
665
|
-
|
|
666
|
-
...module.exports.APIBaseOpt,
|
|
563
|
+
async getUsers(guildID) {
|
|
564
|
+
return await this.makeRequest({
|
|
667
565
|
method: "GET",
|
|
668
|
-
path: `/api/v10/guilds/${guildID}/members
|
|
669
|
-
headers: {
|
|
670
|
-
"Authorization": this.token
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
return new Promise(function(resolve) {
|
|
675
|
-
const req = https.request(options, function(res) {
|
|
676
|
-
const chunks = [];
|
|
677
|
-
|
|
678
|
-
res.on("data", function(chunk) {
|
|
679
|
-
chunks.push(chunk);
|
|
680
|
-
}).on("end", function() {
|
|
681
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
req.end();
|
|
566
|
+
path: `/api/v10/guilds/${guildID}/members`
|
|
686
567
|
});
|
|
687
568
|
}
|
|
688
569
|
|
|
689
|
-
removeFromChannel(channelID, userID) {
|
|
690
|
-
|
|
691
|
-
...module.exports.APIBaseOpt,
|
|
570
|
+
async removeFromChannel(channelID, userID) {
|
|
571
|
+
return await this.makeRequest({
|
|
692
572
|
method: "DELETE",
|
|
693
|
-
path: `/api/v10/channels/${channelID}/recipients/${userID}
|
|
694
|
-
headers: {
|
|
695
|
-
"Authorization": this.token
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
return new Promise(function(resolve) {
|
|
700
|
-
const req = https.request(options, function(res) {
|
|
701
|
-
res.on("end", resolve);
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
req.end();
|
|
573
|
+
path: `/api/v10/channels/${channelID}/recipients/${userID}`
|
|
705
574
|
});
|
|
706
575
|
}
|
|
707
576
|
|
|
708
|
-
leaveChannel(channelID) {
|
|
709
|
-
|
|
710
|
-
...module.exports.APIBaseOpt,
|
|
577
|
+
async leaveChannel(channelID) {
|
|
578
|
+
return await this.makeRequest({
|
|
711
579
|
method: "DELETE",
|
|
712
|
-
path: `/api/v10/channels/${channelID}
|
|
713
|
-
|
|
714
|
-
"Authorization": this.token
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
return new Promise(function(resolve) {
|
|
719
|
-
const req = https.request(options, function(res) {
|
|
720
|
-
res.on("end", resolve);
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
req.end();
|
|
724
|
-
}.bind(this));
|
|
580
|
+
path: `/api/v10/channels/${channelID}`
|
|
581
|
+
});
|
|
725
582
|
}
|
|
726
583
|
|
|
727
|
-
ring(channelID, userIDs) {
|
|
728
|
-
|
|
729
|
-
const options = {
|
|
730
|
-
...module.exports.APIBaseOpt,
|
|
584
|
+
async ring(channelID, userIDs) {
|
|
585
|
+
return await this.makeRequest({
|
|
731
586
|
method: "POST",
|
|
732
587
|
path: `/api/v10/channels/${channelID}/call/ring`,
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
"Content-Type": "application/json",
|
|
736
|
-
"Content-Length": ringData.length
|
|
588
|
+
body: {
|
|
589
|
+
recipients: userIDs
|
|
737
590
|
}
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
return new Promise(function(resolve) {
|
|
741
|
-
const req = https.request(options, function(res) {
|
|
742
|
-
res.on("end", resolve);
|
|
743
|
-
});
|
|
744
|
-
|
|
745
|
-
req.write(ringData);
|
|
746
|
-
req.end();
|
|
747
591
|
});
|
|
748
592
|
}
|
|
749
593
|
|
|
750
|
-
stopRinging(channelID, userIDs) {
|
|
751
|
-
|
|
752
|
-
const options = {
|
|
753
|
-
...module.exports.APIBaseOpt,
|
|
594
|
+
async stopRinging(channelID, userIDs) {
|
|
595
|
+
return await this.makeRequest({
|
|
754
596
|
method: "POST",
|
|
755
597
|
path: `/api/v10/channels/${channelID}/call/stop-ringing`,
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
"Content-Type": "application/json",
|
|
759
|
-
"Content-Length": ringData.length
|
|
598
|
+
body: {
|
|
599
|
+
recipients: userIDs
|
|
760
600
|
}
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
return new Promise(function(resolve) {
|
|
764
|
-
const req = https.request(options, function(res) {
|
|
765
|
-
res.on("end", resolve);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
req.write(ringData);
|
|
769
|
-
req.end();
|
|
770
601
|
});
|
|
771
602
|
}
|
|
772
603
|
|
|
773
|
-
addToChannel(channelID, userID) {
|
|
774
|
-
|
|
775
|
-
...module.exports.APIBaseOpt,
|
|
604
|
+
async addToChannel(channelID, userID) {
|
|
605
|
+
return await this.makeRequest({
|
|
776
606
|
method: "PUT",
|
|
777
607
|
path: `/api/v10/channels/${channelID}/recipients/${userID}`,
|
|
778
|
-
|
|
779
|
-
"Authorization": this.token,
|
|
780
|
-
"Content-Length": 0
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
return new Promise(function(resolve) {
|
|
785
|
-
const req = https.request(options, function(res) {
|
|
786
|
-
res.on("end", resolve);
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
req.write("");
|
|
790
|
-
req.end();
|
|
608
|
+
body: "junkValue"
|
|
791
609
|
});
|
|
792
610
|
}
|
|
793
611
|
|
|
@@ -796,138 +614,78 @@ module.exports = {
|
|
|
796
614
|
|
|
797
615
|
try {
|
|
798
616
|
avatarID = await this.getUserData(userID);
|
|
799
|
-
avatarID = avatarID.
|
|
617
|
+
avatarID = avatarID.avatar;
|
|
800
618
|
} catch(e) {
|
|
801
619
|
return null;
|
|
802
620
|
}
|
|
803
621
|
|
|
804
|
-
|
|
805
|
-
...module.exports.CDNBaseOpt,
|
|
622
|
+
return await this.makeRequest({
|
|
806
623
|
method: "GET",
|
|
807
|
-
path: `/avatars/${userID}/${avatarID}.
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
return new Promise(function(resolve) {
|
|
811
|
-
const req = https.request(options, function(res) {
|
|
812
|
-
const chunks = [];
|
|
813
|
-
|
|
814
|
-
res.on("data", function(chunk) {
|
|
815
|
-
chunks.push(chunk);
|
|
816
|
-
}).on("end", function() {
|
|
817
|
-
resolve(Buffer.concat(chunks));
|
|
818
|
-
});
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
req.end();
|
|
822
|
-
});
|
|
624
|
+
path: `/avatars/${userID}/${avatarID}.png?size=${size}`
|
|
625
|
+
}, module.exports.CDNBaseOpt);
|
|
823
626
|
}
|
|
824
627
|
|
|
825
|
-
addFriend(userID) {
|
|
826
|
-
|
|
827
|
-
...module.exports.APIBaseOpt,
|
|
628
|
+
async addFriend(userID) {
|
|
629
|
+
return await this.makeRequest({
|
|
828
630
|
method: "PUT",
|
|
829
631
|
path: `/api/v10/users/@me/relationships/${userID}`,
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
};
|
|
632
|
+
body: "junkValue"
|
|
633
|
+
});
|
|
634
|
+
}
|
|
835
635
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
res.on("end", resolve);
|
|
839
|
-
});
|
|
636
|
+
async createServer(options) {
|
|
637
|
+
options = options || {};
|
|
840
638
|
|
|
841
|
-
|
|
842
|
-
|
|
639
|
+
const name = options.name ?? "Server";
|
|
640
|
+
const icon = options.icon ?? null;
|
|
641
|
+
|
|
642
|
+
return await this.makeRequest({
|
|
643
|
+
method: "POST",
|
|
644
|
+
path: "/api/v10/guilds",
|
|
645
|
+
body: {
|
|
646
|
+
channels: [],
|
|
647
|
+
guild_template_code: null,
|
|
648
|
+
system_channel_id: null,
|
|
649
|
+
name,
|
|
650
|
+
icon,
|
|
651
|
+
}
|
|
843
652
|
});
|
|
844
653
|
}
|
|
845
654
|
|
|
846
|
-
editMessage(channelID, messageID, newMessage) {
|
|
847
|
-
|
|
848
|
-
const options = {
|
|
849
|
-
...module.exports.APIBaseOpt,
|
|
655
|
+
async editMessage(channelID, messageID, newMessage) {
|
|
656
|
+
return await this.makeRequest({
|
|
850
657
|
method: "PATCH",
|
|
851
658
|
path: `/api/v10/channels/${channelID}/messages/${messageID}`,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
"Content-Type": "application/json",
|
|
855
|
-
"Content-Length": msgData.length
|
|
659
|
+
body: {
|
|
660
|
+
content: newMessage
|
|
856
661
|
}
|
|
857
|
-
};
|
|
858
|
-
|
|
859
|
-
return new Promise(function(resolve) {
|
|
860
|
-
const req = https.request(options, function(res) {
|
|
861
|
-
res.on("end", resolve);
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
req.write(msgData);
|
|
865
|
-
req.end();
|
|
866
662
|
});
|
|
867
663
|
}
|
|
868
664
|
|
|
869
|
-
removeFriend(userID) {
|
|
870
|
-
|
|
871
|
-
...module.exports.APIBaseOpt,
|
|
665
|
+
async removeFriend(userID) {
|
|
666
|
+
return await this.makeRequest({
|
|
872
667
|
method: "DELETE",
|
|
873
|
-
path: `/api/v10/users/@me/relationships/${userID}
|
|
874
|
-
headers: {
|
|
875
|
-
"Authorization": this.token
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
|
|
879
|
-
return new Promise(function(resolve) {
|
|
880
|
-
const req = https.request(options, function(res) {
|
|
881
|
-
res.on("end", resolve);
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
req.end();
|
|
668
|
+
path: `/api/v10/users/@me/relationships/${userID}`
|
|
885
669
|
});
|
|
886
670
|
}
|
|
887
671
|
|
|
888
|
-
renameChannel(channelID, channelName) {
|
|
889
|
-
|
|
890
|
-
const options = {
|
|
891
|
-
...module.exports.APIBaseOpt,
|
|
672
|
+
async renameChannel(channelID, channelName) {
|
|
673
|
+
return await this.makeRequest({
|
|
892
674
|
method: "PATCH",
|
|
893
675
|
path: `/api/v10/channels/${channelID}`,
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
"Content-Type": "application/json",
|
|
897
|
-
"Content-Length": nameData.length
|
|
676
|
+
body: {
|
|
677
|
+
name: channelName
|
|
898
678
|
}
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
return new Promise(function(resolve) {
|
|
902
|
-
const req = https.request(options, function(res) {
|
|
903
|
-
res.on("end", resolve);
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
req.write(nameData);
|
|
907
|
-
req.end();
|
|
908
679
|
});
|
|
909
680
|
}
|
|
910
681
|
|
|
911
|
-
block(userID) {
|
|
912
|
-
|
|
913
|
-
const options = {
|
|
914
|
-
...module.exports.APIBaseOpt,
|
|
682
|
+
async block(userID) {
|
|
683
|
+
return await this.makeRequest({
|
|
915
684
|
method: "PUT",
|
|
916
685
|
path: `/api/v10/users/@me/relationships/${userID}`,
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
"Content-Type": "application/json",
|
|
920
|
-
"Content-Length": blockData.length
|
|
686
|
+
body: {
|
|
687
|
+
type: 2
|
|
921
688
|
}
|
|
922
|
-
};
|
|
923
|
-
|
|
924
|
-
return new Promise(function(resolve) {
|
|
925
|
-
const req = https.request(options, function(res) {
|
|
926
|
-
res.on("end", resolve);
|
|
927
|
-
});
|
|
928
|
-
|
|
929
|
-
req.write(blockData);
|
|
930
|
-
req.end();
|
|
931
689
|
});
|
|
932
690
|
}
|
|
933
691
|
|
|
@@ -937,22 +695,10 @@ module.exports = {
|
|
|
937
695
|
}.bind(this));
|
|
938
696
|
}
|
|
939
697
|
|
|
940
|
-
deleteMessage(channelID, messageID) {
|
|
941
|
-
|
|
942
|
-
...module.exports.APIBaseOpt,
|
|
698
|
+
async deleteMessage(channelID, messageID) {
|
|
699
|
+
return await this.makeRequest({
|
|
943
700
|
method: "DELETE",
|
|
944
|
-
path: `/api/v10/channels/${channelID}/messages/${messageID}
|
|
945
|
-
headers: {
|
|
946
|
-
"Authorization": this.token
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
|
|
950
|
-
return new Promise(function(resolve) {
|
|
951
|
-
const req = https.request(options, function(res) {
|
|
952
|
-
res.on("end", resolve);
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
req.end();
|
|
701
|
+
path: `/api/v10/channels/${channelID}/messages/${messageID}`
|
|
956
702
|
});
|
|
957
703
|
}
|
|
958
704
|
|
|
@@ -972,164 +718,63 @@ module.exports = {
|
|
|
972
718
|
}.bind(this));
|
|
973
719
|
}
|
|
974
720
|
|
|
975
|
-
createGroupChat(userIDs) {
|
|
976
|
-
|
|
977
|
-
const options = {
|
|
978
|
-
...module.exports.APIBaseOpt,
|
|
721
|
+
async createGroupChat(userIDs) {
|
|
722
|
+
return await this.makeRequest({
|
|
979
723
|
method: "POST",
|
|
980
724
|
path: `/api/v10/users/@me/channels`,
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
"Content-Type": "application/json",
|
|
984
|
-
"Content-Length": userData.length
|
|
725
|
+
body: {
|
|
726
|
+
recipients: userIDs
|
|
985
727
|
}
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
return new Promise(function(resolve) {
|
|
989
|
-
const req = https.request(options, function(res) {
|
|
990
|
-
const chunks = [];
|
|
991
|
-
|
|
992
|
-
res.on("data", function(chunk) {
|
|
993
|
-
chunks.push(chunk);
|
|
994
|
-
}).on("end", function() {
|
|
995
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
996
|
-
});
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
req.write(userData);
|
|
1000
|
-
req.end();
|
|
1001
728
|
});
|
|
1002
729
|
}
|
|
1003
730
|
|
|
1004
|
-
startTyping(channelID) {
|
|
1005
|
-
|
|
1006
|
-
...module.exports.APIBaseOpt,
|
|
731
|
+
async startTyping(channelID) {
|
|
732
|
+
return await this.makeRequest({
|
|
1007
733
|
method: "POST",
|
|
1008
734
|
path: `/api/v10/channels/${channelID}/typing`,
|
|
1009
|
-
|
|
1010
|
-
"Authorization": this.token,
|
|
1011
|
-
"Content-Length": 0
|
|
1012
|
-
}
|
|
1013
|
-
};
|
|
1014
|
-
|
|
1015
|
-
return new Promise(function(resolve) {
|
|
1016
|
-
const req = https.request(options, function(res) {
|
|
1017
|
-
res.on("end", resolve);
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
req.write("");
|
|
1021
|
-
req.end();
|
|
735
|
+
body: "junkValue"
|
|
1022
736
|
});
|
|
1023
737
|
}
|
|
1024
738
|
|
|
1025
|
-
pinMessage(channelID, messageID) {
|
|
1026
|
-
|
|
1027
|
-
...module.exports.APIBaseOpt,
|
|
739
|
+
async pinMessage(channelID, messageID) {
|
|
740
|
+
return await this.makeRequest({
|
|
1028
741
|
method: "PUT",
|
|
1029
742
|
path: `/api/v10/channels/${channelID}/pins/${messageID}`,
|
|
1030
|
-
|
|
1031
|
-
"Authorization": this.token,
|
|
1032
|
-
"Content-Length": 0
|
|
1033
|
-
}
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
return new Promise(function(resolve) {
|
|
1037
|
-
const req = https.request(options, function(res) {
|
|
1038
|
-
res.on("end", resolve);
|
|
1039
|
-
});
|
|
1040
|
-
|
|
1041
|
-
req.write("");
|
|
1042
|
-
req.end();
|
|
743
|
+
body: "junkValue"
|
|
1043
744
|
});
|
|
1044
745
|
}
|
|
1045
746
|
|
|
1046
|
-
unpinMessage(channelID, messageID) {
|
|
1047
|
-
|
|
1048
|
-
...module.exports.APIBaseOpt,
|
|
747
|
+
async unpinMessage(channelID, messageID) {
|
|
748
|
+
return await this.makeRequest({
|
|
1049
749
|
method: "DELETE",
|
|
1050
|
-
path: `/api/v10/channels/${channelID}/pins/${messageID}
|
|
1051
|
-
headers: {
|
|
1052
|
-
"Authorization": this.token
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
|
-
return new Promise(function(resolve) {
|
|
1057
|
-
const req = https.request(options, function(res) {
|
|
1058
|
-
res.on("end", resolve);
|
|
1059
|
-
});
|
|
1060
|
-
|
|
1061
|
-
req.end();
|
|
750
|
+
path: `/api/v10/channels/${channelID}/pins/${messageID}`
|
|
1062
751
|
});
|
|
1063
752
|
}
|
|
1064
753
|
|
|
1065
|
-
editNote(userID, note) {
|
|
1066
|
-
|
|
1067
|
-
const options = {
|
|
1068
|
-
...module.exports.APIBaseOpt,
|
|
754
|
+
async editNote(userID, note) {
|
|
755
|
+
return await this.makeRequest({
|
|
1069
756
|
method: "PUT",
|
|
1070
757
|
path: `/api/v10/users/@me/notes/${userID}`,
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
"Content-Type": "application/json",
|
|
1074
|
-
"Content-Length": noteData.length
|
|
758
|
+
body: {
|
|
759
|
+
note
|
|
1075
760
|
}
|
|
1076
|
-
};
|
|
1077
|
-
|
|
1078
|
-
return new Promise(function(resolve) {
|
|
1079
|
-
const req = https.request(options, function(res) {
|
|
1080
|
-
res.on("end", resolve);
|
|
1081
|
-
});
|
|
1082
|
-
|
|
1083
|
-
req.write(noteData);
|
|
1084
|
-
req.end();
|
|
1085
761
|
});
|
|
1086
762
|
}
|
|
1087
763
|
|
|
1088
|
-
getChannelData(channelID) {
|
|
1089
|
-
|
|
1090
|
-
...module.exports.APIBaseOpt,
|
|
764
|
+
async getChannelData(channelID) {
|
|
765
|
+
return await this.makeRequest({
|
|
1091
766
|
method: "GET",
|
|
1092
|
-
path: `/api/v10/channels/${channelID}
|
|
1093
|
-
headers: {
|
|
1094
|
-
"Authorization": this.token
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
|
|
1098
|
-
return new Promise(function(resolve) {
|
|
1099
|
-
const req = https.request(options, function(res) {
|
|
1100
|
-
let chunks = [];
|
|
1101
|
-
|
|
1102
|
-
res.on("data", function(chunk) {
|
|
1103
|
-
chunks.push(chunk);
|
|
1104
|
-
}).on("end", function() {
|
|
1105
|
-
resolve(JSON.parse(Buffer.concat(chunks)));
|
|
1106
|
-
});
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
req.end();
|
|
767
|
+
path: `/api/v10/channels/${channelID}`
|
|
1110
768
|
});
|
|
1111
769
|
}
|
|
1112
770
|
|
|
1113
|
-
transferOwnership(channelID, userID) {
|
|
1114
|
-
|
|
1115
|
-
const options = {
|
|
1116
|
-
...module.exports.APIBaseOpt,
|
|
771
|
+
async transferOwnership(channelID, userID) {
|
|
772
|
+
return await this.makeRequest({
|
|
1117
773
|
method: "PATCH",
|
|
1118
774
|
path: `/api/v10/channels/${channelID}`,
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
"Content-Type": "application/json",
|
|
1122
|
-
"Content-Length": ownershipData.length
|
|
775
|
+
body: {
|
|
776
|
+
owner: userID
|
|
1123
777
|
}
|
|
1124
|
-
};
|
|
1125
|
-
|
|
1126
|
-
return new Promise(function(resolve) {
|
|
1127
|
-
const req = https.request(options, function(res) {
|
|
1128
|
-
res.on("end", resolve);
|
|
1129
|
-
});
|
|
1130
|
-
|
|
1131
|
-
req.write(ownershipData);
|
|
1132
|
-
req.end();
|
|
1133
778
|
});
|
|
1134
779
|
}
|
|
1135
780
|
}
|