mini update

- ClientUserSettingManager (Discum)
- Document (API version, Cookie, ...)
- x-super-properties header Request (Discum)
This commit is contained in:
March 7th 2022-04-05 19:01:20 +07:00
parent f2ee8bab81
commit 26d9e4cbb9
7 changed files with 269 additions and 118 deletions

View File

@ -13,10 +13,17 @@ const client = new Client({
version: 10
},
http: {
version: 10
version: 10,
header: {
cookie: '', // If you want to use cookies, here is the place
}
}
});
/* Discord fingerprint ??? idk ... */
/**
* const { data } = await axios.get('https://discord.com/api/v9/experiments');
* client.options.http.header['x-fingerprint'] = data.fingerprint
*/
```
## Client Settings

View File

@ -4,42 +4,11 @@ const CachedManager = require('./CachedManager');
const { default: Collection } = require('@discordjs/collection');
const { Error, TypeError } = require('../errors/DJSError');
const { remove } = require('lodash');
const { localeObject, DMScanLevel, stickerAnimationMode } = require('../util/Constants')
/**
* Manages API methods for users and stores their cache.
* @extends {CachedManager}
*/
const localeObject = {
DANISH: 'da',
GERMAN: 'de',
ENGLISH_UK: 'en-GB',
ENGLISH_US: 'en-US',
SPANISH: 'es-ES',
FRENCH: 'fr',
CROATIAN: 'hr',
ITALIAN: 'it',
LITHUANIAN: 'lt',
HUNGARIAN: 'hu',
DUTCH: 'nl',
NORWEGIAN: 'no',
POLISH: 'pl',
BRAZILIAN_PORTUGUESE: 'pt-BR',
ROMANIA_ROMANIAN: 'ro',
FINNISH: 'fi',
SWEDISH: 'sv-SE',
VIETNAMESE: 'vi',
TURKISH: 'tr',
CZECH: 'cs',
GREEK: 'el',
BULGARIAN: 'bg',
RUSSIAN: 'ru',
UKRAINIAN: 'uk',
HINDI: 'hi',
THAI: 'th',
CHINA_CHINESE: 'zh-CN',
JAPANESE: 'ja',
TAIWAN_CHINESE: 'zh-TW',
KOREAN: 'ko',
};
class ClientUserSettingManager extends CachedManager {
constructor(client, iterable) {
super(client);
@ -48,19 +17,43 @@ class ClientUserSettingManager extends CachedManager {
// Language
this.locale = null;
// Setting => ACTIVITY SETTINGS => Activity Status => Display current activity as a status message
this.showCurrentGame = null;
this.activityDisplay = null;
//
this.disableDMfromServer = new Collection();
// Allow direct messages from server members
this.DMfromServerMode = null;
//
this.displayImage = null;
//
this.linkedImageDisplay = null;
// Setting => APP SETTINGS => Accessibility => Automatically play GIFs when Discord is focused.
this.autoplayGIF = null;
// Show embeds and preview website links pasted into chat
this.previewLink = null;
// Setting => APP SETTINGS => Accessibility => Play Animated Emojis
this.animatedEmojis = null;
// Setting => APP SETTINGS => Accessibility => Text-to-speech => Allow playback
this.allowTTS = null;
// Setting => APP SETTINGS => Appearance => Message Display => Compact Mode [OK]
this.compactMode = null;
// Setting => APP SETTINGS => Text & Images => Emoji => Convert Emoticons
this.convertEmoticons = null;
// Setting => APP SETTINGS => Accessibility => Text-to-speech => Allow playback
this.allowTTS = null;
// SAFE DIRECT MESSAGING
this.DMScanLevel = null;
// Setting => APP SETTINGS => Appearance => Theme [OK]
this.theme = '';
// Setting => APP SETTINGS => Accessibility => Play Animated Emojis
this.animatedEmojis = null;
//
this.developerMode = null;
//
this.afkTimeout = null;
//
this.stickerAnimationMode = null;
// WHO CAN ADD YOU AS A FRIEND ?
this.addFriendFrom = {
all: null,
mutual_friends: null,
mutual_guilds: null,
};
// Setting => APP SETTINGS => Text & Images => Emoji => Show emoji reactions
this.showEmojiReactions = null;
// Custom Stauts [It's not working now]
@ -72,33 +65,58 @@ class ClientUserSettingManager extends CachedManager {
/**
*
* @param {Object} data Raw Data to patch
* @extends https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/user/user.py
* @private
*/
_patch(data) {
this.rawSetting = data;
if ('locale' in data) {
this.locale = data.locale;
this.locale = localeObject[data.locale];
}
if ('show_current_game' in data) {
this.showCurrentGame = data.show_current_game;
this.activityDisplay = data.show_current_game;
}
if ('default_guilds_restricted' in data) {
this.DMfromServerMode = data.default_guilds_restricted;
}
if ('inline_attachment_media' in data) {
this.displayImage = data.inline_attachment_media;
}
if ('inline_embed_media' in data) {
this.linkedImageDisplay = data.inline_embed_media;
}
if ('gif_auto_play' in data) {
this.autoplayGIF = data.gif_auto_play;
}
if ('render_embeds' in data) {
this.previewLink = data.render_embeds;
}
if ('animate_emoji' in data) {
this.animatedEmojis = data.animate_emoji;
}
if ('enable_tts_command' in data) {
this.allowTTS = data.enable_tts_command;
}
if ('message_display_compact' in data) {
this.compactMode = data.message_display_compact;
}
if ('convert_emoticons' in data) {
this.convertEmoticons = data.convert_emoticons;
}
if ('enable_tts_command' in data) {
this.allowTTS = data.enable_tts_command;
if ('explicit_content_filter' in data) {
this.DMScanLevel = DMScanLevel[data.explicit_content_filter];
}
if ('theme' in data) {
this.theme = data.theme;
}
if ('animate_emoji' in data) {
this.animatedEmojis = data.animate_emoji;
if ('developer_mode' in data) {
this.developerMode = data.developer_mode;
}
if ('afk_timeout' in data) {
this.afkTimeout = data.afk_timeout * 1000; // second => milisecond
}
if ('animate_stickers' in data) {
this.stickerAnimationMode = stickerAnimationMode[data.animate_stickers];
}
if ('render_reactions' in data) {
this.showEmojiReactions = data.render_reactions;
@ -107,6 +125,15 @@ class ClientUserSettingManager extends CachedManager {
this.customStatus = data.custom_status || {}; // Thanks PinkDuwc._#3443 reported this issue
this.customStatus.status = data.status;
}
if ('friend_source_flags' in data) {
this.addFriendFrom = {
all: data.friend_source_flags.all || false,
mutual_friends:
data.friend_source_flags.all ? true : data.friend_source_flags.mutual_friends,
mutual_guilds:
data.friend_source_flags.all ? true : data.friend_source_flags.mutual_guilds,
};
}
if ('guild_folders' in data) {
const data_ = data.guild_positions.map((guildId, i) => {
// Find folder
@ -126,6 +153,14 @@ class ClientUserSettingManager extends CachedManager {
});
this.guildMetadata = new Collection(data_);
}
if ('restricted_guilds' in data) {
data.restricted_guilds.map((guildId) => {
const guild = this.client.guilds.cache.get(guildId);
if (!guild) return;
guild.disableDM = true;
this.disableDMfromServer.set(guildId, true);
});
}
}
async fetch() {
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
@ -286,7 +321,8 @@ class ClientUserSettingManager extends CachedManager {
const oldGuildFolderPosition = this.rawSetting.guild_folders.findIndex(
(value) => value.guild_ids.includes(guildId),
);
const newGuildFolderPosition = this.rawSetting.guild_folders.findIndex((value) =>
const newGuildFolderPosition = this.rawSetting.guild_folders.findIndex(
(value) =>
value.guild_ids.includes(this.rawSetting.guild_positions[newPosition]),
);
if (type == 2 || `${type}`.toUpperCase() == 'HOME') {

View File

@ -128,6 +128,8 @@ class Guild extends AnonymousGuild {
* @type {number}
*/
this.shardId = data.shardId;
this.disableDM = false;
}
/**

View File

@ -103,6 +103,51 @@ const listUserAgent = [
"Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1"
]
exports.DMScanLevel = {
0: 'NOT_SCAN',
1: 'NOT_FRIEND',
2: 'EVERYONE',
};
exports.stickerAnimationMode = {
0: 'ALWAYS',
1: 'INTERACTION',
2: 'NEVER',
};
exports.localeObject = {
da: 'DANISH',
de: 'GERMAN',
'en-GB': 'ENGLISH_UK',
'en-US': 'ENGLISH_US',
'es-ES': 'SPANISH',
fr: 'FRENCH',
hr: 'CROATIAN',
it: 'ITALIAN',
lt: 'LITHUANIAN',
hu: 'HUNGARIAN',
nl: 'DUTCH',
no: 'NORWEGIAN',
pl: 'POLISH',
'pt-BR': 'BRAZILIAN_PORTUGUESE',
ro: 'ROMANIA_ROMANIAN',
fi: 'FINNISH',
'sv-SE': 'SWEDISH',
vi: 'VIETNAMESE',
tr: 'TURKISH',
cs: 'CZECH',
el: 'GREEK',
bg: 'BULGARIAN',
ru: 'RUSSIAN',
uk: 'UKRAINIAN',
hi: 'HINDI',
th: 'THAI',
'zh-CN': 'CHINA_CHINESE',
ja: 'JAPANESE',
'zh-TW': 'TAIWAN_CHINESE',
ko: 'KOREAN',
};
exports.UserAgent = listUserAgent[Math.floor(Math.random() * listUserAgent.length)];
exports.WSCodes = {

View File

@ -167,8 +167,8 @@ class Options extends null {
//$os: 'iPhone14,5',
//$browser: 'Discord iOS',
//$device: 'iPhone14,5 OS 15.2',
$os: 'Windows 11',
$browser: 'Chrome',
$os: 'Windows',
$browser: 'Discord Client',
$device: 'ASUS ROG Phone 5',
},
version: 9,
@ -176,10 +176,9 @@ class Options extends null {
http: {
headers: {
Accept: '*/*',
// 'Accept-Encoding': 'gzip, deflate, br',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
// 'Content-Type': 'application/json',
Pragma: 'no-cache',
Referer: 'https://discord.com/channels/@me',
'Sec-Ch-Ua': '" Not A;Brand";v="99" "',
@ -189,9 +188,25 @@ class Options extends null {
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'X-Debug-Options': 'bugReporterEnabled',
// https://github.com/Merubokkusu/Discord-S.C.U.M/issues/66#issuecomment-1009171667
'x-super-properties': `${Buffer.from(
JSONBig.stringify({
os: 'Windows',
browser: 'Discord Client',
release_channel: 'stable',
client_version: '1.0.9004',
os_version: '10.0.22000',
os_arch: 'x64',
system_locale: 'en-US',
client_build_number: 122087,
client_event_source: null,
}),
'ascii',
).toString('base64')}`,
'X-Discord-Locale': 'en-US',
Origin: 'https://discord.com',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'user-agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9004 Chrome/91.0.4472.164 Electron/13.6.6 Safari/537.36',
},
agent: {},
version: 9,

45
typings/enums.d.ts vendored
View File

@ -10,6 +10,51 @@ export const enum ActivityTypes {
COMPETING = 5,
}
export const enum DMScanLevel {
NOT_SCAN = 0,
NOT_FRIEND = 1,
EVERYONE = 2,
}
export const enum stickerAnimationMode {
ALWAYS = 0,
INTERACTION = 1,
NEVER = 2,
}
export const enum localeSetting {
DANISH = 'da',
GERMAN = 'de',
ENGLISH_UK = 'en-GB',
ENGLISH_US = 'en-US',
SPANISH = 'es-ES',
FRENCH = 'fr',
CROATIAN = 'hr',
ITALIAN = 'it',
LITHUANIAN = 'lt',
HUNGARIAN = 'hu',
DUTCH = 'nl',
NORWEGIAN = 'no',
POLISH = 'pl',
BRAZILIAN_PORTUGUESE = 'pt-BR',
ROMANIA_ROMANIAN = 'ro',
FINNISH = 'fi',
SWEDISH = 'sv-SE',
VIETNAMESE = 'vi',
TURKISH = 'tr',
CZECH = 'cs',
GREEK = 'el',
BULGARIAN = 'bg',
RUSSIAN = 'ru',
UKRAINIAN = 'uk',
HINDI = 'hi',
THAI = 'th',
CHINA_CHINESE = 'zh-CN',
JAPANESE = 'ja',
TAIWAN_CHINESE = 'zh-TW',
KOREAN = 'ko',
}
export const enum ApplicationCommandTypes {
CHAT_INPUT = 1,
USER = 2,

3
typings/index.d.ts vendored
View File

@ -941,6 +941,7 @@ export class Guild extends AnonymousGuild {
public premiumProgressBarEnabled: boolean;
public premiumTier: PremiumTier;
public presences: PresenceManager;
public readonly disableDM: boolean;
public readonly publicUpdatesChannel: TextChannel | null;
public publicUpdatesChannelId: Snowflake | null;
public roles: RoleManager;
@ -3067,7 +3068,7 @@ export class ClientUserSettingManager extends CachedManager<Snowflake, null> {
public fetch(): Promise<ClientUserSetting>;
public setDisplayCompactMode(value?: boolean): Promise<ClientUserSetting>;
public setTheme(value?: 'dark' | 'light'): Promise<ClientUserSetting>;
public setLocale(value: LocaleStrings): Promise<ClientUserSetting>;
public setLocale(value: localeSetting): Promise<ClientUserSetting>;
}
export class GuildApplicationCommandManager extends ApplicationCommandManager<ApplicationCommand, {}, Guild> {