@imaentity/selfjs 2.9.10 → 3.0.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.
Files changed (5) hide show
  1. package/README.md +6 -2
  2. package/changelog.log +20 -0
  3. package/docs.md +452 -91
  4. package/package.json +1 -1
  5. package/self.js +149 -561
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 2.9.10
5
+ * @version 3.0.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,
@@ -213,6 +212,41 @@ module.exports = {
213
212
  }.bind(this));
214
213
  }
215
214
 
215
+ makeRequest(options = {}, base = module.exports.APIBaseOpt) {
216
+ const path = options.path || '/';
217
+ const method = options.method || "GET";
218
+ const headers = options.headers || {};
219
+ const body = options.body || undefined;
220
+
221
+ const strBody = module.exports.jsonEncode(body) ?? "";
222
+
223
+ headers["Authorization"] = this.token;
224
+ headers["Content-Type"] = "application/json";
225
+ headers["Content-Length"] = strBody.length;
226
+
227
+ const reqOptions = {
228
+ ...base,
229
+ path,
230
+ method,
231
+ headers
232
+ };
233
+
234
+ return new Promise(function(resolve) {
235
+ const req = https.request(reqOptions, function(res) {
236
+ const chunks = [];
237
+
238
+ res.on("data", function(chunk) {
239
+ chunks.push(chunk);
240
+ }).on("end", function() {
241
+ resolve(JSON.parse(Buffer.concat(chunks)));
242
+ });
243
+ });
244
+
245
+ if(strBody) req.write(strBody);
246
+ req.end();
247
+ });
248
+ }
249
+
216
250
  onMessage(msgFunc) {
217
251
  this.onMessageFunction = msgFunc;
218
252
  }
@@ -229,58 +263,21 @@ module.exports = {
229
263
  this.statusUpdateFunction = statusFunc;
230
264
  }
231
265
 
232
- getDMChannel(userID) {
233
- const channelData = module.exports.jsonEncode({recipients: [userID]});
234
- const options = {
235
- ...module.exports.APIBaseOpt,
266
+ async getDMChannel(userID) {
267
+ return await this.makeRequest({
236
268
  method: "POST",
237
269
  path: "/api/v10/users/@me/channels",
238
- headers: {
239
- "Authorization": this.token,
240
- "Content-Type": "application/json",
241
- "Content-Length": channelData.length
270
+ body: {
271
+ recipients: [userID]
242
272
  }
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
273
  });
259
274
  }
260
275
 
261
- getRoles(serverID, userID) {
262
- const options = {
263
- ...module.exports.APIBaseOpt,
276
+ async getRoles(serverID, userID) {
277
+ return (await this.makeRequest({
264
278
  method: "GET",
265
- path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false&guild_id=${serverID}`,
266
- headers: {
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
- });
279
+ path: `/api/v10/guilds/${serverID}/members/${userID}`,
280
+ })).guild_member.roles;
284
281
  }
285
282
 
286
283
  uploadFile(channelID, fileName, isSpoiled = false, msgContent = "", messageID = null) {
@@ -425,7 +422,7 @@ module.exports = {
425
422
  }.bind(this));
426
423
  }
427
424
 
428
- search(channelID, options) {
425
+ async search(channelID, options) {
429
426
  options = options || {};
430
427
 
431
428
  const pinned = options.pinned ?? null;
@@ -448,346 +445,129 @@ module.exports = {
448
445
  if(mentions != null) path += mentions.map((e) => `mentions=${e}`).join('&') + '&';
449
446
  if(has != null) path += has.map((e) => `has=${e}`).join('&');
450
447
 
451
- const requestOptions = {
452
- ...module.exports.APIBaseOpt,
448
+ return await this.makeRequest({
453
449
  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();
450
+ path: path
472
451
  });
473
452
  }
474
453
 
475
- getUserData(userID) {
476
- const options = {
477
- ...module.exports.APIBaseOpt,
454
+ async getUserData(userID) {
455
+ return await this.makeRequest({
478
456
  method: "GET",
479
- path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false`,
480
- headers: {
481
- "Authorization": this.token
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
- });
495
-
496
- req.end();
457
+ path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false`
497
458
  });
498
459
  }
499
460
 
500
- setRolesForMemeber(serverID, userID, roleIDs) {
501
- const roleData = module.exports.jsonEncode(roleIDs);
502
- const options = {
503
- ...module.exports.APIBaseOpt,
461
+ async setRolesForMemeber(serverID, userID, roleIDs) {
462
+ return await this.makeRequest({
504
463
  method: "PATCH",
505
464
  path: `/api/v10/guilds/${serverID}/members/${userID}`,
506
- headers: {
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();
465
+ body: roleIDs
520
466
  });
521
467
  }
522
468
 
523
- sendMessage(channelID, message) {
524
- const msgData = module.exports.jsonEncode({content: message});
525
- const options = {
526
- ...module.exports.APIBaseOpt,
469
+ async sendMessage(channelID, message) {
470
+ return await this.makeRequest({
527
471
  method: "POST",
528
472
  path: `/api/v10/channels/${channelID}/messages`,
529
- headers: {
530
- "Authorization": this.token,
531
- "Content-Type": "application/json",
532
- "Content-Length": msgData.length
473
+ body: {
474
+ content: message
533
475
  }
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
476
  });
550
477
  }
551
478
 
552
- replyToMessage(channelID, messageID, message) {
553
- const msgData = module.exports.jsonEncode({content: message, message_reference: {channel_id: channelID, message_id: messageID}});
554
- const options = {
555
- ...module.exports.APIBaseOpt,
479
+ async replyToMessage(channelID, messageID, message) {
480
+ return await this.makeRequest({
556
481
  method: "POST",
557
482
  path: `/api/v10/channels/${channelID}/messages`,
558
- headers: {
559
- "Authorization": this.token,
560
- "Content-Type": "application/json",
561
- "Content-Length": msgData.length
483
+ body: {
484
+ content: message,
485
+ message_reference: {
486
+ channel_id: channelID,
487
+ message_id: messageID
488
+ }
562
489
  }
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
490
  });
579
491
  }
580
492
 
581
- createChannel(guildID, name, type, parentID = null) {
582
- const channelData = module.exports.jsonEncode({name, type, parent_id: parentID});
583
- const options = {
584
- ...module.exports.APIBaseOpt,
493
+ async createChannel(guildID, name, type, parentID = null) {
494
+ return await this.makeRequest({
585
495
  method: "POST",
586
496
  path: `/api/v10/guilds/${guildID}/channels`,
587
- headers: {
588
- "Authorization": this.token,
589
- "Content-Type": "application/json",
590
- "Content-Length": channelData.length
497
+ body: {
498
+ name,
499
+ type,
500
+ parent_id: parentID
591
501
  }
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
502
  });
608
503
  }
609
504
 
610
- setChannelPermissions(channelID, userID, allow, deny) {
611
- const permissionData = module.exports.jsonEncode({id: userID, allow, deny, type: 1});
612
- const options = {
613
- ...module.exports.APIBaseOpt,
505
+ async setChannelPermissions(channelID, userID, allow, deny) {
506
+ return await this.makeRequest({
614
507
  method: "PUT",
615
508
  path: `/api/v10/channels/${channelID}/permissions/${userID}`,
616
- headers: {
617
- "Authorization": this.token,
618
- "Content-Type": "application/json",
619
- "Content-Length": permissionData.length
509
+ body: {
510
+ id: userID,
511
+ allow,
512
+ deny,
513
+ type: 1
620
514
  }
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
515
  });
637
516
  }
638
517
 
639
- getMessages(channelID, limit) {
640
- const options = {
641
- ...module.exports.APIBaseOpt,
518
+ async getMessages(channelID, limit) {
519
+ return await this.makeRequest({
642
520
  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();
521
+ path: `/api/v10/channels/${channelID}/messages?limit=${limit}`
661
522
  });
662
523
  }
663
524
 
664
- getUsers(guildID) {
665
- const options = {
666
- ...module.exports.APIBaseOpt,
525
+ async getUsers(guildID) {
526
+ return await this.makeRequest({
667
527
  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();
528
+ path: `/api/v10/guilds/${guildID}/members`
686
529
  });
687
530
  }
688
531
 
689
- removeFromChannel(channelID, userID) {
690
- const options = {
691
- ...module.exports.APIBaseOpt,
532
+ async removeFromChannel(channelID, userID) {
533
+ return await this.makeRequest({
692
534
  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();
535
+ path: `/api/v10/channels/${channelID}/recipients/${userID}`
705
536
  });
706
537
  }
707
538
 
708
- leaveChannel(channelID) {
709
- const options = {
710
- ...module.exports.APIBaseOpt,
539
+ async leaveChannel(channelID) {
540
+ return await this.makeRequest({
711
541
  method: "DELETE",
712
- path: `/api/v10/channels/${channelID}`,
713
- headers: {
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));
542
+ path: `/api/v10/channels/${channelID}`
543
+ });
725
544
  }
726
545
 
727
- ring(channelID, userIDs) {
728
- const ringData = module.exports.jsonEncode({recipients: userIDs});
729
- const options = {
730
- ...module.exports.APIBaseOpt,
546
+ async ring(channelID, userIDs) {
547
+ return await this.makeRequest({
731
548
  method: "POST",
732
549
  path: `/api/v10/channels/${channelID}/call/ring`,
733
- headers: {
734
- "Authorization": this.token,
735
- "Content-Type": "application/json",
736
- "Content-Length": ringData.length
550
+ body: {
551
+ recipients: userIDs
737
552
  }
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
553
  });
748
554
  }
749
555
 
750
- stopRinging(channelID, userIDs) {
751
- const ringData = module.exports.jsonEncode({recipients: userIDs});
752
- const options = {
753
- ...module.exports.APIBaseOpt,
556
+ async stopRinging(channelID, userIDs) {
557
+ return await this.makeRequest({
754
558
  method: "POST",
755
559
  path: `/api/v10/channels/${channelID}/call/stop-ringing`,
756
- headers: {
757
- "Authorization": this.token,
758
- "Content-Type": "application/json",
759
- "Content-Length": ringData.length
560
+ body: {
561
+ recipients: userIDs
760
562
  }
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
563
  });
771
564
  }
772
565
 
773
- addToChannel(channelID, userID) {
774
- const options = {
775
- ...module.exports.APIBaseOpt,
566
+ async addToChannel(channelID, userID) {
567
+ return await this.makeRequest({
776
568
  method: "PUT",
777
569
  path: `/api/v10/channels/${channelID}/recipients/${userID}`,
778
- headers: {
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();
570
+ body: "junkValue"
791
571
  });
792
572
  }
793
573
 
@@ -801,133 +581,54 @@ module.exports = {
801
581
  return null;
802
582
  }
803
583
 
804
- const options = {
805
- ...module.exports.CDNBaseOpt,
584
+ return await this.makeRequest({
806
585
  method: "GET",
807
586
  path: `/avatars/${userID}/${avatarID}.webp?size=${size}`
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
- });
587
+ }, module.exports.CDNBaseOpt);
823
588
  }
824
589
 
825
- addFriend(userID) {
826
- const options = {
827
- ...module.exports.APIBaseOpt,
590
+ async addFriend(userID) {
591
+ return await this.makeRequest({
828
592
  method: "PUT",
829
593
  path: `/api/v10/users/@me/relationships/${userID}`,
830
- headers: {
831
- "Authorization": this.token,
832
- "Content-Length": 0
833
- }
834
- };
835
-
836
- return new Promise(function(resolve) {
837
- const req = https.request(options, function(res) {
838
- res.on("end", resolve);
839
- });
840
-
841
- req.write("");
842
- req.end();
594
+ body: "junkValue"
843
595
  });
844
596
  }
845
597
 
846
- editMessage(channelID, messageID, newMessage) {
847
- const msgData = module.exports.jsonEncode({content: newMessage});
848
- const options = {
849
- ...module.exports.APIBaseOpt,
598
+ async editMessage(channelID, messageID, newMessage) {
599
+ return await this.makeRequest({
850
600
  method: "PATCH",
851
601
  path: `/api/v10/channels/${channelID}/messages/${messageID}`,
852
- headers: {
853
- "Authorization": this.token,
854
- "Content-Type": "application/json",
855
- "Content-Length": msgData.length
602
+ body: {
603
+ content: newMessage
856
604
  }
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
605
  });
867
606
  }
868
607
 
869
- removeFriend(userID) {
870
- const options = {
871
- ...module.exports.APIBaseOpt,
608
+ async removeFriend(userID) {
609
+ return await this.makeRequest({
872
610
  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();
611
+ path: `/api/v10/users/@me/relationships/${userID}`
885
612
  });
886
613
  }
887
614
 
888
- renameChannel(channelID, channelName) {
889
- const nameData = module.exports.jsonEncode({name: channelName});
890
- const options = {
891
- ...module.exports.APIBaseOpt,
615
+ async renameChannel(channelID, channelName) {
616
+ return await this.makeRequest({
892
617
  method: "PATCH",
893
618
  path: `/api/v10/channels/${channelID}`,
894
- headers: {
895
- "Authorization": this.token,
896
- "Content-Type": "application/json",
897
- "Content-Length": nameData.length
619
+ body: {
620
+ name: channelName
898
621
  }
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
622
  });
909
623
  }
910
624
 
911
- block(userID) {
912
- const blockData = module.exports.jsonEncode({type: 2});
913
- const options = {
914
- ...module.exports.APIBaseOpt,
625
+ async block(userID) {
626
+ return await this.makeRequest({
915
627
  method: "PUT",
916
628
  path: `/api/v10/users/@me/relationships/${userID}`,
917
- headers: {
918
- "Authorization": this.token,
919
- "Content-Type": "application/json",
920
- "Content-Length": blockData.length
629
+ body: {
630
+ type: 2
921
631
  }
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
632
  });
932
633
  }
933
634
 
@@ -937,22 +638,10 @@ module.exports = {
937
638
  }.bind(this));
938
639
  }
939
640
 
940
- deleteMessage(channelID, messageID) {
941
- const options = {
942
- ...module.exports.APIBaseOpt,
641
+ async deleteMessage(channelID, messageID) {
642
+ return await this.makeRequest({
943
643
  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();
644
+ path: `/api/v10/channels/${channelID}/messages/${messageID}`
956
645
  });
957
646
  }
958
647
 
@@ -972,164 +661,63 @@ module.exports = {
972
661
  }.bind(this));
973
662
  }
974
663
 
975
- createGroupChat(userIDs) {
976
- const userData = module.exports.jsonEncode({recipients: userIDs});
977
- const options = {
978
- ...module.exports.APIBaseOpt,
664
+ async createGroupChat(userIDs) {
665
+ return await this.makeRequest({
979
666
  method: "POST",
980
667
  path: `/api/v10/users/@me/channels`,
981
- headers: {
982
- "Authorization": this.token,
983
- "Content-Type": "application/json",
984
- "Content-Length": userData.length
668
+ body: {
669
+ recipients: userIDs
985
670
  }
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
671
  });
1002
672
  }
1003
673
 
1004
- startTyping(channelID) {
1005
- const options = {
1006
- ...module.exports.APIBaseOpt,
674
+ async startTyping(channelID) {
675
+ return await this.makeRequest({
1007
676
  method: "POST",
1008
677
  path: `/api/v10/channels/${channelID}/typing`,
1009
- headers: {
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();
678
+ body: "junkValue"
1022
679
  });
1023
680
  }
1024
681
 
1025
- pinMessage(channelID, messageID) {
1026
- const options = {
1027
- ...module.exports.APIBaseOpt,
682
+ async pinMessage(channelID, messageID) {
683
+ return await this.makeRequest({
1028
684
  method: "PUT",
1029
685
  path: `/api/v10/channels/${channelID}/pins/${messageID}`,
1030
- headers: {
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();
686
+ body: "junkValue"
1043
687
  });
1044
688
  }
1045
689
 
1046
- unpinMessage(channelID, messageID) {
1047
- const options = {
1048
- ...module.exports.APIBaseOpt,
690
+ async unpinMessage(channelID, messageID) {
691
+ return await this.makeRequest({
1049
692
  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();
693
+ path: `/api/v10/channels/${channelID}/pins/${messageID}`
1062
694
  });
1063
695
  }
1064
696
 
1065
- editNote(userID, note) {
1066
- const noteData = module.exports.jsonEncode({note});
1067
- const options = {
1068
- ...module.exports.APIBaseOpt,
697
+ async editNote(userID, note) {
698
+ return await this.makeRequest({
1069
699
  method: "PUT",
1070
700
  path: `/api/v10/users/@me/notes/${userID}`,
1071
- headers: {
1072
- "Authorization": this.token,
1073
- "Content-Type": "application/json",
1074
- "Content-Length": noteData.length
701
+ body: {
702
+ note
1075
703
  }
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
704
  });
1086
705
  }
1087
706
 
1088
- getChannelData(channelID) {
1089
- const options = {
1090
- ...module.exports.APIBaseOpt,
707
+ async getChannelData(channelID) {
708
+ return await this.makeRequest({
1091
709
  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();
710
+ path: `/api/v10/channels/${channelID}`
1110
711
  });
1111
712
  }
1112
713
 
1113
- transferOwnership(channelID, userID) {
1114
- const ownershipData = module.exports.jsonEncode({owner: userID});
1115
- const options = {
1116
- ...module.exports.APIBaseOpt,
714
+ async transferOwnership(channelID, userID) {
715
+ return await this.makeRequest({
1117
716
  method: "PATCH",
1118
717
  path: `/api/v10/channels/${channelID}`,
1119
- headers: {
1120
- "Authorization": this.token,
1121
- "Content-Type": "application/json",
1122
- "Content-Length": ownershipData.length
718
+ body: {
719
+ owner: userID
1123
720
  }
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
721
  });
1134
722
  }
1135
723
  }