i hate discord 😭
This commit is contained in:
Elysia
2023-02-09 19:26:39 +07:00
parent 9bab1f1983
commit 756a241051
11 changed files with 41 additions and 92 deletions

View File

@@ -5,14 +5,8 @@ const Package = (exports.Package = require('../../package.json'));
*/
const { Error, RangeError, TypeError } = require('../errors');
// #88: https://jnrbsn.github.io/user-agents/user-agents.json
const listUserAgent = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.69',
];
exports.defaultUA =
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9010 Chrome/91.0.4472.164 Electron/13.6.6 Safari/537.36';
/**
* Max bulk deletable message age
@@ -135,8 +129,6 @@ exports.localeSetting = {
ko: 'KOREAN',
};
exports.randomUA = () => listUserAgent[Math.floor(Math.random() * listUserAgent.length)];
/**
* The types of WebSocket error codes:
* * 1000: WS_CLOSE_REQUESTED

View File

@@ -4,7 +4,7 @@ const { Buffer } = require('node:buffer');
const fs = require('node:fs');
const path = require('node:path');
const stream = require('node:stream');
const fetch = require('node-fetch');
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
const { Error: DiscordError, TypeError } = require('../errors');
const Invite = require('../structures/Invite');

View File

@@ -2,7 +2,7 @@
const JSONBig = require('json-bigint');
const Intents = require('./Intents');
const { randomUA } = require('../util/Constants');
const { defaultUA } = require('../util/Constants');
/**
* Rate limit data
* @typedef {Object} RateLimitData
@@ -191,20 +191,16 @@ class Options extends null {
proxy: '',
ws: {
compress: false,
// https://discord-user-api.cf/api/v1/properties/web
properties: {
os: 'Windows',
browser: 'Chrome',
device: '',
system_locale: 'en-US',
browser_version: '109.0.0.0',
os_version: '10',
referrer: '',
referring_domain: '',
referrer_current: '',
referring_domain_current: '',
browser: 'Discord Client',
release_channel: 'stable',
client_build_number: 169617,
client_version: '1.0.9010',
os_version: '10.0.22621',
os_arch: 'x64',
system_locale: 'en-US',
client_build_number: 172394,
native_build_number: 29128,
client_event_source: null,
},
// ! capabilities: 4093,
@@ -222,7 +218,7 @@ class Options extends null {
http: {
agent: {},
headers: {
'User-Agent': randomUA(),
'User-Agent': defaultUA,
},
version: 9,
api: 'https://discord.com/api',

View File

@@ -8,7 +8,7 @@ const axios = require('axios');
const chalk = require('chalk');
const { encode: urlsafe_b64encode } = require('safe-base64');
const WebSocket = require('ws');
const { randomUA } = require('./Constants');
const { defaultUA } = require('./Constants');
const Options = require('./Options');
const defaultClientOptions = Options.createDefault();
@@ -153,7 +153,7 @@ new DiscordAuthWebsocket({
failIfError: true,
generateQR: true,
apiVersion: 9,
userAgent: randomUA(),
userAgent: defaultUA,
wsProperties: defaultClientOptions.ws.properties,
};
if (typeof options == 'object') {

View File

@@ -4,10 +4,8 @@ const { parse } = require('node:path');
const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const axios = require('axios');
const fetch = require('node-fetch');
const { Colors, Endpoints } = require('./Constants');
const Options = require('./Options');
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
const { Colors } = require('./Constants');
const { RangeError, TypeError } = require('../errors');
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
const isObject = d => typeof d === 'object' && d !== null;
@@ -332,33 +330,6 @@ class Util extends null {
return text.replaceAll(/\[.+\]\(.+\)/gm, '\\$&');
}
/**
* @typedef {Object} FetchRecommendedShardsOptions
* @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
* @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
*/
/**
* Gets the recommended shard count from Discord.
* @param {string} token Discord auth token
* @param {FetchRecommendedShardsOptions} [options] Options for fetching the recommended shard count
* @returns {Promise<number>} The recommended number of shards
*/
static async fetchRecommendedShards(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
if (!token) throw new DiscordError('TOKEN_MISSING');
const defaults = Options.createDefault();
const response = await fetch(`${defaults.http.api}/v${defaults.http.version}${Endpoints.botGateway}`, {
method: 'GET',
headers: { Authorization: `Bot ${token.replace(/^Bot\s*/i, '')}` },
});
if (!response.ok) {
if (response.status === 401) throw new DiscordError('TOKEN_INVALID');
throw response;
}
const { shards } = await response.json();
return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
}
/**
* Parses emoji info out of a string. The string must be one of:
* * A UTF-8 emoji (no id)