@imaentity/selfjs 3.0.0 β†’ 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.
Files changed (4) hide show
  1. package/changelog.log +10 -1
  2. package/docs.md +18 -0
  3. package/package.json +1 -1
  4. package/self.js +86 -29
package/changelog.log CHANGED
@@ -17,4 +17,13 @@ V2.10.11
17
17
 
18
18
  V3.0.0
19
19
  Changed:
20
- Major overhaul to the structure of self.js
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
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imaentity/selfjs",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Breaking Discord's TOS to bot user accounts.",
5
5
  "main": "self.js",
6
6
  "repository": {
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.0.0
5
+ * @version 3.1.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
- let options = null;
50
- let msgData = null;
49
+ const boundary = "X-SELFJS-BOUNDARY";
51
50
 
52
- if(inputData) {
53
- msgData = module.exports.jsonEncode(inputData);
54
- options = {
55
- ...module.exports.APIBaseOpt,
56
- method: "POST",
57
- path: `/api/webhooks/${webhookID}/${webhookToken}`,
58
- headers: {
59
- "Content-Type": "application/json",
60
- "Content-Length": msgData.length
61
- }
62
- };
63
- } else {
64
- msgData = module.exports.jsonEncode(webhookToken);
65
- options = {
66
- ...module.exports.APIBaseOpt,
67
- method: "POST",
68
- path: webhookID.split("//")[1].split('/').slice(1).join('/'),
69
- headers: {
70
- "Content-Type": "application/json",
71
- "Content-Length": msgData.length
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
- res.on("end", resolve);
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 getUserData(userID) {
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.user.avatar;
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}.webp?size=${size}`
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",