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

@@ -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 = []) {