@imaentity/selfjs 3.0.0 β 3.2.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/changelog.log +14 -1
- package/docs.md +27 -0
- package/package.json +1 -1
- package/self.js +96 -29
package/changelog.log
CHANGED
|
@@ -17,4 +17,17 @@ V2.10.11
|
|
|
17
17
|
|
|
18
18
|
V3.0.0
|
|
19
19
|
Changed:
|
|
20
|
-
|
|
20
|
+
Overhaul to the structure of self.js
|
|
21
|
+
|
|
22
|
+
V3.1.0
|
|
23
|
+
Added:
|
|
24
|
+
Webhooks can now send files
|
|
25
|
+
Client.getUserProfile to fetch user profiles
|
|
26
|
+
Client.createServer to create a server
|
|
27
|
+
|
|
28
|
+
Changed:
|
|
29
|
+
Client.getUser now gets the actual user instead of their profile
|
|
30
|
+
|
|
31
|
+
V3.2.0
|
|
32
|
+
Added:
|
|
33
|
+
Client.refreshURL to refresh expired urls
|
package/docs.md
CHANGED
|
@@ -172,6 +172,15 @@ Welcome To SelfJS Documentation
|
|
|
172
172
|
});
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
+
+ ### π€ getUserProfile
|
|
176
|
+
Gets the profile of a user.
|
|
177
|
+
>Paramaters: userID (String)
|
|
178
|
+
|
|
179
|
+
<br>Example:
|
|
180
|
+
```javascript
|
|
181
|
+
client.getUserProfile("01234567891011121314");
|
|
182
|
+
```
|
|
183
|
+
|
|
175
184
|
+ ### π€ getUserData
|
|
176
185
|
Gets the data of a user.
|
|
177
186
|
>Paramaters: userID (String)
|
|
@@ -319,6 +328,15 @@ Welcome To SelfJS Documentation
|
|
|
319
328
|
client.addFriend("01234567891011121314");
|
|
320
329
|
```
|
|
321
330
|
|
|
331
|
+
+ ### β createServer
|
|
332
|
+
Creates a server with the given options.
|
|
333
|
+
>Paramaters: options ({name: String, icon: String | null})
|
|
334
|
+
|
|
335
|
+
<br>Example:
|
|
336
|
+
```javascript
|
|
337
|
+
client.createServer({name: "My Server", icon: "data:image/png;base64,aGloaSA6Mw=="});
|
|
338
|
+
```
|
|
339
|
+
|
|
322
340
|
+ ### π editMessage
|
|
323
341
|
Edits a message.
|
|
324
342
|
>Paramaters: channelID (String), messageID (String), message (String)
|
|
@@ -450,4 +468,13 @@ Welcome To SelfJS Documentation
|
|
|
450
468
|
<br>Example:
|
|
451
469
|
```javascript
|
|
452
470
|
client.transferOwnership("01234567891011121314", "41312111019876543210");
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
+ ### π refreshURL
|
|
474
|
+
Refreshes an expired attachment url.
|
|
475
|
+
>Paramaters: url (String)
|
|
476
|
+
|
|
477
|
+
<br>Example:
|
|
478
|
+
```javascript
|
|
479
|
+
client.refreshURL();
|
|
453
480
|
```
|
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 3.
|
|
5
|
+
* @version 3.2.0
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const https = require("https");
|
|
@@ -46,36 +46,67 @@ module.exports = {
|
|
|
46
46
|
},
|
|
47
47
|
|
|
48
48
|
sendWebhookMessage: function(webhookID, webhookToken, inputData) {
|
|
49
|
-
|
|
50
|
-
let msgData = null;
|
|
49
|
+
const boundary = "X-SELFJS-BOUNDARY";
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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}--`)]);
|
|
74
83
|
}
|
|
75
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
|
+
|
|
76
95
|
return new Promise(function(resolve) {
|
|
77
96
|
const req = https.request(options, function(res) {
|
|
78
|
-
|
|
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
|
+
});
|
|
79
110
|
});
|
|
80
111
|
|
|
81
112
|
req.write(msgData);
|
|
@@ -451,13 +482,20 @@ module.exports = {
|
|
|
451
482
|
});
|
|
452
483
|
}
|
|
453
484
|
|
|
454
|
-
async
|
|
485
|
+
async getUserProfile(userID) {
|
|
455
486
|
return await this.makeRequest({
|
|
456
487
|
method: "GET",
|
|
457
488
|
path: `/api/v10/users/${userID}/profile?with_mutual_guilds=false`
|
|
458
489
|
});
|
|
459
490
|
}
|
|
460
491
|
|
|
492
|
+
async getUserData(userID) {
|
|
493
|
+
return await this.makeRequest({
|
|
494
|
+
method: "GET",
|
|
495
|
+
path: `/api/v10/users/${userID}`
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
461
499
|
async setRolesForMemeber(serverID, userID, roleIDs) {
|
|
462
500
|
return await this.makeRequest({
|
|
463
501
|
method: "PATCH",
|
|
@@ -576,14 +614,14 @@ module.exports = {
|
|
|
576
614
|
|
|
577
615
|
try {
|
|
578
616
|
avatarID = await this.getUserData(userID);
|
|
579
|
-
avatarID = avatarID.
|
|
617
|
+
avatarID = avatarID.avatar;
|
|
580
618
|
} catch(e) {
|
|
581
619
|
return null;
|
|
582
620
|
}
|
|
583
621
|
|
|
584
622
|
return await this.makeRequest({
|
|
585
623
|
method: "GET",
|
|
586
|
-
path: `/avatars/${userID}/${avatarID}.
|
|
624
|
+
path: `/avatars/${userID}/${avatarID}.png?size=${size}`
|
|
587
625
|
}, module.exports.CDNBaseOpt);
|
|
588
626
|
}
|
|
589
627
|
|
|
@@ -595,6 +633,25 @@ module.exports = {
|
|
|
595
633
|
});
|
|
596
634
|
}
|
|
597
635
|
|
|
636
|
+
async createServer(options) {
|
|
637
|
+
options = options || {};
|
|
638
|
+
|
|
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
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
598
655
|
async editMessage(channelID, messageID, newMessage) {
|
|
599
656
|
return await this.makeRequest({
|
|
600
657
|
method: "PATCH",
|
|
@@ -720,5 +777,15 @@ module.exports = {
|
|
|
720
777
|
}
|
|
721
778
|
});
|
|
722
779
|
}
|
|
780
|
+
|
|
781
|
+
async refreshURL(url) {
|
|
782
|
+
return await this.makeRequest({
|
|
783
|
+
method: "POST",
|
|
784
|
+
path: "/api/v10/attachments/refresh-urls",
|
|
785
|
+
body: {
|
|
786
|
+
attachment_urls: [url]
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
723
790
|
}
|
|
724
791
|
};
|