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>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>

2
package-lock.json generated
View File

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

View File

@ -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",

View File

@ -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,
};
}
/**

View File

@ -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);
});
}
//
/**

View File

@ -166,14 +166,16 @@ class MessageButton extends BaseMessageComponent {
/**
* Click the button
* @param {Message} message Discord Message
* @returns {boolean}
* @returns {Promise<Snowflake>}
*/
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;
}
}

View File

@ -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,

View File

@ -214,7 +214,7 @@ class MessageSelectMenu extends BaseMessageComponent {
* Mesage select menu
* @param {Message} message The message this select menu is for
* @param {Array<string>} values The values of the select menu
* @returns {Promise<boolean>}
* @returns {Promise<Snowflake>}
*/
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;
}
}

View File

@ -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
*/
/**

View File

@ -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

View File

@ -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

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;
// Added
public markUnread(): Promise<boolean>;
public clickButton(buttonID: string): Promise<void>;
public selectMenu(menuID: string, options: string[]): Promise<void>;
public selectMenu(options: string[]): Promise<void>;
public clickButton(buttonID: string): Promise<Snowflake>;
public selectMenu(menuID: string, options: string[]): Promise<Snowflake>;
public selectMenu(options: 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 setURL(url: string): this;
public toJSON(): APIButtonComponent;
public click(message: Message): Promise<boolean>;
public click(message: Message): Promise<Snowflake>;
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<boolean>;
public select(message: Message, values: string[]): Promise<Snowflake>;
}
// Todo
@ -4477,7 +4477,7 @@ export interface ApplicationCommandChoicesData extends Omit<BaseApplicationComma
}
export interface ApplicationCommandChoicesOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: Exclude<CommandOptionChoiceResolvableType, ApplicationCommandOptionTypes>;
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<CommandOptionNumericResolvableType, ApplicationCommandOptionTypes>;
type: CommandOptionNumericResolvableType;
minValue?: number;
maxValue?: number;
}
export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption {
type: ApplicationCommandOptionTypes.STRING;
minLength?: number;
maxLength?: number;
}
export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: 'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP;
options?: ApplicationCommandSubCommandData[];
@ -4514,6 +4528,7 @@ export interface ApplicationCommandSubCommandData extends Omit<BaseApplicationCo
| ApplicationCommandChannelOptionData
| ApplicationCommandAutocompleteOption
| ApplicationCommandNumericOptionData
| ApplicationCommandStringOptionData
)[];
}
@ -4537,6 +4552,7 @@ export type ApplicationCommandOptionData =
| ApplicationCommandChoicesData
| ApplicationCommandAutocompleteOption
| ApplicationCommandNumericOptionData
| ApplicationCommandStringOptionData
| ApplicationCommandSubCommandData;
export type ApplicationCommandOption =
@ -4545,6 +4561,7 @@ export type ApplicationCommandOption =
| ApplicationCommandChannelOption
| ApplicationCommandChoicesOption
| ApplicationCommandNumericOption
| ApplicationCommandStringOption
| ApplicationCommandSubCommand;
export interface ApplicationCommandOptionChoiceData {
@ -5764,7 +5781,7 @@ export interface MessageActionRowOptions<
export interface MessageActivity {
partyId: string;
type: number;
type: ActivityFlags;
}
export interface BaseButtonOptions extends BaseMessageComponentOptions {
@ -5917,6 +5934,7 @@ export interface MessageMentionOptions {
export type MessageMentionTypes = 'roles' | 'users' | 'everyone';
export interface MessageOptions {
activity?: MessageActivity;
tts?: boolean;
nonce?: string | number;
content?: string | null;