@imaentity/selfjs 4.1.0 → 4.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/docs.md +129 -22
- package/package.json +5 -3
- package/self.js +75 -9
package/docs.md
CHANGED
|
@@ -57,10 +57,8 @@ Promise<Object | null>
|
|
|
57
57
|
```javascript
|
|
58
58
|
const user = await self.validateToken(token);
|
|
59
59
|
|
|
60
|
-
if(user)
|
|
61
|
-
|
|
62
|
-
else
|
|
63
|
-
console.log("Invalid token");
|
|
60
|
+
if(user) console.log(`Logged in as ${user.username}`);
|
|
61
|
+
else console.log("Invalid token");
|
|
64
62
|
```
|
|
65
63
|
|
|
66
64
|
## `createToken(options)`
|
|
@@ -112,12 +110,9 @@ const login = await self.createToken({
|
|
|
112
110
|
password: "password"
|
|
113
111
|
});
|
|
114
112
|
|
|
115
|
-
if(!login)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if(!login.mfaRequired) {
|
|
119
|
-
console.log(login.token);
|
|
120
|
-
} else {
|
|
113
|
+
if(!login) throw new Error("Login failed");
|
|
114
|
+
if(!login.mfaRequired) console.log(login.token);
|
|
115
|
+
else {
|
|
121
116
|
console.log("MFA methods:", login.mfaMethods);
|
|
122
117
|
|
|
123
118
|
const result = await login.confirmMFA("totp", {
|
|
@@ -152,7 +147,6 @@ Number
|
|
|
152
147
|
|
|
153
148
|
```javascript
|
|
154
149
|
const timestamp = self.snowflakeToUTC("1329029486758592595");
|
|
155
|
-
|
|
156
150
|
console.log(new Date(timestamp));
|
|
157
151
|
```
|
|
158
152
|
|
|
@@ -177,7 +171,6 @@ String
|
|
|
177
171
|
|
|
178
172
|
```javascript
|
|
179
173
|
const snowflake = self.UTCToSnowflake(Date.now());
|
|
180
|
-
|
|
181
174
|
console.log(snowflake);
|
|
182
175
|
```
|
|
183
176
|
|
|
@@ -202,7 +195,6 @@ const client = new self.Client({
|
|
|
202
195
|
},
|
|
203
196
|
|
|
204
197
|
debugLogs: true,
|
|
205
|
-
|
|
206
198
|
intents: 0
|
|
207
199
|
});
|
|
208
200
|
```
|
|
@@ -441,7 +433,7 @@ Gets recent messages from a channel.
|
|
|
441
433
|
### Returns
|
|
442
434
|
|
|
443
435
|
```javascript
|
|
444
|
-
Promise<Array
|
|
436
|
+
Promise<Array<Object>>
|
|
445
437
|
```
|
|
446
438
|
|
|
447
439
|
Messages are returned from newest to oldest.
|
|
@@ -537,7 +529,7 @@ This can contain both direct messages and group DMs.
|
|
|
537
529
|
### Returns
|
|
538
530
|
|
|
539
531
|
```javascript
|
|
540
|
-
Promise<Object
|
|
532
|
+
Promise<Array<Object>>
|
|
541
533
|
```
|
|
542
534
|
|
|
543
535
|
### Example
|
|
@@ -858,7 +850,6 @@ The current channel object.
|
|
|
858
850
|
|
|
859
851
|
```javascript
|
|
860
852
|
const channel = await client.getChannelObject("123456789");
|
|
861
|
-
|
|
862
853
|
console.log(channel);
|
|
863
854
|
```
|
|
864
855
|
|
|
@@ -885,7 +876,6 @@ The DM channel object.
|
|
|
885
876
|
|
|
886
877
|
```javascript
|
|
887
878
|
const channel = await client.getDMChannel("123456789");
|
|
888
|
-
|
|
889
879
|
console.log(channel);
|
|
890
880
|
```
|
|
891
881
|
|
|
@@ -911,7 +901,6 @@ The DM channel object.
|
|
|
911
901
|
|
|
912
902
|
```javascript
|
|
913
903
|
const channel = await client.getDMChannel("123456789");
|
|
914
|
-
|
|
915
904
|
console.log(channel);
|
|
916
905
|
```
|
|
917
906
|
|
|
@@ -977,6 +966,128 @@ const profile = await client.getUserProfile({
|
|
|
977
966
|
});
|
|
978
967
|
```
|
|
979
968
|
|
|
969
|
+
# User Settings
|
|
970
|
+
|
|
971
|
+
## `client.getUserSettings()`
|
|
972
|
+
|
|
973
|
+
Gets the `PreloadedUserSettings` protobuf containing general account settings.
|
|
974
|
+
The protobuf is decoded into a JavaScript object.
|
|
975
|
+
|
|
976
|
+
### Returns
|
|
977
|
+
|
|
978
|
+
```javascript
|
|
979
|
+
Promise<Object>
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
### Example
|
|
983
|
+
|
|
984
|
+
```javascript
|
|
985
|
+
const settings = await client.getUserSettings();
|
|
986
|
+
console.log(settings);
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
## `client.getFrecencySettings()`
|
|
990
|
+
|
|
991
|
+
Gets the `FrecencyUserSettings` protobuf.
|
|
992
|
+
This contains frecency and favorite data for GIFs, emojis, stickers, and similar items.
|
|
993
|
+
The protobuf is decoded into a JavaScript object.
|
|
994
|
+
|
|
995
|
+
### Returns
|
|
996
|
+
|
|
997
|
+
```javascript
|
|
998
|
+
Promise<Object>
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
### Example
|
|
1002
|
+
|
|
1003
|
+
```javascript
|
|
1004
|
+
const settings = await client.getFrecencySettings();
|
|
1005
|
+
console.log(settings);
|
|
1006
|
+
```
|
|
1007
|
+
|
|
1008
|
+
---
|
|
1009
|
+
|
|
1010
|
+
## `client.updateUserSettings(buf)`
|
|
1011
|
+
|
|
1012
|
+
Updates the `PreloadedUserSettings` protobuf.
|
|
1013
|
+
The provided object is encoded into a protobuf and sent to Discord.
|
|
1014
|
+
|
|
1015
|
+
### Parameters
|
|
1016
|
+
|
|
1017
|
+
| Name | Type | Description |
|
|
1018
|
+
| ----- | -------- | ------------------ |
|
|
1019
|
+
| `buf` | `Object` | New settings data. |
|
|
1020
|
+
|
|
1021
|
+
### Returns
|
|
1022
|
+
|
|
1023
|
+
```javascript
|
|
1024
|
+
Promise<Object>
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
The updated settings.
|
|
1028
|
+
|
|
1029
|
+
### Example
|
|
1030
|
+
|
|
1031
|
+
```javascript
|
|
1032
|
+
const settings = await client.updateUserSettings({
|
|
1033
|
+
// settings data
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
console.log(settings);
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
## `client.updateFrecencySettings(buf)`
|
|
1040
|
+
|
|
1041
|
+
Updates the `FrecencyUserSettings` protobuf.
|
|
1042
|
+
The provided object is encoded into a protobuf and sent to Discord.
|
|
1043
|
+
This controls frecency and favorite data for GIFs, emojis, stickers, and similar items.
|
|
1044
|
+
|
|
1045
|
+
### Parameters
|
|
1046
|
+
|
|
1047
|
+
| Name | Type | Description |
|
|
1048
|
+
| ----- | -------- | --------------------------- |
|
|
1049
|
+
| `buf` | `Object` | New frecency settings data. |
|
|
1050
|
+
|
|
1051
|
+
### Returns
|
|
1052
|
+
|
|
1053
|
+
```javascript
|
|
1054
|
+
Promise<Object>
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
The updated settings.
|
|
1058
|
+
|
|
1059
|
+
### Example
|
|
1060
|
+
|
|
1061
|
+
```javascript
|
|
1062
|
+
const settings = await client.updateFrecencySettings({
|
|
1063
|
+
// frecency settings data
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
console.log(settings);
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
# Servers
|
|
1070
|
+
|
|
1071
|
+
## `client.getServerList()`
|
|
1072
|
+
|
|
1073
|
+
Gets the full list of servers the account is currently in.
|
|
1074
|
+
|
|
1075
|
+
### Returns
|
|
1076
|
+
|
|
1077
|
+
```javascript
|
|
1078
|
+
Promise<Array<Object>>
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
An array containing the server objects.
|
|
1082
|
+
|
|
1083
|
+
### Example
|
|
1084
|
+
|
|
1085
|
+
```javascript
|
|
1086
|
+
const servers = await client.getServerList();
|
|
1087
|
+
|
|
1088
|
+
console.log(servers);
|
|
1089
|
+
```
|
|
1090
|
+
|
|
980
1091
|
# Status
|
|
981
1092
|
|
|
982
1093
|
## `client.setStatus(options)`
|
|
@@ -1004,7 +1115,6 @@ Activity objects contain:
|
|
|
1004
1115
|
```javascript
|
|
1005
1116
|
client.setStatus({
|
|
1006
1117
|
status: "dnd",
|
|
1007
|
-
|
|
1008
1118
|
activities: [{
|
|
1009
1119
|
name: "with the Discord API",
|
|
1010
1120
|
type: Status.PLAYING
|
|
@@ -1017,7 +1127,6 @@ client.setStatus({
|
|
|
1017
1127
|
```javascript
|
|
1018
1128
|
client.setStatus({
|
|
1019
1129
|
status: "online",
|
|
1020
|
-
|
|
1021
1130
|
activities: [{
|
|
1022
1131
|
name: "my custom status",
|
|
1023
1132
|
type: Status.CUSTOM_STATUS
|
|
@@ -1032,7 +1141,6 @@ Streaming activities automatically receive the activity's name as `details`.
|
|
|
1032
1141
|
```javascript
|
|
1033
1142
|
client.setStatus({
|
|
1034
1143
|
status: "online",
|
|
1035
|
-
|
|
1036
1144
|
activities: [{
|
|
1037
1145
|
name: "Minecraft",
|
|
1038
1146
|
type: Status.STREAMING
|
|
@@ -1088,7 +1196,6 @@ client.disconnect(1000);
|
|
|
1088
1196
|
|
|
1089
1197
|
```javascript
|
|
1090
1198
|
const self = require("@imaentity/selfjs");
|
|
1091
|
-
|
|
1092
1199
|
const client = new self.Client({
|
|
1093
1200
|
debugLogs: true
|
|
1094
1201
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imaentity/selfjs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Breaking Discord's TOS to bot user accounts.",
|
|
5
5
|
"main": "self.js",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"keywords": [
|
|
11
11
|
"bot",
|
|
12
12
|
"discord",
|
|
13
|
-
"library"
|
|
13
|
+
"library",
|
|
14
|
+
"selfbot"
|
|
14
15
|
],
|
|
15
16
|
"author": "ImaEntity",
|
|
16
17
|
"license": "ISC",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"homepage": "https://github.com/ImaEntity/SelfJS#readme",
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"ws": "^7.5.4"
|
|
23
|
+
"ws": "^7.5.4",
|
|
24
|
+
"discord-protos": "^1.2.305"
|
|
23
25
|
}
|
|
24
26
|
}
|
package/self.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
* @name SelfJS
|
|
3
3
|
* @description Breaking Discord's TOS to bot user accounts.
|
|
4
4
|
* @author Entity
|
|
5
|
-
* @version 4.
|
|
5
|
+
* @version 4.2
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
const proto = require("discord-protos");
|
|
8
9
|
const EventEmitter = require("events");
|
|
9
10
|
const https = require("https");
|
|
10
11
|
const ws = require("ws");
|
|
11
12
|
|
|
12
13
|
const DISCORD_EPOCH = 1420070400000n;
|
|
13
|
-
const SELF_VERSION = "v4.
|
|
14
|
+
const SELF_VERSION = "v4.2";
|
|
14
15
|
const WS_ENDPOINT = "wss://gateway.discord.gg?v=10&encoding=json";
|
|
15
16
|
const LOGIN_PROPS = {
|
|
16
17
|
os: process.platform,
|
|
17
|
-
browser:
|
|
18
|
+
browser: `SelfJS ${SELF_VERSION}`,
|
|
18
19
|
device: "NodeJS"
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -190,25 +191,35 @@ async function validateToken(token) {
|
|
|
190
191
|
* @param {Object} options Options for getting a token
|
|
191
192
|
* @param {String} options.email The email to use for finding a token
|
|
192
193
|
* @param {String} options.password The password to use for getting a token
|
|
193
|
-
* @returns {Promise<Object
|
|
194
|
+
* @returns {Promise<Object>} An object containing a token, mfa methods and a callback, or an error message
|
|
194
195
|
*/
|
|
195
196
|
async function createToken(options) {
|
|
196
197
|
const {email, password} = options;
|
|
197
|
-
if(!email || !password) return
|
|
198
|
+
if(!email || !password) return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: "Missing email or password"
|
|
201
|
+
};
|
|
198
202
|
|
|
199
203
|
const loginData = await POST({
|
|
200
204
|
path: "/auth/login",
|
|
201
205
|
body: {login: email, password}
|
|
202
206
|
});
|
|
203
207
|
|
|
204
|
-
if(
|
|
208
|
+
if(loginData.captcha_service) return {
|
|
209
|
+
success: false,
|
|
210
|
+
error: "Captcha required, but not yet supported",
|
|
211
|
+
...loginData
|
|
212
|
+
};
|
|
213
|
+
|
|
205
214
|
if(!loginData.mfa) return {
|
|
215
|
+
success: true,
|
|
206
216
|
token: loginData.token,
|
|
207
217
|
user_id: loginData.user_id,
|
|
208
218
|
mfaRequired: false
|
|
209
219
|
};
|
|
210
220
|
|
|
211
221
|
return {
|
|
222
|
+
success: true,
|
|
212
223
|
user_id: loginData.user_id,
|
|
213
224
|
mfaRequired: true,
|
|
214
225
|
mfaMethods: Object.entries(loginData)
|
|
@@ -574,12 +585,20 @@ class Client extends EventEmitter {
|
|
|
574
585
|
|
|
575
586
|
/**
|
|
576
587
|
* Gets the channels active in the DM list of the user, channels can be both DMs and group chats
|
|
577
|
-
* @returns {Promise<Object
|
|
588
|
+
* @returns {Promise<Array<Object>>} The list of channels open in the user's DM list
|
|
578
589
|
*/
|
|
579
590
|
getOpenChannels() {
|
|
580
591
|
return this.#GET({path: "/users/@me/channels"});
|
|
581
592
|
}
|
|
582
593
|
|
|
594
|
+
/**
|
|
595
|
+
* Gets the full list of servers the user is in
|
|
596
|
+
* @returns {Promise<Array<Object>>} The list of servers
|
|
597
|
+
*/
|
|
598
|
+
getServerList() {
|
|
599
|
+
return this.#GET({ path: "/users/@me/guilds" });
|
|
600
|
+
}
|
|
601
|
+
|
|
583
602
|
/**
|
|
584
603
|
* Closes the current session and disconnects from discord
|
|
585
604
|
* Once this is done a client will no longer see events
|
|
@@ -609,7 +628,8 @@ class Client extends EventEmitter {
|
|
|
609
628
|
* }>} options.activities Used to provide a list of activities
|
|
610
629
|
*
|
|
611
630
|
* @returns {void}
|
|
612
|
-
|
|
631
|
+
*/
|
|
632
|
+
// TODO: Send protobuf chunk to endpoint 1
|
|
613
633
|
setStatus(options) {
|
|
614
634
|
for(const activity of options.activities) {
|
|
615
635
|
if(activity.type == Status.CUSTOM_STATUS) {
|
|
@@ -714,7 +734,7 @@ class Client extends EventEmitter {
|
|
|
714
734
|
* @param {String} options.channel_id The channel id to get messages from
|
|
715
735
|
* @param {Number} [options.limit] The max amount of messages to return
|
|
716
736
|
* @param {String} [options.before] Only return messages before this message id
|
|
717
|
-
* @returns {Promise<Array
|
|
737
|
+
* @returns {Promise<Object<Array>>} The list of messages in order from newest to oldest
|
|
718
738
|
*/
|
|
719
739
|
getMessages(options) {
|
|
720
740
|
return this.#GET({
|
|
@@ -868,6 +888,52 @@ class Client extends EventEmitter {
|
|
|
868
888
|
}
|
|
869
889
|
});
|
|
870
890
|
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Gets the "PreloadedUserSettings" protobuf, containing general user settings
|
|
894
|
+
* @returns {Promise<Object>} The protobuf content converted to JSON
|
|
895
|
+
*/
|
|
896
|
+
async getUserSettings() {
|
|
897
|
+
const buf = await this.#GET({path: "/users/@me/settings-proto/1"});
|
|
898
|
+
if(buf?.settings) return proto.PreloadedUserSettings.fromBase64(buf.settings);
|
|
899
|
+
return buf;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Gets the "FrecencyUserSettings" protobuf converted to JSON
|
|
904
|
+
* Containing frecency and favorite data for gifs, emojis, stickers, and other similar things
|
|
905
|
+
* @returns {Promise<Object>} The protobuf content converted to JSON
|
|
906
|
+
*/
|
|
907
|
+
async getFrecencySettings() {
|
|
908
|
+
const buf = await this.#GET({path: "/users/@me/settings-proto/2"});
|
|
909
|
+
if(buf?.settings) return proto.FrecencyUserSettings.fromBase64(buf.settings);
|
|
910
|
+
return buf;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Updates the "PreloadedUserSettings" protobuf, containing general user settings
|
|
915
|
+
* @param {Object} buf The new data to set the protobuf to
|
|
916
|
+
* @returns {Promise<Object>} The updated protobuf stored on the server
|
|
917
|
+
*/
|
|
918
|
+
async updateUserSettings(buf) {
|
|
919
|
+
const b64 = proto.PreloadedUserSettings.toBase64(buf);
|
|
920
|
+
const res = await this.#PATCH({path: "/users/@me/settings-proto/1", body: {settings: b64}});
|
|
921
|
+
if(res?.settings) return proto.PreloadedUserSettings.fromBase64(res.settings);
|
|
922
|
+
return res;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Updates the "FrecencyUserSettings" protobuf
|
|
927
|
+
* Contains frecency and favorite data for gifs, emojis, stickers, and other similar things
|
|
928
|
+
* @param {Object} buf The new data to set the protobuf to
|
|
929
|
+
* @returns {Promise<Object>} The updated protobuf stored on the server
|
|
930
|
+
*/
|
|
931
|
+
async updateFrecencySettings(buf) {
|
|
932
|
+
const b64 = proto.FrecencyUserSettings.toBase64(buf);
|
|
933
|
+
const res = await this.#PATCH({path: "/users/@me/settings-proto/2", body: {settings: b64}});
|
|
934
|
+
if(res?.settings) return proto.FrecencyUserSettings.fromBase64(res.settings);
|
|
935
|
+
return res;
|
|
936
|
+
}
|
|
871
937
|
}
|
|
872
938
|
|
|
873
939
|
module.exports = {
|