mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-30 15:30:07 +00:00
* Inital Docs * Finish Design * Finish Design * Add FILE Structure' * Add Not Ready Template * Update Template * Add Command Manager and first Command ping * Add Command Manager and first Command ping * Add Embeds Guide & EventManager * INITIAL FINISH: GUIDE * FIX TYPOS, LTS's Review, sidebar_position * Update site/docs/nodejs/getting-started.md Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Fixed Position? Add some comments on template, add changes in review * Add Interaction Handling, Modals * format files * Update site/docs/nodejs/getting-started.md 1 Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Update site/docs/nodejs/CommandHandler/command-manager.md Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Fix Review things * itoh's suggestions The guide looks very very veery good overall I like it. This commit adds my personal style of writing. Please review it 🙏. PS: I hope these are not too many changes .-. * deno fmt Co-authored-by: meister03 <root@_HOSTNAME_> Co-authored-by: ITOH <to@itoh.at> Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
117 lines
4.3 KiB
JavaScript
117 lines
4.3 KiB
JavaScript
const DestructObject = require("./DestructObject");
|
|
const Guild = require("./Guild");
|
|
const Channel = require("./Channel");
|
|
const Constants = {
|
|
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE: 5,
|
|
CHANNEL_MESSAGE_WITH_SOURCE: 4,
|
|
DEFERRED_UPDATE_MESSAGE: 6,
|
|
UPDATE_MESSAGE: 7,
|
|
APPLICATION_COMMAND_AUTOCOMPLETE_RESULT: 8,
|
|
MODAL: 9,
|
|
FLAGS: { EPHEMERAL: 64 },
|
|
INTERACTION_TYPES: {
|
|
CHAT_INPUT: 1,
|
|
APPLICATION_COMMAND: 2,
|
|
CONTEXT_MENU: 2,
|
|
MESSAGE_COMPONENT: 3,
|
|
APPLICATION_COMMAND_AUTOCOMPLETE: 4,
|
|
},
|
|
};
|
|
class Interaction extends DestructObject {
|
|
constructor(client, interaction = {}) {
|
|
super(interaction);
|
|
this.raw = interaction;
|
|
this.client = client;
|
|
|
|
this.guild = new Guild(client, { id: this.guild_id || this.guildId });
|
|
this.channel = new Channel(client, { id: this.channel_id || this.channelId }, {
|
|
internal: true,
|
|
guild: this.guild,
|
|
});
|
|
}
|
|
|
|
isCommand() {
|
|
return this.type === Constants.INTERACTION_TYPES.APPLICATION_COMMAND;
|
|
}
|
|
|
|
// @todo check Context Menu type and Component Type
|
|
isChatInputCommand() {
|
|
return this.type === Constants.INTERACTION_TYPES.CHAT_INPUT;
|
|
}
|
|
isContextMenuCommand() {
|
|
return this.isCommand();
|
|
}
|
|
isAutoComplete() {
|
|
return this.type === Constants.INTERACTION_TYPES.APPLICATION_COMMAND_AUTOCOMPLETE;
|
|
}
|
|
isMessageComponent() {
|
|
return this.type === Constants.INTERACTION_TYPES.MESSAGE_COMPONENT;
|
|
}
|
|
isSelectMenu() {
|
|
return this.type === Constants.INTERACTION_TYPES.MESSAGE_COMPONENT;
|
|
}
|
|
isButton() {
|
|
return this.type === Constants.INTERACTION_TYPES.MESSAGE_COMPONENT;
|
|
}
|
|
|
|
async deferReply(options = {}) {
|
|
if (this.deferred || this.replied) throw new Error("Interaction has been already replied");
|
|
const Payload = { data: {}, type: Constants.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE };
|
|
options.type = 5;
|
|
if (this.ephemeral) options.private = true;
|
|
this.ephemeral = options.ephemeral || false;
|
|
this.deferred = true;
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, options);
|
|
}
|
|
|
|
async deferUpdate(options = {}) {
|
|
if (this.deferred || this.replied) throw new Error("Interaction has been already replied");
|
|
this.deferred = true;
|
|
const Payload = { data: options, type: Constants.DEFERRED_UPDATE_MESSAGE };
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, Payload);
|
|
}
|
|
|
|
async reply(options = {}) {
|
|
if (this.deferred || this.replied) throw new Error("Interaction has been already replied");
|
|
this.ephemeral = options.ephemeral || false;
|
|
if (this.ephemeral) options.private = true;
|
|
this.replied = true;
|
|
const Payload = { data: options, type: Constants.CHANNEL_MESSAGE_WITH_SOURCE };
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, Payload);
|
|
}
|
|
|
|
async popupModal(options = {}) {
|
|
if (this.deferred || this.replied) throw new Error("Interaction has been already replied");
|
|
const Payload = { data: options, type: Constants.MODAL };
|
|
this.replied = true;
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, Payload);
|
|
}
|
|
|
|
async editReply(options = {}) {
|
|
if (!this.deferred && !this.replied) throw new Error("Interaction has not been replied");
|
|
this.replied = true;
|
|
const messageId = this.messageId ? this.messageId : options.messageId;
|
|
return this.client.helpers.editInteractionResponse(this.token, options);
|
|
}
|
|
|
|
async deleteReply(options = {}) {
|
|
if (this.ephemeral) throw new Error("Ephemeral messages cannot be deleted");
|
|
const messageId = this.messageId ? this.messageId : options.messageId;
|
|
return this.client.helpers.deleteInteractionResponse(this.token, messageId);
|
|
}
|
|
|
|
async followUp(options = {}) {
|
|
if (!this.replied || !this.deferred) throw new Error("Interaction has not been replied");
|
|
const Payload = { data: options, type: Constants.CHANNEL_MESSAGE_WITH_SOURCE };
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, Payload);
|
|
}
|
|
|
|
async update(options = {}) {
|
|
if (this.deferred || this.replied) throw new Error("Interaction has been already replied");
|
|
const Payload = { data: options, type: Constants.UPDATE_MESSAGE };
|
|
this.replied = true;
|
|
return this.client.helpers.sendInteractionResponse(this.id, this.token, Payload);
|
|
}
|
|
}
|
|
module.exports = Interaction;
|