mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 20:30:58 -05:00
Revamp interactionCreate file
This commit is contained in:
parent
add41dac8b
commit
b186ea260c
@ -2,12 +2,24 @@ import Discord from 'discord.js';
|
|||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
|
const logPrefix = 'Interaction';
|
||||||
export default class InteractionCreate {
|
export default class InteractionCreate {
|
||||||
static async run(client:TClient, interaction:Discord.BaseInteraction){
|
static async run(client:TClient, interaction:Discord.BaseInteraction){
|
||||||
if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
|
if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
|
||||||
const logPrefix = 'Interaction';
|
const handlers = {
|
||||||
|
isChatInputCommand: this.handleChatInput,
|
||||||
|
isAutocomplete: this.handleAutocomplete,
|
||||||
|
isButton: this.handleButton
|
||||||
|
}
|
||||||
|
|
||||||
if (interaction.isChatInputCommand()){
|
for (const [intType, handler] of Object.entries(handlers)) {
|
||||||
|
if (interaction[intType]()) {
|
||||||
|
handler.call(this, client, interaction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static handleChatInput(client:TClient, interaction:Discord.ChatInputCommandInteraction) {
|
||||||
const commandFile = client.commands.get(interaction.commandName);
|
const commandFile = client.commands.get(interaction.commandName);
|
||||||
Logger.console('log', logPrefix, `${interaction.user.username} used /${interaction.commandName} ${interaction.options.getSubcommandGroup(false) ?? ''} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`.replace(/\s\s+/g, ' ').trim());
|
Logger.console('log', logPrefix, `${interaction.user.username} used /${interaction.commandName} ${interaction.options.getSubcommandGroup(false) ?? ''} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`.replace(/\s\s+/g, ' ').trim());
|
||||||
if (!client.config.botSwitches.commands && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: `I am currently operating in development mode.\nPlease notify <@${client.config.whitelist[0]}> if this is a mistake.`, ephemeral: true});
|
if (!client.config.botSwitches.commands && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: `I am currently operating in development mode.\nPlease notify <@${client.config.whitelist[0]}> if this is a mistake.`, ephemeral: true});
|
||||||
@ -21,13 +33,15 @@ export default class InteractionCreate {
|
|||||||
return interaction.reply('An error occurred while running that command.');
|
return interaction.reply('An error occurred while running that command.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (interaction.isAutocomplete()){
|
}
|
||||||
|
static async handleAutocomplete(client:TClient, interaction:Discord.AutocompleteInteraction) {
|
||||||
try {
|
try {
|
||||||
await client.commands.get(interaction.commandName).command.autocomplete(client, interaction);
|
await client.commands.get(interaction.commandName).command.autocomplete(client, interaction);
|
||||||
} catch (error){
|
} catch (error){
|
||||||
return console.log('An error occurred while running autocomplete:\n', error)
|
return console.log('An error occurred while running autocomplete:\n', error)
|
||||||
}
|
}
|
||||||
} else if (interaction.isButton()){
|
}
|
||||||
|
static handleButton(client:TClient, interaction:Discord.ButtonInteraction<'cached'>) {
|
||||||
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
|
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
|
||||||
const RoleID = interaction.customId.replace('reaction-','');
|
const RoleID = interaction.customId.replace('reaction-','');
|
||||||
|
|
||||||
@ -45,7 +59,6 @@ export default class InteractionCreate {
|
|||||||
Logger.console('log', logPrefix, `Eval embed has been deleted in #${interaction.message.channel.name} by ${interaction.member.displayName}`);
|
Logger.console('log', logPrefix, `Eval embed has been deleted in #${interaction.message.channel.name} by ${interaction.member.displayName}`);
|
||||||
} else Logger.console('log', logPrefix, `Button has been pressed at ${interaction.message.url}`);
|
} else Logger.console('log', logPrefix, `Button has been pressed at ${interaction.message.url}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
static roleConflictHandler(interaction:Discord.ButtonInteraction<'cached'>, role1:Discord.Snowflake, role2:Discord.Snowflake, newRole:Discord.Snowflake) {
|
static roleConflictHandler(interaction:Discord.ButtonInteraction<'cached'>, role1:Discord.Snowflake, role2:Discord.Snowflake, newRole:Discord.Snowflake) {
|
||||||
if (interaction.member.roles.cache.has(role1) && interaction.member.roles.cache.has(role2)) {
|
if (interaction.member.roles.cache.has(role1) && interaction.member.roles.cache.has(role2)) {
|
||||||
const roleToRemove = newRole === role1 ? role2 : role1;
|
const roleToRemove = newRole === role1 ? role2 : role1;
|
||||||
|
@ -61,6 +61,7 @@ export class TagSystemSvc {
|
|||||||
async sendTag(interaction:ChatInputCommandInteraction, tagName:string, targetId:Snowflake) {
|
async sendTag(interaction:ChatInputCommandInteraction, tagName:string, targetId:Snowflake) {
|
||||||
const getTag = await this.model.findOne({where: {tagname: tagName}});
|
const getTag = await this.model.findOne({where: {tagname: tagName}});
|
||||||
const targetMsg = targetId ? `*This tag is directed at ${MessageTool.formatMention(targetId, 'user')}*` : '';
|
const targetMsg = targetId ? `*This tag is directed at ${MessageTool.formatMention(targetId, 'user')}*` : '';
|
||||||
|
const fetchUser = await interaction.guild?.members.fetch(getTag.dataValues.userid);
|
||||||
const ic = interaction.client as TClient;
|
const ic = interaction.client as TClient;
|
||||||
const embedFormat = [
|
const embedFormat = [
|
||||||
new ic.embed().setTitle(tagName).setColor(ic.config.embedColor)
|
new ic.embed().setTitle(tagName).setColor(ic.config.embedColor)
|
||||||
@ -68,7 +69,7 @@ export class TagSystemSvc {
|
|||||||
.setDescription(getTag.dataValues.message)
|
.setDescription(getTag.dataValues.message)
|
||||||
];
|
];
|
||||||
if (getTag.dataValues.embedFlag) return await interaction.reply({content: targetMsg, embeds: embedFormat, allowedMentions: {parse: ['users']}});
|
if (getTag.dataValues.embedFlag) return await interaction.reply({content: targetMsg, embeds: embedFormat, allowedMentions: {parse: ['users']}});
|
||||||
else return await interaction.reply({content: targetMsg+`\n**${getTag.dataValues.message}**`, allowedMentions: {parse: ['users']}});
|
else return await interaction.reply({content: targetMsg+`\n**${getTag.dataValues.message}**\n╰ **${fetchUser.displayName}**`, allowedMentions: {parse: ['users']}});
|
||||||
}
|
}
|
||||||
async modifyTag(tagname:string, message:string) {
|
async modifyTag(tagname:string, message:string) {
|
||||||
CacheServer.delete('tags');
|
CacheServer.delete('tags');
|
||||||
|
Loading…
Reference in New Issue
Block a user