- refactor: rename `RelationshipsManager` > `RelationshipManager`

- feat(RelationshipManager): add `friendCache`, `blockedCache`, `incomingCache`, `outgoingCache`

- feat(ClientApplication): Add `popularCommands`

- deps: Update
This commit is contained in:
March 7th 2022-09-09 23:44:45 +07:00
parent af2a885f2a
commit fb71762d2d
7 changed files with 83 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "discord.js-selfbot-v13",
"version": "2.6.7",
"version": "2.6.12",
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js",
"types": "./typings/index.d.ts",
@ -52,17 +52,17 @@
"homepage": "https://github.com/aiko-chan-ai/discord.js-selfbot-v13#readme",
"dependencies": {
"@aikochan2k6/qrcode-terminal": "^0.12.1",
"@discordjs/builders": "^1.1.0",
"@discordjs/collection": "^1.0.0",
"@discordjs/builders": "^1.2.0",
"@discordjs/collection": "^1.1.0",
"@discordjs/voice": "^0.11.0",
"@sapphire/async-queue": "^1.5.0",
"@sapphire/shapeshift": "^3.5.1",
"@sapphire/shapeshift": "^3.6.0",
"@types/node-fetch": "^2.6.2",
"@types/ws": "^8.5.3",
"axios": "^0.27.2",
"bignumber.js": "^9.1.0",
"chalk": "^4.1.2",
"discord-api-types": "^0.37.3",
"discord-api-types": "^0.37.8",
"form-data": "^4.0.0",
"json-bigint": "^1.0.0",
"node-fetch": "^2.6.1",
@ -83,7 +83,7 @@
"@types/node": "^16.11.12",
"conventional-changelog-cli": "^2.2.2",
"dtslint": "^4.2.1",
"eslint": "^8.22.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.2.1",
@ -94,6 +94,6 @@
"prettier": "^2.5.1",
"tsd": "^0.22.0",
"tslint": "^6.1.3",
"typescript": "^4.5.4"
"typescript": "^4.8.3"
}
}

View File

@ -14,7 +14,7 @@ const ChannelManager = require('../managers/ChannelManager');
const ClientSettingManager = require('../managers/ClientSettingManager');
const DeveloperPortalManager = require('../managers/DeveloperPortalManager');
const GuildManager = require('../managers/GuildManager');
const RelationshipsManager = require('../managers/RelationshipsManager');
const RelationshipManager = require('../managers/RelationshipManager');
const SessionManager = require('../managers/SessionManager');
const UserManager = require('../managers/UserManager');
const VoiceStateManager = require('../managers/VoiceStateManager');
@ -142,9 +142,9 @@ class Client extends BaseClient {
// Patch
/**
* All of the relationships {@link User}
* @type {RelationshipsManager}
* @type {RelationshipManager}
*/
this.relationships = new RelationshipsManager(this);
this.relationships = new RelationshipManager(this);
/**
* All of the settings {@link Object}
* @type {ClientSettingManager}

View File

@ -68,7 +68,7 @@ exports.UserManager = require('./managers/UserManager');
exports.VoiceStateManager = require('./managers/VoiceStateManager');
exports.WebSocketManager = require('./client/websocket/WebSocketManager');
exports.WebSocketShard = require('./client/websocket/WebSocketShard');
exports.RelationshipsManager = require('./managers/RelationshipsManager');
exports.RelationshipManager = require('./managers/RelationshipManager');
// Structures
exports.Activity = require('./structures/Presence').Activity;

View File

@ -10,7 +10,7 @@ const { RelationshipTypes } = require('../util/Constants');
/**
* Manages API methods for Relationships and stores their cache.
*/
class RelationshipsManager {
class RelationshipManager {
constructor(client, users) {
/**
* The client that instantiated this manager.
@ -26,6 +26,54 @@ class RelationshipsManager {
this._setup(users);
}
/**
* Get all friends
* @type {Collection<Snowflake, User>}
* @readonly
*/
get friendCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.FRIEND)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all blocked users
* @type {Collection<Snowflake, User>}
* @readonly
*/
get blockedCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.BLOCKED)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all incoming friend requests
* @type {Collection<Snowflake, User>}
* @readonly
*/
get incomingCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.PENDING_INCOMING)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all outgoing friend requests
* @type {Collection<Snowflake, User>}
* @readonly
*/
get outgoingCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.PENDING_OUTGOING)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Return array of cache
* @returns {Array<{id: Snowflake, type: RelationshipTypes}>}
@ -172,4 +220,4 @@ class RelationshipsManager {
}
}
module.exports = RelationshipsManager;
module.exports = RelationshipManager;

View File

@ -1,5 +1,6 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const Team = require('./Team');
const Application = require('./interfaces/Application');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
@ -107,6 +108,17 @@ class ClientApplication extends Application {
this.botPublic ??= null;
}
if ('popular_application_command_ids' in data) {
/**
* List of popular command
* @type {?Collection<Snowflake, ApplicationCommand>}
*/
this.popularCommands = new Collection();
data.popular_application_command_ids.forEach(id => {
this.popularCommands.set(id, this.commands.cache.get(id));
});
}
/**
* The owner of this OAuth application
* @type {?(User|Team)}

16
typings/index.d.ts vendored
View File

@ -9,7 +9,6 @@ import {
hyperlink,
inlineCode,
italic,
JSONEncodable,
quote,
roleMention,
SlashCommandBuilder,
@ -25,14 +24,11 @@ import { VoiceConnection } from '@discordjs/voice';
import { Collection } from '@discordjs/collection';
import {
APIActionRowComponent,
APIActionRowComponentTypes,
APIApplicationCommand,
APIApplicationCommandInteractionData,
APIApplicationCommandOption,
APIApplicationCommandPermission,
APIAuditLogChange,
APIButtonComponent,
APIChannel,
APIEmbed,
APIEmoji,
APIInteractionDataResolvedChannel,
@ -832,7 +828,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public application: If<Ready, ClientApplication>;
// Added
public setting: ClientSettingManager;
public relationships: RelationshipsManager;
public relationships: RelationshipManager;
public updateCookie(): Promise<void>;
public readonly callVoice?: VoiceConnection;
public voiceStates: VoiceStateManager;
@ -903,6 +899,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
export class ClientApplication extends Application {
private constructor(client: Client, data: RawClientApplicationData);
public botPublic: boolean | null;
public popularCommands: Collection<Snowflake, ApplicationCommand> | undefined;
public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager;
public cover: string | null;
@ -1943,7 +1940,8 @@ export class MessageActionRow<
? APIActionRowComponent<APIModalActionRowComponent>
: APIActionRowComponent<APIMessageActionRowComponent>,
> extends BaseMessageComponent {
// @ts-ignore
// @ts-ignore (TS:2344, Caused by TypeScript 4.8)
// Fixed in DiscordJS >= 14.x / DiscordApiTypes >= 0.37.x, ignoring the type error here.
public constructor(data?: MessageActionRow<T> | MessageActionRowOptions<U> | V);
public type: 'ACTION_ROW';
public components: T[];
@ -3998,10 +3996,14 @@ export class UserManager extends CachedManager<Snowflake, User, UserResolvable>
public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>;
}
export class RelationshipsManager {
export class RelationshipManager {
private constructor(client: Client, users?: object[]);
public cache: Collection<Snowflake, RelationshipTypes>;
public client: Client;
public readonly friendCache: Collection<Snowflake, User>;
public readonly blockedCache: Collection<Snowflake, User>;
public readonly incomingCache: Collection<Snowflake, User>;
public readonly outgoingCache: Collection<Snowflake, User>;
public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<RelationshipTypes>;
public deleteFriend(user: UserResolvable): Promise<boolean>;
public deleteBlocked(user: UserResolvable): Promise<boolean>;