feat: update (see description)

- Remove `bignumber.js`
- Fix `circular dependency`
- Fix: missing activity.name (SpotifyRPC)
- Refactor code
- Update UserAgent
This commit is contained in:
March 7th 2022-12-05 18:30:45 +07:00
parent e0b6265aa5
commit 8b4924e147
16 changed files with 52 additions and 58 deletions

View File

@ -60,7 +60,6 @@
"@types/node-fetch": "^2.6.2",
"@types/ws": "^8.5.3",
"axios": "1.1",
"bignumber.js": "^9.1.0",
"chalk": "^4.1.2",
"discord-api-types": "^0.37.19",
"form-data": "^4.0.0",

View File

@ -1026,6 +1026,9 @@ class Client extends BaseClient {
}
break;
case 'nopecha': {
if (options.captchaKey.length !== 16) {
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 16 character string');
}
break;
}
}

View File

@ -144,8 +144,8 @@ class WebSocketManager extends EventEmitter {
});
const recommendedShards = 1;
const sessionStartLimit = {
total: 1000000000,
remaining: 1000000000,
total: Infinity,
remaining: Infinity,
};
const { total, remaining } = sessionStartLimit;

View File

@ -710,7 +710,7 @@ class WebSocketShard extends EventEmitter {
this.debug(
`[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${Intents.resolve(
client.options.intents,
)} :)`,
)} 😊`,
);
this.send({ op: Opcodes.IDENTIFY, d }, true);
}

View File

@ -1,7 +1,6 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const BigNumber = require('bignumber.js');
const CachedManager = require('./CachedManager');
const { TypeError, Error } = require('../errors');
const { Message } = require('../structures/Message');
@ -246,8 +245,8 @@ class MessageManager extends CachedManager {
await this.client.api.guilds[this.channel.guild.id].messages.search.get({
query: {
channel_id: this.channel.id,
max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
max_id: `${BigInt(messageId) + 1n}`,
min_id: `${BigInt(messageId) - 1n}`,
include_nsfw: true,
},
})
@ -258,8 +257,8 @@ class MessageManager extends CachedManager {
const data = (
await this.client.api.channels[this.channel.id].messages.search.get({
query: {
max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
max_id: `${BigInt(messageId) + 1n}`,
min_id: `${BigInt(messageId) - 1n}`,
},
})
).messages[0];

View File

@ -4,7 +4,6 @@ const Buffer = require('node:buffer').Buffer;
const https = require('node:https');
const { setTimeout } = require('node:timers');
const FormData = require('form-data');
const JSONBig = require('json-bigint');
const fetch = require('node-fetch');
const proxy = require('proxy-agent');
@ -61,9 +60,10 @@ class APIRequest {
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'X-Debug-Options': 'bugReporterEnabled',
'X-Super-Properties': `${Buffer.from(JSONBig.stringify(this.client.options.ws.properties), 'ascii').toString(
'base64',
)}`,
'X-Super-Properties': `${Buffer.from(
this.client.options.jsonTransformer(this.client.options.ws.properties),
'ascii',
).toString('base64')}`,
'X-Discord-Locale': 'en-US',
'User-Agent': this.client.options.http.headers['User-Agent'],
};

View File

@ -31,7 +31,7 @@ module.exports = class CaptchaSolver {
}
}
case 'nopecha': {
if (!key || typeof key !== 'string') throw new Error('Nopecha key is not provided');
if (!key || typeof key !== 'string') throw new Error('NopeCHA key is not provided');
try {
const { Configuration, NopeCHAApi } = require('nopecha');
const configuration = new Configuration({

View File

@ -257,10 +257,6 @@ class DMChannel extends Channel {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
data.d = {
...data.d,
self_video: false,
};
if (this.shard.status !== Status.READY) return false;
this.shard.send(data);
return true;

View File

@ -1471,9 +1471,9 @@ class Guild extends AnonymousGuild {
/**
* Add Integrations to the guild.
* @param {Snowflake} applicationId Application (ID) target
* @returns {Promise<void>}
* @returns {Promise<boolean>}
*/
async addIntegration(applicationId) {
addIntegration(applicationId) {
if (!this.me.permissions.has('MANAGE_WEBHOOKS')) {
throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS');
}
@ -1481,18 +1481,14 @@ class Guild extends AnonymousGuild {
throw new Error('MISSING_PERMISSIONS', 'MANAGE_GUILD');
}
if (!applicationId || typeof applicationId !== 'string') throw new TypeError('INVALID_APPLICATION_ID');
// Check permission
await this.client.api.oauth2.authorize.post({
query: {
client_id: applicationId,
scope: 'applications.commands',
},
data: {
return this.client.authorizeURL(
`https://discord.com/api/oauth2/authorize?client_id=${applicationId}&scope=applications.commands`,
{
guild_id: this.id,
permissions: '0',
permissions: `0`,
authorize: true,
},
});
);
}
/**
@ -1501,7 +1497,7 @@ class Guild extends AnonymousGuild {
* @param {?PermissionResolvable} permissions Permissions
* @returns {Promise<boolean>}
*/
addBot(bot, permissions) {
addBot(bot, permissions = 0n) {
if (!this.me.permissions.has('MANAGE_WEBHOOKS')) {
throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS');
}
@ -1514,8 +1510,8 @@ class Guild extends AnonymousGuild {
if (!botId) throw new TypeError('INVALID_BOT_ID');
// Check permission
const selfPerm = this.me.permissions.toArray();
const missingPerms = permission.toArray().filter(x => selfPerm.indexOf(x) === -1);
if (missingPerms[0]) {
const missingPerms = permission.toArray().filter(x => selfPerm.includes(x));
if (missingPerms.length) {
throw new Error('MISSING_PERMISSIONS', missingPerms.join(', '));
}
// Add bot

View File

@ -321,7 +321,7 @@ class Invite extends Base {
/**
* Join this Guild using this invite.
* @param {boolean} autoVerify Whether to automatically verify member
* @returns {Promise<void>}
* @returns {Promise<Guild>}
* @example
* await client.fetchInvite('code').then(async invite => {
* await invite.acceptInvite();
@ -329,6 +329,7 @@ class Invite extends Base {
*/
async acceptInvite(autoVerify = true) {
if (!this.guild) throw new Error('INVITE_NO_GUILD');
if (this.client.guilds.cache.get(this.guild.id)) return this.guild;
const dataHeader = {
location: 'Join Guild',
location_guild_id: this.guild?.id,
@ -341,18 +342,19 @@ class Invite extends Base {
'X-Context-Properties': Buffer.from(JSON.stringify(dataHeader), 'utf8').toString('base64'),
},
});
const guild = this.client.guilds.cache.get(this.guild.id);
if (autoVerify) {
const getForm = await this.client.api
.guilds(this.guild.id)
['member-verification'].get({ query: { with_guild: false, invite_code: this.code } })
.catch(() => {});
if (!getForm) return undefined;
if (!getForm) return guild;
const form = Object.assign(getForm.form_fields[0], { response: true });
// Respond to the form
// https://discord.com/api/v9/guilds/:id/requests/@me
await this.client.api.guilds(this.guild.id).requests['@me'].put({ data: { form_fields: [form] } });
}
return undefined;
return guild;
}
}

View File

@ -2,10 +2,11 @@
const { setTimeout } = require('node:timers');
const BaseMessageComponent = require('./BaseMessageComponent');
const { Message } = require('./Message');
const { MessageComponentTypes, InteractionTypes, ChannelTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const Util = require('../util/Util');
const { lazy } = require('../util/Util');
const Message = lazy(() => require('./Message').Message);
/**
* Represents a select menu message component
@ -284,7 +285,7 @@ class MessageSelectMenu extends BaseMessageComponent {
* @returns {Promise<InteractionResponse>}
*/
async select(message, values = []) {
if (!(message instanceof Message)) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
if (!(message instanceof Message())) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
if (!Array.isArray(values)) throw new TypeError('[INVALID_VALUES] Please pass an array of values');
if (!this.customId || this.disabled) return false; // Disabled or null customID
// Check value is invalid [Max options is 20] => For loop

View File

@ -407,10 +407,6 @@ class PartialGroupDMChannel extends Channel {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
data.d = {
...data.d,
self_video: false,
};
if (this.shard.status !== Status.READY) return false;
this.shard.send(data);
return true;

View File

@ -294,7 +294,7 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
* @returns {RichPresence}
*/
setType(type) {
this.type = ActivityTypes[type?.toUpperCase()];
this.type = ActivityTypes[type];
if (typeof this.type == 'string') this.type = ActivityTypes[this.type];
if (typeof this.type != 'number') throw new Error('Type must be a valid ActivityType');
return this;
@ -471,11 +471,9 @@ https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Documents/RichP
delete obj.name;
delete obj.url;
obj.type = 0;
let buttonData = [];
if (obj.buttons) {
buttonData = obj.buttons.map((b, i) => ({ label: b, url: obj.metadata.button_urls[i] }));
if (obj.buttons?.length) {
obj.buttons = obj.buttons.map((b, i) => ({ label: b, url: obj.metadata.button_urls[i] }));
delete obj.metadata;
obj.buttons = buttonData;
}
return obj;
}
@ -566,6 +564,10 @@ class SpotifyRPC extends RichPresence {
* @private
*/
setup(options) {
this.name = options.name || 'Spotify';
this.type = ActivityTypes.LISTENING;
this.party = {
id: `spotify:${this.client.user.id}`,
};
@ -638,8 +640,8 @@ class SpotifyRPC extends RichPresence {
toJSON() {
if (!this.sync_id) throw new Error('Song id is required');
const obj = {
name: 'Spotify',
type: ActivityTypes.LISTENING,
name: this.name,
type: this.type,
application_id: this.application_id,
url: this.url,
state: this.state,

View File

@ -6,11 +6,11 @@ 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/107.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13.0; rv:107.0) Gecko/20100101 Firefox/107.0',
'Mozilla/5.0 (X11; Linux i686; rv:107.0) Gecko/20100101 Firefox/107.0',
@ -26,8 +26,8 @@ const listUserAgent = [
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0',
'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/107.0.1418.68',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/107.0.1418.68',
];
/**

View File

@ -188,7 +188,7 @@ class Options extends null {
browser: 'Chrome',
device: '',
system_locale: 'en-US',
browser_version: '107.0.0.0',
browser_version: '108.0.0.0',
os_version: '10',
referrer: '',
referring_domain: '',

4
typings/index.d.ts vendored
View File

@ -1412,7 +1412,7 @@ export class GuildAuditLogsEntry<
: Role | GuildEmoji | { id: Snowflake } | null;
public targetType: TTargetType;
public toJSON(): unknown;
public addIntegration(applicationId: Snowflake): Promise<void>;
public addIntegration(applicationId: Snowflake): Promise<boolean>;
public addBot(bot: UserResolvable | Snowflake, permissions?: PermissionResolvable): Promise<boolean>;
}
@ -1813,7 +1813,7 @@ export class Invite extends Base {
public delete(reason?: string): Promise<Invite>;
public toJSON(): unknown;
public toString(): string;
public acceptInvite(autoVerify?: boolean): Promise<void>;
public acceptInvite(autoVerify?: boolean): Promise<Guild>;
public static INVITES_PATTERN: RegExp;
public stageInstance: InviteStageInstance | null;
public guildScheduledEvent: GuildScheduledEvent | null;