1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 16:30:59 -04:00
Daggerbot-TS/src/events/interactionCreate.ts

49 lines
3.4 KiB
TypeScript
Raw Normal View History

import Discord from 'discord.js';
2023-04-14 06:47:58 -04:00
import TClient from '../client.js';
import Logger from '../helpers/Logger.js';
2023-12-24 10:21:40 -05:00
export default class InteractionCreate {
static async run(client:TClient, interaction:Discord.BaseInteraction){
2023-02-13 02:37:23 -05:00
if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
2023-12-24 10:21:40 -05:00
const logPrefix = 'Interaction';
2023-02-13 02:37:23 -05:00
if (interaction.isChatInputCommand()){
const commandFile = client.commands.get(interaction.commandName);
2023-12-24 10:21:40 -05:00
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});
2023-02-13 02:37:23 -05:00
if (commandFile){
try{
2023-10-06 01:54:27 -04:00
commandFile.command.run(client, interaction);
commandFile.command.autocomplete ? commandFile.command.autocomplete(interaction) : undefined;
2023-03-05 05:04:10 -05:00
commandFile.uses ? commandFile.uses++ : commandFile.uses = 1;
2023-02-13 02:37:23 -05:00
} catch (error){
2023-10-06 01:54:27 -04:00
console.log(`An error occurred while running command "${interaction.commandName} ${interaction.options.getSubcommandGroup(false) ?? ''} ${interaction.options.getSubcommand(false) ?? ''}"`, error, error.stack);
return interaction.reply('An error occurred while running that command.');
}
2023-02-13 02:37:23 -05:00
}
2023-08-14 10:36:29 -04:00
} else if (interaction.isAutocomplete()){
try {
2023-10-06 01:54:27 -04:00
await client.commands.get(interaction.commandName).command.autocomplete(client, interaction);
2023-08-14 10:36:29 -04:00
} catch (error){
return console.log('An error occurred while running autocomplete:\n', error)
}
2023-05-02 17:35:43 -04:00
} else if (interaction.isButton()){
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
const RoleID = interaction.customId.replace('reaction-','');
2023-12-24 10:21:40 -05:00
let roleConflictMsg = 'Cannot have both roles! - Button Role';
const MFFarm1 = '1149139369433776269';
const MFFarm2 = '1149139583729160325';
if (interaction.member.roles.cache.has(MFFarm1) && RoleID === MFFarm2) interaction.member.roles.remove(MFFarm1, roleConflictMsg);
else if (interaction.member.roles.cache.has(MFFarm2) && RoleID === MFFarm1) interaction.member.roles.remove(MFFarm2, roleConflictMsg);
2023-12-24 10:21:40 -05:00
if (interaction.member.roles.cache.has(RoleID)) interaction.member.roles.remove(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been removed from <@&${RoleID}>`, ephemeral: true}));
else interaction.member.roles.add(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true}));
} else if (interaction.customId.includes('deleteEvalEmbed')) {
if (!client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'You are not whitelisted, therefore you cannot delete this message.', ephemeral: true});
interaction.message.delete();
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}`);
}
2023-02-13 02:37:23 -05:00
}
2023-03-05 05:04:10 -05:00
}