2021-10-28 18:03:51 -05:00
|
|
|
// SupportBot | Emerald Services
|
|
|
|
|
// Ticket Remove Command
|
|
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const yaml = require("js-yaml");
|
|
|
|
|
const supportbot = yaml.load(
|
|
|
|
|
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
|
|
|
|
);
|
|
|
|
|
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
|
|
|
|
|
|
|
|
|
|
const Command = require("../Structures/Command.js");
|
|
|
|
|
|
|
|
|
|
async function asyncForEach(array, callback) {
|
|
|
|
|
for (let index = 0; index < array.length; index++) {
|
|
|
|
|
await callback(array[index], index, array);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = new Command({
|
|
|
|
|
name: cmdconfig.TicketRemove,
|
|
|
|
|
description: cmdconfig.TicketRemoveDesc,
|
|
|
|
|
slashCommandOptions: [
|
|
|
|
|
{
|
|
|
|
|
name: "user",
|
|
|
|
|
description: "User to remove",
|
|
|
|
|
type: "USER",
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
permission: "SEND_MESSAGES",
|
|
|
|
|
|
|
|
|
|
async run(interaction) {
|
2021-12-15 00:19:40 -06:00
|
|
|
const { getRole, getChannel, getCategory } = interaction.client;
|
|
|
|
|
let Staff = await getRole(supportbot.Staff, interaction.guild);
|
|
|
|
|
let Admin = await getRole(supportbot.Admin, interaction.guild);
|
|
|
|
|
if (!Staff || !Admin)
|
2021-11-21 18:42:18 -06:00
|
|
|
return interaction.reply(
|
|
|
|
|
"Some roles seem to be missing!\nPlease check for errors when starting the bot."
|
2021-10-28 18:03:51 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const NoPerms = new Discord.MessageEmbed()
|
|
|
|
|
.setTitle("Invalid Permissions!")
|
|
|
|
|
.setDescription(
|
|
|
|
|
`${supportbot.IncorrectPerms}\n\nRole Required: \`${supportbot.Staff}\` or \`${supportbot.Admin}\``
|
|
|
|
|
)
|
|
|
|
|
.setColor(supportbot.WarningColour);
|
|
|
|
|
|
|
|
|
|
if (
|
2021-12-15 00:19:40 -06:00
|
|
|
!interaction.member.roles.cache.has(Staff.id) ||
|
|
|
|
|
!interaction.member.roles.cache.has(Admin.id)
|
2021-12-14 18:04:38 -06:00
|
|
|
)
|
|
|
|
|
return interaction.reply({ embeds: [NoPerms] });
|
|
|
|
|
let TicketData = await JSON.parse(
|
|
|
|
|
fs.readFileSync("./Data/TicketData.json", "utf8")
|
|
|
|
|
);
|
|
|
|
|
let ticket = await TicketData.tickets.findIndex(
|
|
|
|
|
(t) => t.id == interaction.channel.id
|
|
|
|
|
);
|
|
|
|
|
if (ticket == -1) {
|
|
|
|
|
const Exists = new Discord.MessageEmbed()
|
|
|
|
|
.setTitle("No Ticket Found!")
|
|
|
|
|
.setDescription(`${supportbot.NoValidTicket}`)
|
|
|
|
|
.setColor(supportbot.WarningColour);
|
|
|
|
|
return interaction.reply({ embeds: [Exists] });
|
|
|
|
|
}
|
2021-10-28 18:03:51 -05:00
|
|
|
|
2021-12-14 18:04:38 -06:00
|
|
|
let uMember = interaction.options.getUser("user");
|
|
|
|
|
const UserNotExist = new Discord.MessageEmbed()
|
|
|
|
|
.setTitle("User Not Found!")
|
|
|
|
|
.setDescription(
|
|
|
|
|
`${supportbot.UserNotFound}\n\nTry Again:\`/${cmdconfig.TicketRemove} <user#0000>\``
|
|
|
|
|
)
|
|
|
|
|
.setColor(supportbot.ErrorColour);
|
2021-10-28 18:03:51 -05:00
|
|
|
|
2021-12-14 18:04:38 -06:00
|
|
|
if (!uMember) return interaction.reply({ embeds: [UserNotExist] });
|
2021-10-28 18:03:51 -05:00
|
|
|
|
2021-12-14 18:04:38 -06:00
|
|
|
interaction.channel.permissionOverwrites.edit(uMember.id, {
|
|
|
|
|
VIEW_CHANNEL: false,
|
|
|
|
|
});
|
2021-10-28 18:03:51 -05:00
|
|
|
|
2021-12-14 18:04:38 -06:00
|
|
|
const Complete = new Discord.MessageEmbed()
|
|
|
|
|
.setTitle("User Removed!")
|
|
|
|
|
.setDescription(supportbot.RemovedUser.replace(/%user%/g, uMember.id))
|
|
|
|
|
.setTimestamp()
|
|
|
|
|
.setColor(supportbot.EmbedColour);
|
|
|
|
|
interaction.reply({ embeds: [Complete] });
|
|
|
|
|
TicketData.tickets[ticket].subUsers = TicketData.tickets[
|
|
|
|
|
ticket
|
|
|
|
|
].subUsers.filter((u) => u != uMember.id);
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
"./Data/TicketData.json",
|
|
|
|
|
JSON.stringify(TicketData, null, 4),
|
|
|
|
|
(err) => {
|
|
|
|
|
if (err) console.error(err);
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-10-28 18:03:51 -05:00
|
|
|
},
|
|
|
|
|
});
|