@imaentity/selfjs 1.9.10 → 2.9.11
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/changelog.log +5 -0
- package/docs.md +2 -0
- package/package.json +1 -1
- package/self.js +36 -26
package/changelog.log
ADDED
package/docs.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- **sendWebhookMessage(webhookID, webhookToken, inputData)**: A function to send a webhook message. The webhook token and ID are provided, along with any input data.
|
|
8
8
|
|
|
9
|
+
- **jsonEncode(jsonObject)**: Encodes a JSON object for use with the discord API. (Self does this automatically.)
|
|
10
|
+
|
|
9
11
|
# Class
|
|
10
12
|
- **Client**: This class allows the interaction with the Discord server. The following are its methods:
|
|
11
13
|
|
package/package.json
CHANGED
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 2.9.11
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const https = require("https");
|
|
@@ -36,12 +36,22 @@ module.exports = {
|
|
|
36
36
|
});
|
|
37
37
|
},
|
|
38
38
|
|
|
39
|
+
jsonEncode: function(jsonData) {
|
|
40
|
+
const str = JSON.stringify(jsonData);
|
|
41
|
+
|
|
42
|
+
return str.replace(/[\u007F-\uFFFF]/g, function(chr) {
|
|
43
|
+
const code = chr.charCodeAt(0).toString(16);
|
|
44
|
+
|
|
45
|
+
return "\\u" + new Array(4 - code.length).fill('0').join("") + code;
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
|
|
39
49
|
sendWebhookMessage: function(webhookID, webhookToken, inputData) {
|
|
40
50
|
let options = null;
|
|
41
51
|
let msgData = null;
|
|
42
52
|
|
|
43
53
|
if(inputData) {
|
|
44
|
-
msgData =
|
|
54
|
+
msgData = module.exports.jsonEncode(inputData);
|
|
45
55
|
options = {
|
|
46
56
|
...module.exports.APIBaseOpt,
|
|
47
57
|
method: "POST",
|
|
@@ -52,7 +62,7 @@ module.exports = {
|
|
|
52
62
|
}
|
|
53
63
|
};
|
|
54
64
|
} else {
|
|
55
|
-
msgData =
|
|
65
|
+
msgData = module.exports.jsonEncode(webhookToken);
|
|
56
66
|
options = {
|
|
57
67
|
...module.exports.APIBaseOpt,
|
|
58
68
|
method: "POST",
|
|
@@ -101,7 +111,7 @@ module.exports = {
|
|
|
101
111
|
this.socket.on("open", function() {
|
|
102
112
|
if(logMsgs) console.log("[MainControlSocket] Sending hello");
|
|
103
113
|
|
|
104
|
-
this.socket.send(
|
|
114
|
+
this.socket.send(module.exports.jsonEncode({
|
|
105
115
|
op: 2,
|
|
106
116
|
d: {
|
|
107
117
|
token: this.token,
|
|
@@ -122,12 +132,12 @@ module.exports = {
|
|
|
122
132
|
|
|
123
133
|
if(logMsgs) console.log("[MainControlSocket] Sending heartbeat");
|
|
124
134
|
this.beforeHB = Date.now();
|
|
125
|
-
this.socket.send(
|
|
135
|
+
this.socket.send(module.exports.jsonEncode({op: 1, d: this.sequenceID}));
|
|
126
136
|
|
|
127
137
|
this.hearbeatInterval = setInterval(function() {
|
|
128
138
|
if(logMsgs) console.log("[MainControlSocket] Sending heartbeat");
|
|
129
139
|
this.beforeHB = Date.now();
|
|
130
|
-
this.socket.send(
|
|
140
|
+
this.socket.send(module.exports.jsonEncode({op: 1, d: this.sequenceID}));
|
|
131
141
|
}.bind(this), payload.d.heartbeat_interval);
|
|
132
142
|
} else if(payload.op == 11) {
|
|
133
143
|
if(logMsgs) console.log("[MainControlSocket] Heartbeat ACK received");
|
|
@@ -143,7 +153,7 @@ module.exports = {
|
|
|
143
153
|
if(logMsgs) console.log("[MainControlSocket] Ready message received");
|
|
144
154
|
resolve();
|
|
145
155
|
} else if(payload.t == "MESSAGE_CREATE") {
|
|
146
|
-
const ackData =
|
|
156
|
+
const ackData = module.exports.jsonEncode({token: null});
|
|
147
157
|
const options = {
|
|
148
158
|
...module.exports.APIBaseOpt,
|
|
149
159
|
method: "POST",
|
|
@@ -185,7 +195,7 @@ module.exports = {
|
|
|
185
195
|
this.socket.on("open", function() {
|
|
186
196
|
if(logMsgs) console.log("[MainControlSocket] Resume message sent");
|
|
187
197
|
|
|
188
|
-
this.socket.send(
|
|
198
|
+
this.socket.send(module.exports.jsonEncode({
|
|
189
199
|
op: 6,
|
|
190
200
|
d: {
|
|
191
201
|
token: this.token,
|
|
@@ -220,7 +230,7 @@ module.exports = {
|
|
|
220
230
|
}
|
|
221
231
|
|
|
222
232
|
getDMChannel(userID) {
|
|
223
|
-
const channelData =
|
|
233
|
+
const channelData = module.exports.jsonEncode({recipients: [userID]});
|
|
224
234
|
const options = {
|
|
225
235
|
...module.exports.APIBaseOpt,
|
|
226
236
|
method: "POST",
|
|
@@ -280,7 +290,7 @@ module.exports = {
|
|
|
280
290
|
|
|
281
291
|
fileName = fileName.split('/').pop();
|
|
282
292
|
|
|
283
|
-
const requestData =
|
|
293
|
+
const requestData = module.exports.jsonEncode({
|
|
284
294
|
files: [
|
|
285
295
|
{
|
|
286
296
|
filename: fileName,
|
|
@@ -358,7 +368,7 @@ module.exports = {
|
|
|
358
368
|
fileRes.on("data", function(chunk) {
|
|
359
369
|
fileChunks.push(chunk);
|
|
360
370
|
}).on("end", function() {
|
|
361
|
-
let finalData =
|
|
371
|
+
let finalData = module.exports.jsonEncode({
|
|
362
372
|
content: msgContent,
|
|
363
373
|
attachments: [
|
|
364
374
|
{
|
|
@@ -376,7 +386,7 @@ module.exports = {
|
|
|
376
386
|
message_id: messageID
|
|
377
387
|
};
|
|
378
388
|
|
|
379
|
-
finalData =
|
|
389
|
+
finalData = module.exports.jsonEncode(finalData);
|
|
380
390
|
}
|
|
381
391
|
|
|
382
392
|
const finalOptions = {
|
|
@@ -488,7 +498,7 @@ module.exports = {
|
|
|
488
498
|
}
|
|
489
499
|
|
|
490
500
|
setRolesForMemeber(serverID, userID, roleIDs) {
|
|
491
|
-
const roleData =
|
|
501
|
+
const roleData = module.exports.jsonEncode(roleIDs);
|
|
492
502
|
const options = {
|
|
493
503
|
...module.exports.APIBaseOpt,
|
|
494
504
|
method: "PATCH",
|
|
@@ -511,7 +521,7 @@ module.exports = {
|
|
|
511
521
|
}
|
|
512
522
|
|
|
513
523
|
sendMessage(channelID, message) {
|
|
514
|
-
const msgData =
|
|
524
|
+
const msgData = module.exports.jsonEncode({content: message});
|
|
515
525
|
const options = {
|
|
516
526
|
...module.exports.APIBaseOpt,
|
|
517
527
|
method: "POST",
|
|
@@ -540,7 +550,7 @@ module.exports = {
|
|
|
540
550
|
}
|
|
541
551
|
|
|
542
552
|
replyToMessage(channelID, messageID, message) {
|
|
543
|
-
const msgData =
|
|
553
|
+
const msgData = module.exports.jsonEncode({content: message, message_reference: {channel_id: channelID, message_id: messageID}});
|
|
544
554
|
const options = {
|
|
545
555
|
...module.exports.APIBaseOpt,
|
|
546
556
|
method: "POST",
|
|
@@ -569,7 +579,7 @@ module.exports = {
|
|
|
569
579
|
}
|
|
570
580
|
|
|
571
581
|
createChannel(guildID, name, type, parentID = null) {
|
|
572
|
-
const channelData =
|
|
582
|
+
const channelData = module.exports.jsonEncode({name, type, parent_id: parentID});
|
|
573
583
|
const options = {
|
|
574
584
|
...module.exports.APIBaseOpt,
|
|
575
585
|
method: "POST",
|
|
@@ -598,7 +608,7 @@ module.exports = {
|
|
|
598
608
|
}
|
|
599
609
|
|
|
600
610
|
setChannelPermissions(channelID, userID, allow, deny) {
|
|
601
|
-
const permissionData =
|
|
611
|
+
const permissionData = module.exports.jsonEncode({id: userID, allow, deny, type: 1});
|
|
602
612
|
const options = {
|
|
603
613
|
...module.exports.APIBaseOpt,
|
|
604
614
|
method: "PUT",
|
|
@@ -715,7 +725,7 @@ module.exports = {
|
|
|
715
725
|
}
|
|
716
726
|
|
|
717
727
|
ring(channelID, userIDs) {
|
|
718
|
-
const ringData =
|
|
728
|
+
const ringData = module.exports.jsonEncode({recipients: userIDs});
|
|
719
729
|
const options = {
|
|
720
730
|
...module.exports.APIBaseOpt,
|
|
721
731
|
method: "POST",
|
|
@@ -738,7 +748,7 @@ module.exports = {
|
|
|
738
748
|
}
|
|
739
749
|
|
|
740
750
|
stopRinging(channelID, userIDs) {
|
|
741
|
-
const ringData =
|
|
751
|
+
const ringData = module.exports.jsonEncode({recipients: userIDs});
|
|
742
752
|
const options = {
|
|
743
753
|
...module.exports.APIBaseOpt,
|
|
744
754
|
method: "POST",
|
|
@@ -834,7 +844,7 @@ module.exports = {
|
|
|
834
844
|
}
|
|
835
845
|
|
|
836
846
|
editMessage(channelID, messageID, newMessage) {
|
|
837
|
-
const msgData =
|
|
847
|
+
const msgData = module.exports.jsonEncode({content: newMessage});
|
|
838
848
|
const options = {
|
|
839
849
|
...module.exports.APIBaseOpt,
|
|
840
850
|
method: "PATCH",
|
|
@@ -876,7 +886,7 @@ module.exports = {
|
|
|
876
886
|
}
|
|
877
887
|
|
|
878
888
|
renameChannel(channelID, channelName) {
|
|
879
|
-
const nameData =
|
|
889
|
+
const nameData = module.exports.jsonEncode({name: channelName});
|
|
880
890
|
const options = {
|
|
881
891
|
...module.exports.APIBaseOpt,
|
|
882
892
|
method: "PATCH",
|
|
@@ -899,7 +909,7 @@ module.exports = {
|
|
|
899
909
|
}
|
|
900
910
|
|
|
901
911
|
block(userID) {
|
|
902
|
-
const blockData =
|
|
912
|
+
const blockData = module.exports.jsonEncode({type: 2});
|
|
903
913
|
const options = {
|
|
904
914
|
...module.exports.APIBaseOpt,
|
|
905
915
|
method: "PUT",
|
|
@@ -948,7 +958,7 @@ module.exports = {
|
|
|
948
958
|
|
|
949
959
|
setStatus(status, activities, afk = false) {
|
|
950
960
|
return new Promise(function (resolve) {
|
|
951
|
-
this.socket.send(
|
|
961
|
+
this.socket.send(module.exports.jsonEncode({
|
|
952
962
|
op: 3,
|
|
953
963
|
d: {
|
|
954
964
|
since: Date.now(),
|
|
@@ -963,7 +973,7 @@ module.exports = {
|
|
|
963
973
|
}
|
|
964
974
|
|
|
965
975
|
createGroupChat(userIDs) {
|
|
966
|
-
const userData =
|
|
976
|
+
const userData = module.exports.jsonEncode({recipients: userIDs});
|
|
967
977
|
const options = {
|
|
968
978
|
...module.exports.APIBaseOpt,
|
|
969
979
|
method: "POST",
|
|
@@ -1053,7 +1063,7 @@ module.exports = {
|
|
|
1053
1063
|
}
|
|
1054
1064
|
|
|
1055
1065
|
editNote(userID, note) {
|
|
1056
|
-
const noteData =
|
|
1066
|
+
const noteData = module.exports.jsonEncode({note});
|
|
1057
1067
|
const options = {
|
|
1058
1068
|
...module.exports.APIBaseOpt,
|
|
1059
1069
|
method: "PUT",
|
|
@@ -1101,7 +1111,7 @@ module.exports = {
|
|
|
1101
1111
|
}
|
|
1102
1112
|
|
|
1103
1113
|
transferOwnership(channelID, userID) {
|
|
1104
|
-
const ownershipData =
|
|
1114
|
+
const ownershipData = module.exports.jsonEncode({owner: userID});
|
|
1105
1115
|
const options = {
|
|
1106
1116
|
...module.exports.APIBaseOpt,
|
|
1107
1117
|
method: "PATCH",
|