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
This commit is contained in:
March 7th 2022-07-07 16:10:51 +07:00
parent 578bc0adde
commit 010272fba7
12 changed files with 90 additions and 23 deletions

View File

@ -30,6 +30,7 @@
### <strong>I don't take any responsibility for blocked Discord accounts that used this module.</strong> ### <strong>I don't take any responsibility for blocked Discord accounts that used this module.</strong>
### <strong>Using this on a user account is prohibited by the [Discord TOS](https://discord.com/terms) and can lead to the account block.</strong> ### <strong>Using this on a user account is prohibited by the [Discord TOS](https://discord.com/terms) and can lead to the account block.</strong>
### Finally the package got 100 stars (GitHub), thank you all 💖
### <strong>[Document Website (recommend)](https://discordjs-self-v13.netlify.app/)</strong> ### <strong>[Document Website (recommend)](https://discordjs-self-v13.netlify.app/)</strong>

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "discord.js-selfbot-v13", "name": "discord.js-selfbot-v13",
"version": "2.3.64", "version": "2.3.65",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "discord.js-selfbot-v13", "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]", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",

View File

@ -232,6 +232,10 @@ class ApplicationCommand extends Base {
* the allowed types of channels that can be selected * the allowed types of channels that can be selected
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option * @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} [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.options?.length !== existing.options?.length ||
(option.channelTypes ?? option.channel_types)?.length !== existing.channelTypes?.length || (option.channelTypes ?? option.channel_types)?.length !== existing.channelTypes?.length ||
(option.minValue ?? option.min_value) !== existing.minValue || (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; return false;
} }
@ -517,6 +523,10 @@ class ApplicationCommand extends Base {
* the allowed types of channels that can be selected * the allowed types of channels that can be selected
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option * @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} [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 channelTypesKey = received ? 'channelTypes' : 'channel_types';
const minValueKey = received ? 'minValue' : 'min_value'; const minValueKey = received ? 'minValue' : 'min_value';
const maxValueKey = received ? 'maxValue' : 'max_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 nameLocalizationsKey = received ? 'nameLocalizations' : 'name_localizations';
const nameLocalizedKey = received ? 'nameLocalized' : 'name_localized'; const nameLocalizedKey = received ? 'nameLocalized' : 'name_localized';
const descriptionLocalizationsKey = received ? 'descriptionLocalizations' : 'description_localizations'; const descriptionLocalizationsKey = received ? 'descriptionLocalizations' : 'description_localizations';
@ -569,6 +581,8 @@ class ApplicationCommand extends Base {
option.channel_types, option.channel_types,
[minValueKey]: option.minValue ?? option.min_value, [minValueKey]: option.minValue ?? option.min_value,
[maxValueKey]: option.maxValue ?? option.max_value, [maxValueKey]: option.maxValue ?? option.max_value,
[minLengthKey]: option.minLength ?? option.min_length,
[maxLengthKey]: option.maxLength ?? option.max_length,
}; };
} }
/** /**

View File

@ -15,6 +15,7 @@ const ReactionCollector = require('./ReactionCollector');
const { Sticker } = require('./Sticker'); const { Sticker } = require('./Sticker');
const { Error } = require('../errors'); const { Error } = require('../errors');
const ReactionManager = require('../managers/ReactionManager'); const ReactionManager = require('../managers/ReactionManager');
const ActivityFlags = require('../util/ActivityFlags');
const { InteractionTypes, MessageTypes, SystemMessageTypes } = require('../util/Constants'); const { InteractionTypes, MessageTypes, SystemMessageTypes } = require('../util/Constants');
const MessageFlags = require('../util/MessageFlags'); const MessageFlags = require('../util/MessageFlags');
const Permissions = require('../util/Permissions'); const Permissions = require('../util/Permissions');
@ -269,7 +270,7 @@ class Message extends Base {
*/ */
this.activity = { this.activity = {
partyId: data.activity.party_id, partyId: data.activity.party_id,
type: data.activity.type, type: new ActivityFlags(data.activity.type),
}; };
} else { } else {
this.activity ??= null; this.activity ??= null;
@ -1037,8 +1038,15 @@ class Message extends Base {
); );
}), }),
); );
if (!button) throw new TypeError('BUTTON_NOT_FOUND'); if (!button) {
else button.click(this); 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 * 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 if (typeof menuID !== 'string') throw new TypeError('MENU_ID_NOT_STRING');
else throw new TypeError('MENU_ID_NOT_FOUND'); 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);
});
} }
// //
/** /**

View File

@ -166,14 +166,16 @@ class MessageButton extends BaseMessageComponent {
/** /**
* Click the button * Click the button
* @param {Message} message Discord Message * @param {Message} message Discord Message
* @returns {boolean} * @returns {Promise<Snowflake>}
*/ */
async click(message) { async click(message) {
const nonce = SnowflakeUtil.generate();
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 (!this.customId || this.style == 5 || this.disabled) return false; // Button URL, Disabled if (!this.customId || this.style == 5 || this.disabled) return false; // Button URL, Disabled
await message.client.api.interactions.post({ await message.client.api.interactions.post({
data: { data: {
type: 3, // ? type: 3, // ?
nonce,
guild_id: message.guild?.id ?? null, // In DMs guild_id: message.guild?.id ?? null, // In DMs
channel_id: message.channel.id, channel_id: message.channel.id,
message_id: message.id, message_id: message.id,
@ -184,10 +186,9 @@ class MessageButton extends BaseMessageComponent {
component_type: 2, // Button component_type: 2, // Button
custom_id: this.customId, custom_id: this.customId,
}, },
nonce: SnowflakeUtil.generate(),
}, },
}); });
return true; return nonce;
} }
} }

View File

@ -5,6 +5,7 @@ const BaseMessageComponent = require('./BaseMessageComponent');
const MessageEmbed = require('./MessageEmbed'); const MessageEmbed = require('./MessageEmbed');
const WebEmbed = require('./WebEmbed'); const WebEmbed = require('./WebEmbed');
const { RangeError } = require('../errors'); const { RangeError } = require('../errors');
const ActivityFlags = require('../util/ActivityFlags');
const DataResolver = require('../util/DataResolver'); const DataResolver = require('../util/DataResolver');
const MessageFlags = require('../util/MessageFlags'); const MessageFlags = require('../util/MessageFlags');
const Util = require('../util/Util'); 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 = { this.data = {
activity,
content, content,
tts, tts,
nonce, nonce,

View File

@ -214,7 +214,7 @@ class MessageSelectMenu extends BaseMessageComponent {
* Mesage select menu * Mesage select menu
* @param {Message} message The message this select menu is for * @param {Message} message The message this select menu is for
* @param {Array<string>} values The values of the select menu * @param {Array<string>} values The values of the select menu
* @returns {Promise<boolean>} * @returns {Promise<Snowflake>}
*/ */
async select(message, values = []) { async select(message, values = []) {
// Github copilot is the best :)) // 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(', ')}`, `[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({ await message.client.api.interactions.post({
data: { data: {
type: 3, // ? type: 3, // ?
@ -255,10 +256,10 @@ class MessageSelectMenu extends BaseMessageComponent {
type: 3, // Select Menu type: 3, // Select Menu
values, values,
}, },
nonce: SnowflakeUtil.generate(), nonce,
}, },
}); });
return true; return nonce;
} }
} }

View File

@ -10,7 +10,7 @@ const Util = require('../util/Util');
* Activity sent in a message. * Activity sent in a message.
* @typedef {Object} MessageActivity * @typedef {Object} MessageActivity
* @property {string} [partyId] Id of the party represented in activity * @property {string} [partyId] Id of the party represented in activity
* @property {number} [type] Type of activity sent * @property {ActivityFlags} [type] Type of activity sent
*/ */
/** /**

View File

@ -443,7 +443,7 @@ class SpotifyRPC extends RichPresence {
* The game's or Spotify session's id * The game's or Spotify session's id
* @type {?string} * @type {?string}
*/ */
this.session_id = this.client.ws.shards.first().sessionId; this.session_id = this.client.session_id;
this.secrets = { this.secrets = {
join: crypto.randomBytes(20).toString('hex'), // SHA1 / SHA128 join: crypto.randomBytes(20).toString('hex'), // SHA1 / SHA128

View File

@ -57,6 +57,7 @@ class TextBasedChannel {
/** /**
* Base options provided when sending. * Base options provided when sending.
* @typedef {Object} BaseMessageOptions * @typedef {Object} BaseMessageOptions
* @property {MessageActivity} [activity] Group activity
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud * @property {boolean} [tts=false] Whether or not the message should be spoken aloud
* @property {string} [nonce=''] The nonce for the message * @property {string} [nonce=''] The nonce for the message
* @property {string} [content=''] The content for the message * @property {string} [content=''] The content for the message

34
typings/index.d.ts vendored
View File

@ -1771,9 +1771,9 @@ export class Message<Cached extends boolean = boolean> extends Base {
public inGuild(): this is Message<true> & this; public inGuild(): this is Message<true> & this;
// Added // Added
public markUnread(): Promise<boolean>; public markUnread(): Promise<boolean>;
public clickButton(buttonID: string): Promise<void>; public clickButton(buttonID: string): Promise<Snowflake>;
public selectMenu(menuID: string, options: string[]): Promise<void>; public selectMenu(menuID: string, options: string[]): Promise<Snowflake>;
public selectMenu(options: string[]): Promise<void>; public selectMenu(options: string[]): Promise<Snowflake>;
public contextMenu(botID: Snowflake, commandName: string): Promise<Snowflake>; public contextMenu(botID: Snowflake, commandName: string): Promise<Snowflake>;
} }
@ -1832,7 +1832,7 @@ export class MessageButton extends BaseMessageComponent {
public setStyle(style: MessageButtonStyleResolvable): this; public setStyle(style: MessageButtonStyleResolvable): this;
public setURL(url: string): this; public setURL(url: string): this;
public toJSON(): APIButtonComponent; public toJSON(): APIButtonComponent;
public click(message: Message): Promise<boolean>; public click(message: Message): Promise<Snowflake>;
private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle; private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle;
} }
@ -2070,7 +2070,7 @@ export class MessageSelectMenu extends BaseMessageComponent {
...options: MessageSelectOptionData[] | MessageSelectOptionData[][] ...options: MessageSelectOptionData[] | MessageSelectOptionData[][]
): this; ): this;
public toJSON(): APISelectMenuComponent; public toJSON(): APISelectMenuComponent;
public select(message: Message, values: string[]): Promise<boolean>; public select(message: Message, values: string[]): Promise<Snowflake>;
} }
// Todo // Todo
@ -4477,7 +4477,7 @@ export interface ApplicationCommandChoicesData extends Omit<BaseApplicationComma
} }
export interface ApplicationCommandChoicesOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> { export interface ApplicationCommandChoicesOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: Exclude<CommandOptionChoiceResolvableType, ApplicationCommandOptionTypes>; type: CommandOptionChoiceResolvableType;
choices?: ApplicationCommandOptionChoiceData[]; choices?: ApplicationCommandOptionChoiceData[];
autocomplete?: false; autocomplete?: false;
} }
@ -4490,12 +4490,26 @@ export interface ApplicationCommandNumericOptionData extends ApplicationCommandC
max_value?: number; 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 { export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption {
type: Exclude<CommandOptionNumericResolvableType, ApplicationCommandOptionTypes>; type: CommandOptionNumericResolvableType;
minValue?: number; minValue?: number;
maxValue?: number; maxValue?: number;
} }
export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption {
type: ApplicationCommandOptionTypes.STRING;
minLength?: number;
maxLength?: number;
}
export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> { export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: 'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP; type: 'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP;
options?: ApplicationCommandSubCommandData[]; options?: ApplicationCommandSubCommandData[];
@ -4514,6 +4528,7 @@ export interface ApplicationCommandSubCommandData extends Omit<BaseApplicationCo
| ApplicationCommandChannelOptionData | ApplicationCommandChannelOptionData
| ApplicationCommandAutocompleteOption | ApplicationCommandAutocompleteOption
| ApplicationCommandNumericOptionData | ApplicationCommandNumericOptionData
| ApplicationCommandStringOptionData
)[]; )[];
} }
@ -4537,6 +4552,7 @@ export type ApplicationCommandOptionData =
| ApplicationCommandChoicesData | ApplicationCommandChoicesData
| ApplicationCommandAutocompleteOption | ApplicationCommandAutocompleteOption
| ApplicationCommandNumericOptionData | ApplicationCommandNumericOptionData
| ApplicationCommandStringOptionData
| ApplicationCommandSubCommandData; | ApplicationCommandSubCommandData;
export type ApplicationCommandOption = export type ApplicationCommandOption =
@ -4545,6 +4561,7 @@ export type ApplicationCommandOption =
| ApplicationCommandChannelOption | ApplicationCommandChannelOption
| ApplicationCommandChoicesOption | ApplicationCommandChoicesOption
| ApplicationCommandNumericOption | ApplicationCommandNumericOption
| ApplicationCommandStringOption
| ApplicationCommandSubCommand; | ApplicationCommandSubCommand;
export interface ApplicationCommandOptionChoiceData { export interface ApplicationCommandOptionChoiceData {
@ -5764,7 +5781,7 @@ export interface MessageActionRowOptions<
export interface MessageActivity { export interface MessageActivity {
partyId: string; partyId: string;
type: number; type: ActivityFlags;
} }
export interface BaseButtonOptions extends BaseMessageComponentOptions { export interface BaseButtonOptions extends BaseMessageComponentOptions {
@ -5917,6 +5934,7 @@ export interface MessageMentionOptions {
export type MessageMentionTypes = 'roles' | 'users' | 'everyone'; export type MessageMentionTypes = 'roles' | 'users' | 'everyone';
export interface MessageOptions { export interface MessageOptions {
activity?: MessageActivity;
tts?: boolean; tts?: boolean;
nonce?: string | number; nonce?: string | number;
content?: string | null; content?: string | null;