Files
SupportBot/Events/interactionCreate.js
T

131 lines
4.0 KiB
JavaScript
Raw Normal View History

2021-10-24 22:48:25 +01:00
// SupportBot | Emerald Services
// Interaction Create Event
const fs = require("fs");
const Discord = require("discord.js");
const yaml = require("js-yaml");
2021-10-27 19:30:10 -05:00
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
2021-10-24 22:48:25 +01:00
const Event = require("../Structures/Event.js");
2021-11-10 21:41:12 -06:00
module.exports = new Event("interactionCreate", async (client, interaction) => {
2021-10-24 22:48:25 +01:00
if (interaction.isCommand()) {
const command = client.commands.find(
2022-02-04 17:49:02 -06:00
(cmd) => cmd.name.toLowerCase() === interaction.commandName
2021-10-24 22:48:25 +01:00
);
2021-11-23 18:08:45 -06:00
if (interaction.user.bot || !interaction.guild) return;
2021-10-24 22:48:25 +01:00
const NotValid = new Discord.MessageEmbed()
.setDescription(`:x: \`Invalid Command\` `)
.setColor(supportbot.ErrorColour);
if (!command)
return interaction.reply({
embeds: [NotValid],
});
2022-02-04 17:49:02 -06:00
const permission = interaction.member.permissions.has(command.permissions);
2021-10-24 22:48:25 +01:00
const ValidPerms = new Discord.MessageEmbed()
.setDescription(
":x: `Invalid Permissions` Do you have the correct permissions to execute this command?"
)
.setColor(supportbot.ErrorColour);
if (!permission)
return interaction.reply({
embeds: [ValidPerms],
});
command.run(interaction);
}
if (interaction.isButton()) {
2022-02-04 17:49:02 -06:00
if (
interaction.customId === "openticket" ||
interaction.customId.includes("department-")
) {
2021-10-24 22:48:25 +01:00
try {
const cmd = client.commands.get(cmdconfig.OpenTicket);
if (!cmd) return;
cmd.run(interaction);
} catch (error) {
console.error(error);
}
}
if (interaction.customId === "ticketclose") {
2021-11-23 18:08:45 -06:00
try {
const cmd = client.commands.get(cmdconfig.CloseTicket);
if (!cmd) return;
cmd.run(interaction);
} catch (error) {
console.error(error);
2021-10-24 22:48:25 +01:00
}
}
if (interaction.customId === "ticketlock") {
2021-10-27 19:48:00 -05:00
if (interaction.channel.name.startsWith(`${supportbot.TicketPrefix}`)) {
2021-10-24 22:48:25 +01:00
interaction.message.fetch();
let Admin =
interaction.guild.roles.cache.find(
(AdminUser) => AdminUser.name === supportbot.Admin
) ||
interaction.guild.roles.cache.find(
(AdminUser) => AdminUser.id === supportbot.Admin
);
2021-11-10 21:41:12 -06:00
if (!interaction.member.roles.cache.has(Admin.id)) {
return await interaction.reply({
content: "You don't have permission to do that.",
ephemeral: true,
});
}
2021-10-24 22:48:25 +01:00
let all = interaction.channel.permissionOverwrites.cache;
let parent =
interaction.guild.channels.cache.find(
(c) => c.name === `${supportbot.LockTicketCategory}`
) ||
interaction.guild.channels.cache.find(
(c) => c.id === `${supportbot.LockTicketCategory}`
);
if (parent) {
2022-02-04 17:49:02 -06:00
await interaction.channel.setParent(parent.id);
2021-10-24 22:48:25 +01:00
}
all.forEach((perm) => {
interaction.channel.permissionOverwrites.delete(perm.id);
});
2022-02-04 17:49:02 -06:00
await interaction.channel.permissionOverwrites.create(Admin.id, {
2021-10-24 22:48:25 +01:00
VIEW_CHANNEL: true,
});
2022-02-04 17:49:02 -06:00
await interaction.channel.permissionOverwrites.create(
interaction.guild.id,
{
VIEW_CHANNEL: false,
}
);
2021-10-24 22:48:25 +01:00
const ticketDeleteButton = new Discord.MessageButton()
.setCustomId("ticketclose")
.setLabel("Close")
.setStyle(supportbot.TicketDeleteColour)
.setEmoji(supportbot.TicketDeleteEmoji);
const row = new Discord.MessageActionRow().addComponents(
ticketDeleteButton
);
const ArchiveEmbed = new Discord.MessageEmbed()
.setTitle("Archived")
.setDescription(`Archived ${interaction.channel.name}`)
.setColor(`${supportbot.SuccessColour}`);
2021-11-10 21:41:12 -06:00
interaction.reply({ embeds: [ArchiveEmbed] });
2021-10-24 22:48:25 +01:00
interaction.message.edit({ components: [row] });
}
}
}
});