From 010272fba78af5c856f7cf23658dbb0aaee4a2f2 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:10:51 +0700 Subject: [PATCH] Minor change (description) - feat(ApplicationCommand): add `min_length` and `max_length` for string option (v13) #8217 (Djs v13.9) - fix(Interaction): Button.click & Menu.select return Snowflake - feat(MessagePayload): Send Activity message --- README.md | 1 + package-lock.json | 2 +- package.json | 2 +- src/structures/ApplicationCommand.js | 16 ++++++++- src/structures/Message.js | 20 ++++++++--- src/structures/MessageButton.js | 7 ++-- src/structures/MessagePayload.js | 19 +++++++++++ src/structures/MessageSelectMenu.js | 7 ++-- src/structures/Presence.js | 2 +- src/structures/RichPresence.js | 2 +- src/structures/interfaces/TextBasedChannel.js | 1 + typings/index.d.ts | 34 ++++++++++++++----- 12 files changed, 90 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7e2b964..a50f5ae 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ ### I don't take any responsibility for blocked Discord accounts that used this module. ### Using this on a user account is prohibited by the [Discord TOS](https://discord.com/terms) and can lead to the account block. +### Finally the package got 100 stars (GitHub), thank you all 💖 ### [Document Website (recommend)](https://discordjs-self-v13.netlify.app/) diff --git a/package-lock.json b/package-lock.json index 1b7408a..e012663 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "discord.js-selfbot-v13", - "version": "2.3.64", + "version": "2.3.65", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index a385ecb..3995a96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js-selfbot-v13", - "version": "2.3.64", + "version": "2.3.65", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]", "main": "./src/index.js", "types": "./typings/index.d.ts", diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index fcb7813..117908d 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -232,6 +232,10 @@ class ApplicationCommand extends Base { * the allowed types of channels that can be selected * @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option * @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option + * @property {number} [minLength] The minimum length for a `STRING` option + * (maximum of `6000`) + * @property {number} [maxLength] The maximum length for a `STRING` option + * (maximum of `6000`) */ /** @@ -461,7 +465,9 @@ class ApplicationCommand extends Base { option.options?.length !== existing.options?.length || (option.channelTypes ?? option.channel_types)?.length !== existing.channelTypes?.length || (option.minValue ?? option.min_value) !== existing.minValue || - (option.maxValue ?? option.max_value) !== existing.maxValue + (option.maxValue ?? option.max_value) !== existing.maxValue || + (option.minLength ?? option.min_length) !== existing.minLength || + (option.maxLength ?? option.max_length) !== existing.maxLength ) { return false; } @@ -517,6 +523,10 @@ class ApplicationCommand extends Base { * the allowed types of channels that can be selected * @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option * @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option + * @property {number} [minLength] The minimum length for a `STRING` option + * (maximum of `6000`) + * @property {number} [maxLength] The maximum length for a `STRING` option + * (maximum of `6000`) */ /** @@ -540,6 +550,8 @@ class ApplicationCommand extends Base { const channelTypesKey = received ? 'channelTypes' : 'channel_types'; const minValueKey = received ? 'minValue' : 'min_value'; const maxValueKey = received ? 'maxValue' : 'max_value'; + const minLengthKey = received ? 'minLength' : 'min_length'; + const maxLengthKey = received ? 'maxLength' : 'max_length'; const nameLocalizationsKey = received ? 'nameLocalizations' : 'name_localizations'; const nameLocalizedKey = received ? 'nameLocalized' : 'name_localized'; const descriptionLocalizationsKey = received ? 'descriptionLocalizations' : 'description_localizations'; @@ -569,6 +581,8 @@ class ApplicationCommand extends Base { option.channel_types, [minValueKey]: option.minValue ?? option.min_value, [maxValueKey]: option.maxValue ?? option.max_value, + [minLengthKey]: option.minLength ?? option.min_length, + [maxLengthKey]: option.maxLength ?? option.max_length, }; } /** diff --git a/src/structures/Message.js b/src/structures/Message.js index a610b0d..86c5b88 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -15,6 +15,7 @@ const ReactionCollector = require('./ReactionCollector'); const { Sticker } = require('./Sticker'); const { Error } = require('../errors'); const ReactionManager = require('../managers/ReactionManager'); +const ActivityFlags = require('../util/ActivityFlags'); const { InteractionTypes, MessageTypes, SystemMessageTypes } = require('../util/Constants'); const MessageFlags = require('../util/MessageFlags'); const Permissions = require('../util/Permissions'); @@ -269,7 +270,7 @@ class Message extends Base { */ this.activity = { partyId: data.activity.party_id, - type: data.activity.type, + type: new ActivityFlags(data.activity.type), }; } else { this.activity ??= null; @@ -1037,8 +1038,15 @@ class Message extends Base { ); }), ); - if (!button) throw new TypeError('BUTTON_NOT_FOUND'); - else button.click(this); + if (!button) { + throw new TypeError('BUTTON_NOT_FOUND'); + } else { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async (resolve, reject) => { + const res = await button.click(this).catch(reject); + if (res) resolve(res); + }); + } } /** * Select specific menu or First Menu @@ -1070,7 +1078,11 @@ class Message extends Base { else if (typeof menuID !== 'string') throw new TypeError('MENU_ID_NOT_STRING'); else throw new TypeError('MENU_ID_NOT_FOUND'); } - menuCorrect.select(this, Array.isArray(menuID) ? menuID : options); + // eslint-disable-next-line no-async-promise-executor + return new Promise(async (resolve, reject) => { + const res = await menuCorrect.select(this, Array.isArray(menuID) ? menuID : options).catch(reject); + if (res) resolve(res); + }); } // /** diff --git a/src/structures/MessageButton.js b/src/structures/MessageButton.js index 6b46cc3..d9ac9b5 100644 --- a/src/structures/MessageButton.js +++ b/src/structures/MessageButton.js @@ -166,14 +166,16 @@ class MessageButton extends BaseMessageComponent { /** * Click the button * @param {Message} message Discord Message - * @returns {boolean} + * @returns {Promise} */ async click(message) { + const nonce = SnowflakeUtil.generate(); if (!(message instanceof Message)) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message'); if (!this.customId || this.style == 5 || this.disabled) return false; // Button URL, Disabled await message.client.api.interactions.post({ data: { type: 3, // ? + nonce, guild_id: message.guild?.id ?? null, // In DMs channel_id: message.channel.id, message_id: message.id, @@ -184,10 +186,9 @@ class MessageButton extends BaseMessageComponent { component_type: 2, // Button custom_id: this.customId, }, - nonce: SnowflakeUtil.generate(), }, }); - return true; + return nonce; } } diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index e3bc3f8..32364ea 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -5,6 +5,7 @@ const BaseMessageComponent = require('./BaseMessageComponent'); const MessageEmbed = require('./MessageEmbed'); const WebEmbed = require('./WebEmbed'); const { RangeError } = require('../errors'); +const ActivityFlags = require('../util/ActivityFlags'); const DataResolver = require('../util/DataResolver'); const MessageFlags = require('../util/MessageFlags'); const Util = require('../util/Util'); @@ -226,7 +227,25 @@ class MessagePayload { } } + // Activity + let activity; + if ( + this.options.activity instanceof Object && + typeof this.options.activity.partyId == 'string' && + this.options.activity.type + ) { + const type = ActivityFlags.resolve(this.options.activity.type); + const sessionId = this.target.client.session_id; + const partyId = this.options.activity.partyId; + activity = { + type, + party_id: partyId, + session_id: sessionId, + }; + } + this.data = { + activity, content, tts, nonce, diff --git a/src/structures/MessageSelectMenu.js b/src/structures/MessageSelectMenu.js index fc61344..5d63f3a 100644 --- a/src/structures/MessageSelectMenu.js +++ b/src/structures/MessageSelectMenu.js @@ -214,7 +214,7 @@ class MessageSelectMenu extends BaseMessageComponent { * Mesage select menu * @param {Message} message The message this select menu is for * @param {Array} values The values of the select menu - * @returns {Promise} + * @returns {Promise} */ async select(message, values = []) { // Github copilot is the best :)) @@ -240,6 +240,7 @@ class MessageSelectMenu extends BaseMessageComponent { `[SELECT_MENU_INVALID_VALUE] The value ${check_} is invalid. Please use a valid value ${validValue.join(', ')}`, ); } + const nonce = SnowflakeUtil.generate(); await message.client.api.interactions.post({ data: { type: 3, // ? @@ -255,10 +256,10 @@ class MessageSelectMenu extends BaseMessageComponent { type: 3, // Select Menu values, }, - nonce: SnowflakeUtil.generate(), + nonce, }, }); - return true; + return nonce; } } diff --git a/src/structures/Presence.js b/src/structures/Presence.js index afa3212..2f4bde0 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -10,7 +10,7 @@ const Util = require('../util/Util'); * Activity sent in a message. * @typedef {Object} MessageActivity * @property {string} [partyId] Id of the party represented in activity - * @property {number} [type] Type of activity sent + * @property {ActivityFlags} [type] Type of activity sent */ /** diff --git a/src/structures/RichPresence.js b/src/structures/RichPresence.js index 9bdd5db..b53f930 100644 --- a/src/structures/RichPresence.js +++ b/src/structures/RichPresence.js @@ -443,7 +443,7 @@ class SpotifyRPC extends RichPresence { * The game's or Spotify session's id * @type {?string} */ - this.session_id = this.client.ws.shards.first().sessionId; + this.session_id = this.client.session_id; this.secrets = { join: crypto.randomBytes(20).toString('hex'), // SHA1 / SHA128 diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index 0b6ca5f..2f2376b 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -57,6 +57,7 @@ class TextBasedChannel { /** * Base options provided when sending. * @typedef {Object} BaseMessageOptions + * @property {MessageActivity} [activity] Group activity * @property {boolean} [tts=false] Whether or not the message should be spoken aloud * @property {string} [nonce=''] The nonce for the message * @property {string} [content=''] The content for the message diff --git a/typings/index.d.ts b/typings/index.d.ts index 8080e23..7383282 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1771,9 +1771,9 @@ export class Message extends Base { public inGuild(): this is Message & this; // Added public markUnread(): Promise; - public clickButton(buttonID: string): Promise; - public selectMenu(menuID: string, options: string[]): Promise; - public selectMenu(options: string[]): Promise; + public clickButton(buttonID: string): Promise; + public selectMenu(menuID: string, options: string[]): Promise; + public selectMenu(options: string[]): Promise; public contextMenu(botID: Snowflake, commandName: string): Promise; } @@ -1832,7 +1832,7 @@ export class MessageButton extends BaseMessageComponent { public setStyle(style: MessageButtonStyleResolvable): this; public setURL(url: string): this; public toJSON(): APIButtonComponent; - public click(message: Message): Promise; + public click(message: Message): Promise; private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle; } @@ -2070,7 +2070,7 @@ export class MessageSelectMenu extends BaseMessageComponent { ...options: MessageSelectOptionData[] | MessageSelectOptionData[][] ): this; public toJSON(): APISelectMenuComponent; - public select(message: Message, values: string[]): Promise; + public select(message: Message, values: string[]): Promise; } // Todo @@ -4477,7 +4477,7 @@ export interface ApplicationCommandChoicesData extends Omit { - type: Exclude; + type: CommandOptionChoiceResolvableType; choices?: ApplicationCommandOptionChoiceData[]; autocomplete?: false; } @@ -4490,12 +4490,26 @@ export interface ApplicationCommandNumericOptionData extends ApplicationCommandC max_value?: number; } +export interface ApplicationCommandStringOptionData extends ApplicationCommandChoicesData { + type: ApplicationCommandOptionTypes.STRING; + minLength?: number; + min_length?: number; + maxLength?: number; + max_length?: number; +} + export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption { - type: Exclude; + type: CommandOptionNumericResolvableType; minValue?: number; maxValue?: number; } +export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption { + type: ApplicationCommandOptionTypes.STRING; + minLength?: number; + maxLength?: number; +} + export interface ApplicationCommandSubGroupData extends Omit { type: 'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP; options?: ApplicationCommandSubCommandData[]; @@ -4514,6 +4528,7 @@ export interface ApplicationCommandSubCommandData extends Omit