Files
SupportBot-Dashboard/Events/interactionCreate.js
T

139 lines
4.2 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");
2022-08-12 01:35:36 +01:00
2021-10-27 19:30:10 -05:00
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
2022-08-12 01:35:36 +01:00
const cmdconfig = yaml.load(
fs.readFileSync("./Configs/commands.yml", "utf8")
);
const msgconfig = yaml.load(
fs.readFileSync("./Configs/messages.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) => {
2022-07-22 13:19:05 +01:00
if (interaction.type == Discord.InteractionType.ApplicationCommand) {
2021-10-24 22:48:25 +01:00
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
2022-07-22 13:19:05 +01:00
const NotValid = new Discord.EmbedBuilder()
2021-10-24 22:48:25 +01:00
.setDescription(`:x: \`Invalid Command\` `)
2022-08-12 01:35:36 +01:00
.setColor(supportbot.Embed.Colours.Error);
2021-10-24 22:48:25 +01:00
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
2022-07-22 13:19:05 +01:00
const ValidPerms = new Discord.EmbedBuilder()
2021-10-24 22:48:25 +01:00
.setDescription(
2022-07-22 13:19:05 +01:00
"> :x: `Invalid Permissions` Do you have the correct permissions to execute this command?"
2021-10-24 22:48:25 +01:00
)
2022-08-12 01:35:36 +01:00
.setColor(supportbot.Embed.Colours.Error);
2021-10-24 22:48:25 +01:00
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 {
2022-07-23 07:50:12 +01:00
const cmd = client.commands.get(cmdconfig.OpenTicket.Command);
2021-10-24 22:48:25 +01:00
if (!cmd) return;
cmd.run(interaction);
} catch (error) {
console.error(error);
}
}
if (interaction.customId === "ticketclose") {
2021-11-23 18:08:45 -06:00
try {
2022-07-23 07:50:12 +01:00
const cmd = client.commands.get(cmdconfig.CloseTicket.Command);
2021-11-23 18:08:45 -06:00
if (!cmd) return;
cmd.run(interaction);
} catch (error) {
console.error(error);
2021-10-24 22:48:25 +01:00
}
}
if (interaction.customId === "ticketlock") {
2022-08-12 01:35:36 +01:00
if (interaction.channel.name.startsWith(supportbot.Ticket.Channel)) {
2021-10-24 22:48:25 +01:00
interaction.message.fetch();
let Admin =
interaction.guild.roles.cache.find(
2022-08-12 01:35:36 +01:00
(AdminUser) => AdminUser.name === supportbot.Roles.StaffMember.Admin
2021-10-24 22:48:25 +01:00
) ||
interaction.guild.roles.cache.find(
2022-08-12 01:35:36 +01:00
(AdminUser) => AdminUser.id === supportbot.Roles.StaffMember.Admin
2021-10-24 22:48:25 +01:00
);
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(
2022-08-12 01:35:36 +01:00
(c) => c.name === supportbot.Ticket.LockTicketCategory
2021-10-24 22:48:25 +01:00
) ||
interaction.guild.channels.cache.find(
2022-08-12 01:35:36 +01:00
(c) => c.id === supportbot.Ticket.LockTicketCategory
2021-10-24 22:48:25 +01:00
);
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
2022-07-22 13:19:05 +01:00
const ticketDeleteButton = new Discord.ButtonBuilder()
2021-10-24 22:48:25 +01:00
.setCustomId("ticketclose")
.setLabel("Close")
2022-08-12 01:35:36 +01:00
.setStyle(supportbot.Buttons.Tickets.DeleteStyle)
.setEmoji(supportbot.Buttons.Tickets.DeleteEmoji);
2021-10-24 22:48:25 +01:00
2022-07-22 13:19:05 +01:00
const row = new Discord.ActionRowBuilder().addComponents(
2021-10-24 22:48:25 +01:00
ticketDeleteButton
);
2022-07-22 13:19:05 +01:00
const ArchiveEmbed = new Discord.EmbedBuilder()
2021-10-24 22:48:25 +01:00
.setTitle("Archived")
.setDescription(`Archived ${interaction.channel.name}`)
2022-08-12 01:35:36 +01:00
.setColor(supportbot.Embed.Colours.Success);
2021-10-24 22:48:25 +01:00
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] });
}
}
}
});