@imaentity/selfjs 1.9.9 → 2.9.10
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/docs.md +2 -0
- package/package.json +1 -1
- package/self.js +41 -27
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.10
|
|
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",
|
|
@@ -88,6 +98,7 @@ module.exports = {
|
|
|
88
98
|
this.messageDeleteFunction = null;
|
|
89
99
|
this.latency = null;
|
|
90
100
|
this.beforeHB = null;
|
|
101
|
+
this.hearbeatInterval = null;
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
login(token, isMobile = false, logMsgs = false) {
|
|
@@ -100,7 +111,7 @@ module.exports = {
|
|
|
100
111
|
this.socket.on("open", function() {
|
|
101
112
|
if(logMsgs) console.log("[MainControlSocket] Sending hello");
|
|
102
113
|
|
|
103
|
-
this.socket.send(
|
|
114
|
+
this.socket.send(module.exports.jsonEncode({
|
|
104
115
|
op: 2,
|
|
105
116
|
d: {
|
|
106
117
|
token: this.token,
|
|
@@ -121,12 +132,12 @@ module.exports = {
|
|
|
121
132
|
|
|
122
133
|
if(logMsgs) console.log("[MainControlSocket] Sending heartbeat");
|
|
123
134
|
this.beforeHB = Date.now();
|
|
124
|
-
this.socket.send(
|
|
135
|
+
this.socket.send(module.exports.jsonEncode({op: 1, d: this.sequenceID}));
|
|
125
136
|
|
|
126
|
-
setInterval(function() {
|
|
137
|
+
this.hearbeatInterval = setInterval(function() {
|
|
127
138
|
if(logMsgs) console.log("[MainControlSocket] Sending heartbeat");
|
|
128
139
|
this.beforeHB = Date.now();
|
|
129
|
-
this.socket.send(
|
|
140
|
+
this.socket.send(module.exports.jsonEncode({op: 1, d: this.sequenceID}));
|
|
130
141
|
}.bind(this), payload.d.heartbeat_interval);
|
|
131
142
|
} else if(payload.op == 11) {
|
|
132
143
|
if(logMsgs) console.log("[MainControlSocket] Heartbeat ACK received");
|
|
@@ -142,7 +153,7 @@ module.exports = {
|
|
|
142
153
|
if(logMsgs) console.log("[MainControlSocket] Ready message received");
|
|
143
154
|
resolve();
|
|
144
155
|
} else if(payload.t == "MESSAGE_CREATE") {
|
|
145
|
-
const ackData =
|
|
156
|
+
const ackData = module.exports.jsonEncode({token: null});
|
|
146
157
|
const options = {
|
|
147
158
|
...module.exports.APIBaseOpt,
|
|
148
159
|
method: "POST",
|
|
@@ -176,12 +187,15 @@ module.exports = {
|
|
|
176
187
|
} else if(payload.op == 7) {
|
|
177
188
|
if(logMsgs) console.log("[MainControlSocket] Reconnect message received");
|
|
178
189
|
|
|
190
|
+
if(this.hearbeatInterval) clearInterval(this.hearbeatInterval);
|
|
191
|
+
this.socket.terminate();
|
|
192
|
+
|
|
179
193
|
this.socket = new ws("wss://gateway.discord.gg?v=10&encoding=json");
|
|
180
194
|
|
|
181
195
|
this.socket.on("open", function() {
|
|
182
196
|
if(logMsgs) console.log("[MainControlSocket] Resume message sent");
|
|
183
197
|
|
|
184
|
-
this.socket.send(
|
|
198
|
+
this.socket.send(module.exports.jsonEncode({
|
|
185
199
|
op: 6,
|
|
186
200
|
d: {
|
|
187
201
|
token: this.token,
|
|
@@ -216,7 +230,7 @@ module.exports = {
|
|
|
216
230
|
}
|
|
217
231
|
|
|
218
232
|
getDMChannel(userID) {
|
|
219
|
-
const channelData =
|
|
233
|
+
const channelData = module.exports.jsonEncode({recipients: [userID]});
|
|
220
234
|
const options = {
|
|
221
235
|
...module.exports.APIBaseOpt,
|
|
222
236
|
method: "POST",
|
|
@@ -276,7 +290,7 @@ module.exports = {
|
|
|
276
290
|
|
|
277
291
|
fileName = fileName.split('/').pop();
|
|
278
292
|
|
|
279
|
-
const requestData =
|
|
293
|
+
const requestData = module.exports.jsonEncode({
|
|
280
294
|
files: [
|
|
281
295
|
{
|
|
282
296
|
filename: fileName,
|
|
@@ -354,7 +368,7 @@ module.exports = {
|
|
|
354
368
|
fileRes.on("data", function(chunk) {
|
|
355
369
|
fileChunks.push(chunk);
|
|
356
370
|
}).on("end", function() {
|
|
357
|
-
let finalData =
|
|
371
|
+
let finalData = module.exports.jsonEncode({
|
|
358
372
|
content: msgContent,
|
|
359
373
|
attachments: [
|
|
360
374
|
{
|
|
@@ -372,7 +386,7 @@ module.exports = {
|
|
|
372
386
|
message_id: messageID
|
|
373
387
|
};
|
|
374
388
|
|
|
375
|
-
finalData =
|
|
389
|
+
finalData = module.exports.jsonEncode(finalData);
|
|
376
390
|
}
|
|
377
391
|
|
|
378
392
|
const finalOptions = {
|
|
@@ -484,7 +498,7 @@ module.exports = {
|
|
|
484
498
|
}
|
|
485
499
|
|
|
486
500
|
setRolesForMemeber(serverID, userID, roleIDs) {
|
|
487
|
-
const roleData =
|
|
501
|
+
const roleData = module.exports.jsonEncode(roleIDs);
|
|
488
502
|
const options = {
|
|
489
503
|
...module.exports.APIBaseOpt,
|
|
490
504
|
method: "PATCH",
|
|
@@ -507,7 +521,7 @@ module.exports = {
|
|
|
507
521
|
}
|
|
508
522
|
|
|
509
523
|
sendMessage(channelID, message) {
|
|
510
|
-
const msgData =
|
|
524
|
+
const msgData = module.exports.jsonEncode({content: message});
|
|
511
525
|
const options = {
|
|
512
526
|
...module.exports.APIBaseOpt,
|
|
513
527
|
method: "POST",
|
|
@@ -536,7 +550,7 @@ module.exports = {
|
|
|
536
550
|
}
|
|
537
551
|
|
|
538
552
|
replyToMessage(channelID, messageID, message) {
|
|
539
|
-
const msgData =
|
|
553
|
+
const msgData = module.exports.jsonEncode({content: message, message_reference: {channel_id: channelID, message_id: messageID}});
|
|
540
554
|
const options = {
|
|
541
555
|
...module.exports.APIBaseOpt,
|
|
542
556
|
method: "POST",
|
|
@@ -565,7 +579,7 @@ module.exports = {
|
|
|
565
579
|
}
|
|
566
580
|
|
|
567
581
|
createChannel(guildID, name, type, parentID = null) {
|
|
568
|
-
const channelData =
|
|
582
|
+
const channelData = module.exports.jsonEncode({name, type, parent_id: parentID});
|
|
569
583
|
const options = {
|
|
570
584
|
...module.exports.APIBaseOpt,
|
|
571
585
|
method: "POST",
|
|
@@ -594,7 +608,7 @@ module.exports = {
|
|
|
594
608
|
}
|
|
595
609
|
|
|
596
610
|
setChannelPermissions(channelID, userID, allow, deny) {
|
|
597
|
-
const permissionData =
|
|
611
|
+
const permissionData = module.exports.jsonEncode({id: userID, allow, deny, type: 1});
|
|
598
612
|
const options = {
|
|
599
613
|
...module.exports.APIBaseOpt,
|
|
600
614
|
method: "PUT",
|
|
@@ -711,7 +725,7 @@ module.exports = {
|
|
|
711
725
|
}
|
|
712
726
|
|
|
713
727
|
ring(channelID, userIDs) {
|
|
714
|
-
const ringData =
|
|
728
|
+
const ringData = module.exports.jsonEncode({recipients: userIDs});
|
|
715
729
|
const options = {
|
|
716
730
|
...module.exports.APIBaseOpt,
|
|
717
731
|
method: "POST",
|
|
@@ -734,7 +748,7 @@ module.exports = {
|
|
|
734
748
|
}
|
|
735
749
|
|
|
736
750
|
stopRinging(channelID, userIDs) {
|
|
737
|
-
const ringData =
|
|
751
|
+
const ringData = module.exports.jsonEncode({recipients: userIDs});
|
|
738
752
|
const options = {
|
|
739
753
|
...module.exports.APIBaseOpt,
|
|
740
754
|
method: "POST",
|
|
@@ -830,7 +844,7 @@ module.exports = {
|
|
|
830
844
|
}
|
|
831
845
|
|
|
832
846
|
editMessage(channelID, messageID, newMessage) {
|
|
833
|
-
const msgData =
|
|
847
|
+
const msgData = module.exports.jsonEncode({content: newMessage});
|
|
834
848
|
const options = {
|
|
835
849
|
...module.exports.APIBaseOpt,
|
|
836
850
|
method: "PATCH",
|
|
@@ -872,7 +886,7 @@ module.exports = {
|
|
|
872
886
|
}
|
|
873
887
|
|
|
874
888
|
renameChannel(channelID, channelName) {
|
|
875
|
-
const nameData =
|
|
889
|
+
const nameData = module.exports.jsonEncode({name: channelName});
|
|
876
890
|
const options = {
|
|
877
891
|
...module.exports.APIBaseOpt,
|
|
878
892
|
method: "PATCH",
|
|
@@ -895,7 +909,7 @@ module.exports = {
|
|
|
895
909
|
}
|
|
896
910
|
|
|
897
911
|
block(userID) {
|
|
898
|
-
const blockData =
|
|
912
|
+
const blockData = module.exports.jsonEncode({type: 2});
|
|
899
913
|
const options = {
|
|
900
914
|
...module.exports.APIBaseOpt,
|
|
901
915
|
method: "PUT",
|
|
@@ -944,7 +958,7 @@ module.exports = {
|
|
|
944
958
|
|
|
945
959
|
setStatus(status, activities, afk = false) {
|
|
946
960
|
return new Promise(function (resolve) {
|
|
947
|
-
this.socket.send(
|
|
961
|
+
this.socket.send(module.exports.jsonEncode({
|
|
948
962
|
op: 3,
|
|
949
963
|
d: {
|
|
950
964
|
since: Date.now(),
|
|
@@ -959,7 +973,7 @@ module.exports = {
|
|
|
959
973
|
}
|
|
960
974
|
|
|
961
975
|
createGroupChat(userIDs) {
|
|
962
|
-
const userData =
|
|
976
|
+
const userData = module.exports.jsonEncode({recipients: userIDs});
|
|
963
977
|
const options = {
|
|
964
978
|
...module.exports.APIBaseOpt,
|
|
965
979
|
method: "POST",
|
|
@@ -1049,7 +1063,7 @@ module.exports = {
|
|
|
1049
1063
|
}
|
|
1050
1064
|
|
|
1051
1065
|
editNote(userID, note) {
|
|
1052
|
-
const noteData =
|
|
1066
|
+
const noteData = module.exports.jsonEncode({note});
|
|
1053
1067
|
const options = {
|
|
1054
1068
|
...module.exports.APIBaseOpt,
|
|
1055
1069
|
method: "PUT",
|
|
@@ -1097,7 +1111,7 @@ module.exports = {
|
|
|
1097
1111
|
}
|
|
1098
1112
|
|
|
1099
1113
|
transferOwnership(channelID, userID) {
|
|
1100
|
-
const ownershipData =
|
|
1114
|
+
const ownershipData = module.exports.jsonEncode({owner: userID});
|
|
1101
1115
|
const options = {
|
|
1102
1116
|
...module.exports.APIBaseOpt,
|
|
1103
1117
|
method: "PATCH",
|