chore(release): version

This commit is contained in:
March 7th
2022-06-15 23:07:24 +07:00
parent d2a766ef3b
commit 007f0ef3b1
13 changed files with 173 additions and 72 deletions

View File

@@ -0,0 +1,23 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
/**
* @typedef {object} AutocompleteResponseChoice
* @property {string} name The name of the choice
* @property {string} value The value of the choice
*/
/**
* @typedef {object} AutocompleteResponse
* @property {Snowflake} [nonce] Snowflake of the data
* @property {Array<AutocompleteResponseChoice>} [choices] Array of choices
*/
/**
* Emitted when receiving a response from Discord
* @event Client#applicationCommandAutocompleteResponse
* @param {AutocompleteResponse} data Data
* @deprecated Test only
*/
client.emit(Events.DEBUG, data);
};

View File

@@ -2,5 +2,10 @@
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
/**
* Emitted whenever client user send interaction and success
* @event Client#interactionSuccess
* @param {InteractionResponseBody} data data
*/
client.emit(Events.INTERACTION_SUCCESS, data);
};

View File

@@ -241,6 +241,76 @@ class MessageManager extends CachedManager {
for (const message of data) messages.set(message.id, this._add(message, cache));
return messages;
}
/**
* @typedef {object} MessageSearchOptions
* @property {Array<Snowflake>} [author] An array of author IDs to filter by
* @property {Array<Snowflake>} [mentions] An array of user IDs (mentioned) to filter by
* @property {string} [content] A messageContent to filter by
* @property {Snowflake} [maxId] The maximum Message ID to filter by
* @property {Snowflake} [minId] The minimum Message ID to filter by
* @property {Array<Snowflake>} [channel] An array of channel IDs to filter by
* @property {boolean} [pinned] Whether to filter by pinned messages
* @property {Array<string>} [has] Message has: `link`, `embed`, `file`, `video`, `image`, or `sound`
*/
/**
* @typedef {object} MessageSearchResult
* @property {Collection<Snowflake, Message>} messages A collection of found messages
* @property {number} total The total number of messages that match the search criteria
*/
/**
* Search Messages in the channel.
* @param {MessageSearchOptions} options Performs a search within the channel.
* @returns {MessageSearchResult}
*/
async search(options = {}) {
let { author, content, mentions, has, maxId, minId, channelId, pinned } = Object.assign(
{
author: [],
content: '',
mentions: [],
has: [],
maxId: null,
minId: null,
channelId: [],
pinned: false,
},
options,
);
const stringQuery = [];
const result = new Collection();
let data;
if (author.length > 0) stringQuery.push(author.map(id => `author_id=${id}`).join('&'));
if (content && content.length) stringQuery.push(`content=${encodeURIComponent(content)}`);
if (mentions.length > 0) stringQuery.push(mentions.map(id => `mentions=${id}`).join('&'));
has = has.filter(v => ['link', 'embed', 'file', 'video', 'image', 'sound', 'sticker'].includes(v));
if (has.length > 0) stringQuery.push(has.map(v => `has=${v}`).join('&'));
if (maxId) stringQuery.push(`max_id=${maxId}`);
if (minId) stringQuery.push(`min_id=${minId}`);
if (this.channel.guildId && channelId.length > 0) {
stringQuery.push(channelId.map(id => `channel_id=${id}`).join('&'));
}
if (typeof pinned == 'boolean') stringQuery.push(`pinned=${pinned}`);
// Main
if (!stringQuery.length) {
return {
messages: result,
total: 0,
};
}
if (this.channel.guildId) {
data = await this.client.api.guilds[this.channel.guildId].messages[`search?${stringQuery.join('&')}`].get();
} else {
data = await this.client.api.channels[this.channel.id].messages[`search?${stringQuery.join('&')}`].get();
}
for await (const message of data.messages) result.set(message[0].id, new Message(this.client, message[0]));
return {
messages: result,
total: data.total_results,
};
}
}
module.exports = MessageManager;

View File

@@ -1,16 +1,17 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const Discord = require('discord.js-selfbot-v13');
const CachedManager = require('./CachedManager');
const { Error } = require('../errors');
const { lazy } = require('../util/Util');
const User = lazy(() => require('../structures/User'));
/**
* Manages API methods for users who reacted to a reaction and stores their cache.
* @extends {CachedManager}
*/
class ReactionUserManager extends CachedManager {
constructor(reaction, iterable) {
super(reaction.client, Discord.User, iterable);
super(reaction.client, User(), iterable);
/**
* The reaction that this manager belongs to

View File

@@ -1,12 +1,13 @@
'use strict';
const { Message } = require('discord.js');
const Base = require('./Base');
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
const MessageAttachment = require('../structures/MessageAttachment');
const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const { lazy } = require('../util/Util');
const Message = lazy(() => require('../structures/Message').Message);
/**
* Represents an application command.
* @extends {Base}
@@ -506,7 +507,7 @@ class ApplicationCommand extends Base {
* Send Slash command to channel
* @param {Message} message Discord Message
* @param {Array<string>} options The options to Slash Command
* @returns {Promise<boolean>}
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
* @example
* const botID = '12345678987654321'
* const user = await client.users.fetch(botID);
@@ -516,7 +517,7 @@ class ApplicationCommand extends Base {
*/
async sendSlashCommand(message, options = []) {
// Check Options
if (!(message instanceof Message)) {
if (!(message instanceof Message())) {
throw new TypeError('The message must be a Discord.Message');
}
if (!Array.isArray(options)) {
@@ -630,6 +631,7 @@ class ApplicationCommand extends Base {
if (subCommandCheck && subCommand?.options && subCommand?.options[i]?.required) {
throw new Error('Value required missing');
}
let nonce = SnowflakeUtil.generate();
const data = {
type: 2, // Slash command, context menu
// Type: 4: Auto-complete
@@ -646,7 +648,7 @@ class ApplicationCommand extends Base {
options: option_,
attachments: attachments,
},
nonce: SnowflakeUtil.generate(),
nonce,
};
await this.client.api.interactions
.post({
@@ -654,19 +656,21 @@ class ApplicationCommand extends Base {
files: attachmentsBuffer,
})
.catch(async () => {
nonce = SnowflakeUtil.generate();
data.data.guild_id = message.guildId;
data.nonce = nonce;
await this.client.api.interactions.post({
body: data,
files: attachmentsBuffer,
});
});
return true;
return nonce;
}
/**
* Message Context Menu
* @param {Message} message Discord Message
* @param {boolean} sendFromMessage nothing .-. not used
* @returns {Promise<boolean>}
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
* @example
* const botID = '12345678987654321'
* const user = await client.users.fetch(botID);
@@ -675,10 +679,11 @@ class ApplicationCommand extends Base {
* await command.sendContextMenu(messsage);
*/
async sendContextMenu(message, sendFromMessage = false) {
if (!sendFromMessage && !(message instanceof Message)) {
if (!sendFromMessage && !(message instanceof Message())) {
throw new TypeError('The message must be a Discord.Message');
}
if (this.type == 'CHAT_INPUT') return false;
const nonce = SnowflakeUtil.generate();
await this.client.api.interactions.post({
body: {
type: 2, // Slash command, context menu
@@ -694,10 +699,10 @@ class ApplicationCommand extends Base {
type: ApplicationCommandTypes[this.type],
target_id: ApplicationCommandTypes[this.type] == 1 ? message.author.id : message.id,
},
nonce: SnowflakeUtil.generate(),
nonce,
},
});
return true;
return nonce;
}
}

View File

@@ -1076,7 +1076,7 @@ class Message extends Base {
* Send context Menu v2
* @param {Snowflake} botId Bot id
* @param {string} commandName Command name in Context Menu
* @returns {Promise<void>}
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
*/
async contextMenu(botId, commandName) {
if (!botId) throw new Error('Bot ID is required');
@@ -1112,7 +1112,8 @@ class Message extends Base {
.join(', ')}`,
);
}
return contextCMD.sendContextMenu(this, true);
const nonce = await contextCMD.sendContextMenu(this, true);
return nonce;
}
}

View File

@@ -138,7 +138,7 @@ class Modal {
* @param {Snowflake} guildId GuildID of the guild to send the modal to
* @param {Snowflake} channelId ChannelID of the channel to send the modal to
* @param {...ModalReplyData} data Data to send with the modal
* @returns {Promise<boolean>}
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
* @example
* // With Event
* client.on('interactionModalCreate', modal => {
@@ -199,19 +199,20 @@ class Modal {
// Get Object
const dataFinal = this.toJSON();
delete dataFinal.title;
const nonce = SnowflakeUtil.generate();
const postData = {
type: 5, // Modal
application_id: this.application.id,
guild_id: guildId,
channel_id: channelId,
data: dataFinal,
nonce: SnowflakeUtil.generate(),
nonce,
session_id: this.client.session_id,
};
await this.client.api.interactions.post({
data: postData,
});
return true;
return nonce;
}
}

View File

@@ -1,7 +1,6 @@
'use strict';
/* eslint-disable import/order */
const { Message } = require('discord.js');
const MessageCollector = require('../MessageCollector');
const MessagePayload = require('../MessagePayload');
const SnowflakeUtil = require('../../util/SnowflakeUtil');
@@ -9,6 +8,8 @@ const { Collection } = require('@discordjs/collection');
const { InteractionTypes } = require('../../util/Constants');
const { TypeError, Error } = require('../../errors');
const InteractionCollector = require('../InteractionCollector');
const { lazy } = require('../../util/Util');
const Message = lazy(() => require('../Message').Message);
/**
* Interface for classes that have text-channel-like features.
@@ -394,7 +395,7 @@ class TextBasedChannel {
* @param {Snowflake} botId Bot Id (Supports application ID - not bot)
* @param {string} commandName Command name
* @param {...?string} args Command arguments
* @returns {Promise<pending>}
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
*/
async sendSlash(botId, commandName, ...args) {
if (!botId) throw new Error('Bot ID is required');
@@ -432,8 +433,8 @@ class TextBasedChannel {
)}`,
);
}
return commandTarget.sendSlashCommand(
new Message(this.client, {
const nonce = await commandTarget.sendSlashCommand(
new (Message())(this.client, {
channel_id: this.id,
guild_id: this.guild?.id || null,
author: this.client.user,
@@ -442,6 +443,7 @@ class TextBasedChannel {
}),
args && args.length ? args : [],
);
return nonce;
}
static applyToClass(structure, full = false, ignore = []) {

View File

@@ -625,6 +625,19 @@ class Util extends null {
if (features.includes('THREE_DAY_THREAD_ARCHIVE')) return 4320;
return 1440;
}
/**
* Lazily evaluates a callback function (yea it's v14 :yay:)
* @param {Function} cb The callback to lazily evaluate
* @returns {Function}
* @example
* const User = lazy(() => require('./User'));
* const user = new (User())(client, data);
*/
static lazy(cb) {
let defaultValue;
return () => (defaultValue ??= cb());
}
}
module.exports = Util;