Merge pull request #297 from aiko-chan-ai/dev

Update
This commit is contained in:
Cinnamon 2022-09-09 23:49:13 +07:00 committed by GitHub
commit 6093a60ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 112 additions and 24 deletions

View File

@ -52,17 +52,17 @@
"homepage": "https://github.com/aiko-chan-ai/discord.js-selfbot-v13#readme", "homepage": "https://github.com/aiko-chan-ai/discord.js-selfbot-v13#readme",
"dependencies": { "dependencies": {
"@aikochan2k6/qrcode-terminal": "^0.12.1", "@aikochan2k6/qrcode-terminal": "^0.12.1",
"@discordjs/builders": "^1.1.0", "@discordjs/builders": "^1.2.0",
"@discordjs/collection": "^1.0.0", "@discordjs/collection": "^1.1.0",
"@discordjs/voice": "^0.11.0", "@discordjs/voice": "^0.11.0",
"@sapphire/async-queue": "^1.5.0", "@sapphire/async-queue": "^1.5.0",
"@sapphire/shapeshift": "^3.5.1", "@sapphire/shapeshift": "^3.6.0",
"@types/node-fetch": "^2.6.2", "@types/node-fetch": "^2.6.2",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
"axios": "^0.27.2", "axios": "^0.27.2",
"bignumber.js": "^9.1.0", "bignumber.js": "^9.1.0",
"chalk": "^4.1.2", "chalk": "^4.1.2",
"discord-api-types": "^0.37.3", "discord-api-types": "^0.37.8",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"json-bigint": "^1.0.0", "json-bigint": "^1.0.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
@ -83,7 +83,7 @@
"@types/node": "^16.11.12", "@types/node": "^16.11.12",
"conventional-changelog-cli": "^2.2.2", "conventional-changelog-cli": "^2.2.2",
"dtslint": "^4.2.1", "dtslint": "^4.2.1",
"eslint": "^8.22.0", "eslint": "^8.23.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3", "eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
@ -94,6 +94,6 @@
"prettier": "^2.5.1", "prettier": "^2.5.1",
"tsd": "^0.22.0", "tsd": "^0.22.0",
"tslint": "^6.1.3", "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 ClientSettingManager = require('../managers/ClientSettingManager');
const DeveloperPortalManager = require('../managers/DeveloperPortalManager'); const DeveloperPortalManager = require('../managers/DeveloperPortalManager');
const GuildManager = require('../managers/GuildManager'); const GuildManager = require('../managers/GuildManager');
const RelationshipsManager = require('../managers/RelationshipsManager'); const RelationshipManager = require('../managers/RelationshipManager');
const SessionManager = require('../managers/SessionManager'); const SessionManager = require('../managers/SessionManager');
const UserManager = require('../managers/UserManager'); const UserManager = require('../managers/UserManager');
const VoiceStateManager = require('../managers/VoiceStateManager'); const VoiceStateManager = require('../managers/VoiceStateManager');
@ -142,9 +142,9 @@ class Client extends BaseClient {
// Patch // Patch
/** /**
* All of the relationships {@link User} * 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} * All of the settings {@link Object}
* @type {ClientSettingManager} * @type {ClientSettingManager}

View File

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

View File

@ -1,11 +1,14 @@
'use strict'; 'use strict';
const process = require('node:process');
const { Collection } = require('@discordjs/collection'); const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager'); const CachedManager = require('./CachedManager');
const { TypeError, Error } = require('../errors'); const { TypeError, Error } = require('../errors');
const GuildBan = require('../structures/GuildBan'); const GuildBan = require('../structures/GuildBan');
const { GuildMember } = require('../structures/GuildMember'); const { GuildMember } = require('../structures/GuildMember');
let deprecationEmittedForDays = false;
/** /**
* Manages API methods for GuildBans and stores their cache. * Manages API methods for GuildBans and stores their cache.
* @extends {CachedManager} * @extends {CachedManager}
@ -126,6 +129,9 @@ class GuildBanManager extends CachedManager {
* Options used to ban a user from a guild. * Options used to ban a user from a guild.
* @typedef {Object} BanOptions * @typedef {Object} BanOptions
* @property {number} [days=0] Number of days of messages to delete, must be between 0 and 7, inclusive * @property {number} [days=0] Number of days of messages to delete, must be between 0 and 7, inclusive
* <warn>This property is deprecated. Use `deleteMessageSeconds` instead.</warn>
* @property {number} [deleteMessageSeconds=0] Number of seconds of messages to delete,
* must be between 0 and 604800 (7 days), inclusive
* @property {string} [reason] The reason for the ban * @property {string} [reason] The reason for the ban
*/ */
@ -142,15 +148,30 @@ class GuildBanManager extends CachedManager {
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`)) * .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
* .catch(console.error); * .catch(console.error);
*/ */
async create(user, options = { days: 0 }) { async create(user, options = {}) {
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true); if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
const id = this.client.users.resolveId(user); const id = this.client.users.resolveId(user);
if (!id) throw new Error('BAN_RESOLVE_ID', true); if (!id) throw new Error('BAN_RESOLVE_ID', true);
if (typeof options.days !== 'undefined' && !deprecationEmittedForDays) {
process.emitWarning(
'The days option for GuildBanManager#create() is deprecated. Use the deleteMessageSeconds option instead.',
'DeprecationWarning',
);
deprecationEmittedForDays = true;
}
await this.client.api await this.client.api
.guilds(this.guild.id) .guilds(this.guild.id)
.bans(id) .bans(id)
.put({ .put({
data: { delete_message_days: options.days }, data: {
delete_message_seconds:
typeof options.deleteMessageSeconds !== 'undefined'
? options.deleteMessageSeconds
: (options.days ?? 0) * 24 * 60 * 60,
},
reason: options.reason, reason: options.reason,
}); });
if (user instanceof GuildMember) return user; if (user instanceof GuildMember) return user;

View File

@ -394,7 +394,7 @@ class GuildMemberManager extends CachedManager {
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`)) * .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
* .catch(console.error); * .catch(console.error);
*/ */
ban(user, options = { days: 0 }) { ban(user, options) {
return this.guild.bans.create(user, options); return this.guild.bans.create(user, options);
} }

View File

@ -10,7 +10,7 @@ const { RelationshipTypes } = require('../util/Constants');
/** /**
* Manages API methods for Relationships and stores their cache. * Manages API methods for Relationships and stores their cache.
*/ */
class RelationshipsManager { class RelationshipManager {
constructor(client, users) { constructor(client, users) {
/** /**
* The client that instantiated this manager. * The client that instantiated this manager.
@ -26,6 +26,54 @@ class RelationshipsManager {
this._setup(users); 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 * Return array of cache
* @returns {Array<{id: Snowflake, type: RelationshipTypes}>} * @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'; 'use strict';
const { Collection } = require('@discordjs/collection');
const Team = require('./Team'); const Team = require('./Team');
const Application = require('./interfaces/Application'); const Application = require('./interfaces/Application');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager'); const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
@ -107,6 +108,17 @@ class ClientApplication extends Application {
this.botPublic ??= null; 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 * The owner of this OAuth application
* @type {?(User|Team)} * @type {?(User|Team)}

View File

@ -465,8 +465,8 @@ class GuildMember extends Base {
* @param {BanOptions} [options] Options for the ban * @param {BanOptions} [options] Options for the ban
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
* @example * @example
* // ban a guild member * // Ban a guild member, deleting a week's worth of messages
* guildMember.ban({ days: 7, reason: 'They deserved it' }) * guildMember.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: 'They deserved it' })
* .then(console.log) * .then(console.log)
* .catch(console.error); * .catch(console.error);
*/ */

View File

@ -40,6 +40,7 @@ class Intents extends BitField {}
* * `DIRECT_MESSAGES` * * `DIRECT_MESSAGES`
* * `DIRECT_MESSAGE_REACTIONS` * * `DIRECT_MESSAGE_REACTIONS`
* * `DIRECT_MESSAGE_TYPING` * * `DIRECT_MESSAGE_TYPING`
* * `MESSAGE_CONTENT`
* * `GUILD_SCHEDULED_EVENTS` * * `GUILD_SCHEDULED_EVENTS`
* @type {Object} * @type {Object}
* @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents} * @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents}
@ -60,6 +61,7 @@ Intents.FLAGS = {
DIRECT_MESSAGES: 1 << 12, DIRECT_MESSAGES: 1 << 12,
DIRECT_MESSAGE_REACTIONS: 1 << 13, DIRECT_MESSAGE_REACTIONS: 1 << 13,
DIRECT_MESSAGE_TYPING: 1 << 14, DIRECT_MESSAGE_TYPING: 1 << 14,
MESSAGE_CONTENT: 1 << 15,
GUILD_SCHEDULED_EVENTS: 1 << 16, GUILD_SCHEDULED_EVENTS: 1 << 16,
}; };

19
typings/index.d.ts vendored
View File

@ -9,7 +9,6 @@ import {
hyperlink, hyperlink,
inlineCode, inlineCode,
italic, italic,
JSONEncodable,
quote, quote,
roleMention, roleMention,
SlashCommandBuilder, SlashCommandBuilder,
@ -25,14 +24,11 @@ import { VoiceConnection } from '@discordjs/voice';
import { Collection } from '@discordjs/collection'; import { Collection } from '@discordjs/collection';
import { import {
APIActionRowComponent, APIActionRowComponent,
APIActionRowComponentTypes,
APIApplicationCommand,
APIApplicationCommandInteractionData, APIApplicationCommandInteractionData,
APIApplicationCommandOption, APIApplicationCommandOption,
APIApplicationCommandPermission, APIApplicationCommandPermission,
APIAuditLogChange, APIAuditLogChange,
APIButtonComponent, APIButtonComponent,
APIChannel,
APIEmbed, APIEmbed,
APIEmoji, APIEmoji,
APIInteractionDataResolvedChannel, APIInteractionDataResolvedChannel,
@ -832,7 +828,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public application: If<Ready, ClientApplication>; public application: If<Ready, ClientApplication>;
// Added // Added
public setting: ClientSettingManager; public setting: ClientSettingManager;
public relationships: RelationshipsManager; public relationships: RelationshipManager;
public updateCookie(): Promise<void>; public updateCookie(): Promise<void>;
public readonly callVoice?: VoiceConnection; public readonly callVoice?: VoiceConnection;
public voiceStates: VoiceStateManager; public voiceStates: VoiceStateManager;
@ -903,6 +899,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
export class ClientApplication extends Application { export class ClientApplication extends Application {
private constructor(client: Client, data: RawClientApplicationData); private constructor(client: Client, data: RawClientApplicationData);
public botPublic: boolean | null; public botPublic: boolean | null;
public popularCommands: Collection<Snowflake, ApplicationCommand> | undefined;
public botRequireCodeGrant: boolean | null; public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager; public commands: ApplicationCommandManager;
public cover: string | null; public cover: string | null;
@ -1943,7 +1940,8 @@ export class MessageActionRow<
? APIActionRowComponent<APIModalActionRowComponent> ? APIActionRowComponent<APIModalActionRowComponent>
: APIActionRowComponent<APIMessageActionRowComponent>, : APIActionRowComponent<APIMessageActionRowComponent>,
> extends BaseMessageComponent { > 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 constructor(data?: MessageActionRow<T> | MessageActionRowOptions<U> | V);
public type: 'ACTION_ROW'; public type: 'ACTION_ROW';
public components: T[]; 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>; public send(user: UserResolvable, options: string | MessagePayload | MessageOptions): Promise<Message>;
} }
export class RelationshipsManager { export class RelationshipManager {
private constructor(client: Client, users?: object[]); private constructor(client: Client, users?: object[]);
public cache: Collection<Snowflake, RelationshipTypes>; public cache: Collection<Snowflake, RelationshipTypes>;
public client: Client; 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 fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<RelationshipTypes>;
public deleteFriend(user: UserResolvable): Promise<boolean>; public deleteFriend(user: UserResolvable): Promise<boolean>;
public deleteBlocked(user: UserResolvable): Promise<boolean>; public deleteBlocked(user: UserResolvable): Promise<boolean>;
@ -4858,7 +4860,9 @@ export interface AwaitReactionsOptions extends ReactionCollectorOptions {
} }
export interface BanOptions { export interface BanOptions {
/** @deprecated Use {@link deleteMessageSeconds} instead. */
days?: number; days?: number;
deleteMessageSeconds?: number;
reason?: string; reason?: string;
} }
@ -5845,6 +5849,7 @@ export type IntentsString =
| 'DIRECT_MESSAGES' | 'DIRECT_MESSAGES'
| 'DIRECT_MESSAGE_REACTIONS' | 'DIRECT_MESSAGE_REACTIONS'
| 'DIRECT_MESSAGE_TYPING' | 'DIRECT_MESSAGE_TYPING'
| 'MESSAGE_CONTENT'
| 'GUILD_SCHEDULED_EVENTS'; | 'GUILD_SCHEDULED_EVENTS';
export interface InviteGenerationOptions { export interface InviteGenerationOptions {