fix: error

- Documents
- Enums
- Checkupdate function
- Update UserAgent
This commit is contained in:
March 7th 2022-06-11 20:13:52 +07:00
parent 64d7900302
commit c9f1010e54
8 changed files with 94 additions and 66 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,12 @@ const { Events, Opcodes } = require('../../../util/Constants');
const { Networking } = require('../../../util/Voice');
async function checkUpdate(client) {
const res_ = await axios.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`);
const res_ = await axios
.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`)
.catch(() => {});
if (!res_) {
return client.emit(Events.DEBUG, `${chalk.redBright('[Fail]')} Check Update error`);
}
const lastest_tag = res_.data['dist-tags'].latest;
// Checking if the package is outdated
// Stable version
@ -29,11 +34,7 @@ Old Version: ${chalk.redBright(Discord.version)} => New Version: ${chalk.greenBr
module.exports = (client, { d: data }, shard) => {
if (client.options.checkUpdate) {
try {
checkUpdate(client);
} catch (e) {
client.emit(Events.DEBUG, `${chalk.redBright('[Fail]')} Check Update error: ${e.message}`);
}
checkUpdate(client);
}
if (client.options.patchVoice) {

View File

@ -1,6 +1,6 @@
'use strict';
const { Events, Relationship } = require('../../../util/Constants');
const { Events, RelationshipTypes } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
if (data.user) {
@ -11,7 +11,7 @@ module.exports = (client, { d: data }) => {
* Emitted whenever a relationship is updated.
* @event Client#relationshipAdd
* @param {UserId} user The userID that was updated
* @param {RelationshipType} type The new relationship type
* @param {RelationshipTypes} type The new relationship type
*/
client.emit(Events.RELATIONSHIP_ADD, data.id, Relationship[data.type]);
client.emit(Events.RELATIONSHIP_ADD, data.id, RelationshipTypes[data.type]);
};

View File

@ -12,7 +12,16 @@ const { RelationshipTypes } = require('../util/Constants');
*/
class RelationshipsManager {
constructor(client, users) {
/**
* The client that instantiated this manager.
* @type {Client}
*/
this.client = client;
/**
* A collection of users this manager is caching.
* @type {Collection<Snowflake, RelationshipTypes>}
* @readonly
*/
this.cache = new Collection();
this._setup(users);
}
@ -62,6 +71,11 @@ class RelationshipsManager {
// Some option .-.
/**
* Deletes a friend relationship with a client user.
* @param {User} user Target
* @returns {Promise<boolean>}
*/
async deleteFriend(user) {
const id = this.resolveId(user);
// Check if already friends
@ -70,6 +84,11 @@ class RelationshipsManager {
return true;
}
/**
* Deletes a blocked relationship with a client user.
* @param {User} user Target
* @returns {Promise<boolean>}
*/
async deleteBlocked(user) {
const id = this.resolveId(user);
// Check if already blocked
@ -78,6 +97,12 @@ class RelationshipsManager {
return true;
}
/**
* Sends a friend request.
* @param {string} username Username of the user to send the request to
* @param {number} discriminator Discriminator of the user to send the request to
* @returns {Promise<boolean>}
*/
async sendFriendRequest(username, discriminator) {
await this.client.api.users('@me').relationships.post({
data: {
@ -88,6 +113,11 @@ class RelationshipsManager {
return true;
}
/**
* Accepts a friend request.
* @param {UserResolvable} user The user to add as a friend
* @returns {Promise<boolean>}
*/
async addFriend(user) {
const id = this.resolveId(user);
// Check if already friends
@ -102,6 +132,11 @@ class RelationshipsManager {
return true;
}
/**
* Blocks a user.
* @param {UserResolvable} user User to block
* @returns {Promise<boolean>}
*/
async addBlocked(user) {
const id = this.resolveId(user);
// Check

View File

@ -4,7 +4,7 @@ const https = require('node:https');
const { setTimeout } = require('node:timers');
const FormData = require('form-data');
const fetch = require('node-fetch');
const { UserAgent } = require('../util/Constants');
const { randomUA } = require('../util/Constants');
let agent = null;
@ -18,7 +18,7 @@ class APIRequest {
this.retries = 0;
const { userAgentSuffix } = this.client.options;
this.fullUserAgent = `${UserAgent}${userAgentSuffix.length ? `, ${userAgentSuffix.join(', ')}` : ''}`;
this.fullUserAgent = `${randomUA()}${userAgentSuffix.length ? `, ${userAgentSuffix.join(', ')}` : ''}`;
let queryString = '';
if (options.query) {

View File

@ -5,7 +5,7 @@ const Base = require('./Base');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const { Relationship } = require('../util/Constants');
const { RelationshipTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const UserFlags = require('../util/UserFlags');
@ -164,12 +164,12 @@ class User extends Base {
/**
* Check relationship status
* @type {Relationship}
* @type {RelationshipTypes}
* @readonly
*/
get relationships() {
const i = this.client.relationships.cache.get(this.id) ?? 0;
return Relationship[parseInt(i)];
return RelationshipTypes[parseInt(i)];
}
/**

View File

@ -6,41 +6,39 @@ 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/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12.3; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (X11; Linux i686; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12.4; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (X11; Linux i686; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12.3; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12.4; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (X11; Linux i686; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/100.0.1185.39',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/100.0.1185.39',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33',
];
/**
* Nitro state
* * NONE
* * CLASSIC
* * BOOST
* @typedef {string} NitroState
*/
exports.NitroState = createEnum(['NONE', 'CLASSIC', 'BOOST']);
exports.NitroState = {
0: 'NONE',
1: 'CLASSIC',
2: 'BOOST',
};
exports.DMScanLevel = {
0: 'NOT_SCAN',
1: 'NOT_FRIEND',
2: 'EVERYONE',
};
exports.DMScanLevel = createEnum(['NOT_SCAN', 'NOT_FRIEND', 'EVERYONE']);
exports.stickerAnimationMode = {
0: 'ALWAYS',
@ -80,9 +78,7 @@ exports.localeObject = {
'zh-TW': 'TAIWAN_CHINESE',
ko: 'KOREAN',
};
// No used
exports.UserAgent = listUserAgent[Math.floor(Math.random() * listUserAgent.length)];
// Useful
exports.randomUA = () => listUserAgent[Math.floor(Math.random() * listUserAgent.length)];
exports.WSCodes = {
@ -206,7 +202,7 @@ exports.Opcodes = {
HEARTBEAT_ACK: 11, // # Sent immediately following a client heartbeat that was received
GUILD_SYNC: 12, // # Receive guild_sync but not used anymore
/** Add some opcode from Discum
/* @extends https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/gateway/gateway.py#L56
/* @see https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/gateway/gateway.py#L56
*/
DM_UPDATE: 13, // # Send used to get dm features
LAZY_REQUEST: 14, // # Send discord responds back with GUILD_MEMBER_LIST_UPDATE type SYNC...
@ -293,14 +289,14 @@ exports.Events = {
TYPING_START: 'typingStart',
WEBHOOKS_UPDATE: 'webhookUpdate',
INTERACTION_CREATE: 'interactionCreate',
/**
* @private This event is not documented in the API.
*/
INTERACTION_SUCCESS: 'interactionSuccess',
/**
* @private This event is not documented in the API.
*/
INTERACTION_FAILED: 'interactionFailed',
/**
* @private This event is not documented in the API.
*/
ERROR: 'error',
WARN: 'warn',
DEBUG: 'debug',
@ -323,13 +319,16 @@ exports.Events = {
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete',
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd',
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove',
/**
* @private This event is not documented in the API.
*/
RELATIONSHIP_ADD: 'relationshipAdd',
/**
* @private This event is not documented in the API.
*/
RELATIONSHIP_REMOVE: 'relationshipRemove',
/**
* @private This event is not documented in the API.
* @private .-. hidden data from discord :))
*/
UNHANDLED_PACKET: 'unhandledPacket',
};
@ -1301,24 +1300,17 @@ exports.TextInputStyles = createEnum([null, 'SHORT', 'PARAGRAPH']);
exports.GuildScheduledEventPrivacyLevels = createEnum([null, null, 'GUILD_ONLY']);
/**
* Relationship Enum
* * FRIEND
* * BLOCKED
* * INCOMING_REQUEST
* * OUTGOING_REQUEST
* @typedef {string} RelationshipType
* Relationship Enums:
* * 0: NONE
* * 1: FRIEND
* * 2: BLOCKED
* * 3: INCOMING_REQUEST
* * 4: OUTGOING_REQUEST
* @typedef {string} RelationshipTypes
* @see {@link https://luna.gitlab.io/discord-unofficial-docs/relationships.html}
*/
exports.RelationshipTypes = createEnum([null, 'FRIEND', 'BLOCKED', 'INCOMING_REQUEST', 'OUTGOING_REQUEST']);
exports.Relationship = {
0: 'NONE',
1: 'FRIEND',
2: 'BLOCKED',
3: 'INCOMING_REQUEST',
4: 'OUTGOING_REQUEST',
};
exports.RelationshipTypes = createEnum(['NONE', 'FRIEND', 'BLOCKED', 'INCOMING_REQUEST', 'OUTGOING_REQUEST']);
/**
* The premium tier (Server Boost level) of a guild:

2
typings/index.d.ts vendored
View File

@ -3036,7 +3036,6 @@ export const Constants: {
devDependencies: Record<string, string>;
[key: string]: unknown;
};
UserAgent: string;
Endpoints: {
botGateway: string;
invite: (root: string, code: string, eventId?: Snowflake) => string;
@ -3150,6 +3149,7 @@ export const Constants: {
GuildScheduledEventEntityTypes: EnumHolder<typeof GuildScheduledEventEntityTypes>;
GuildScheduledEventStatuses: EnumHolder<typeof GuildScheduledEventStatuses>;
GuildScheduledEventPrivacyLevels: EnumHolder<typeof GuildScheduledEventPrivacyLevels>;
randomUA: () => string;
};
export const version: string;