Added Max Ticket Count + Timeout

This commit is contained in:
Noah committed 2021-12-18 20:54:01 -06:00
1 parent 1178a0a611
commit 33f7675aac
3 files changed
+65 -16

No files matched your search

+12 -1
View File
@@ -47,9 +47,12 @@ module.exports = new Command({
return interaction.reply({ embeds: [NoPerms] });
}
await interaction.deferReply();
let TicketData = await JSON.parse(
let tickets = await JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
).tickets.find((t) => t.id === interaction.channel.id);
let TicketData = await tickets.tickets.findIndex(
(t) => t.id == ticketChannel.id
);
if (!TicketData) {
const Exists = new Discord.MessageEmbed()
.setTitle("No Ticket Found!")
@@ -87,6 +90,14 @@ module.exports = new Command({
});
}
try {
tickets.tickets[TicketData].open = false;
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(tickets, null, 4),
(err) => {
if (err) console.error(err);
}
);
await interaction.followUp(`**${supportbot.ClosingTicket}**`);
const transcriptEmbed = new Discord.MessageEmbed()
.setTitle(supportbot.TranscriptTitle)
+49 -12
View File
@@ -31,11 +31,29 @@ module.exports = new Command({
permissions: ["SEND_MESSAGES"],
async run(interaction) {
let TicketData = await JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
const { getRole, getChannel, getCategory } = interaction.client;
let reactionUser = interaction.guild.members.cache.get(interaction.user.id);
let User = interaction.guild.members.cache.get(interaction.user.id);
if (
reactionUser.roles.cache.has(
supportbot.MaxAllowedTickets &&
TicketData.tickets.filter((t) => t.user == interaction.user.id && t.open)
.length >= supportbot.MaxAllowedTickets
) {
return interaction.reply({
embeds: [
{
title: "Too Many Tickets!",
description: `You can't have more than ${supportbot.MaxAllowedTickets} open tickets!`,
color: supportbot.WarningColour,
},
],
});
}
if (
User.roles.cache.has(
getRole(supportbot.TicketBlackListRole, interaction.guild).id
)
) {
@@ -49,10 +67,6 @@ module.exports = new Command({
// Ticket ID
let ticketNumberID = await TicketNumberID.pad();
let TicketData = await JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
// Ticket Subject
const TicketSubject =
interaction.options?.getString("reason") || supportbot.NoTicketSubject;
@@ -127,6 +141,7 @@ module.exports = new Command({
user: Author.id,
number: ticketNumberID,
reason: TicketSubject,
open: true,
subUsers: [],
});
fs.writeFileSync(
@@ -232,12 +247,34 @@ module.exports = new Command({
});
const filter = (i) => i.user.id === interaction.user.id;
const collector = await m.awaitMessageComponent({
filter,
max: 1,
componentType: "BUTTON",
time: 60000,
});
let collector;
try {
collector = await m.awaitMessageComponent({
filter,
max: 1,
componentType: "BUTTON",
time: supportbot.Timeout * 60000,
});
} catch (e) {
if (e.code == "INTERACTION_COLLECTOR_ERROR")
try {
let ticket = await TicketData.tickets.findIndex(
(t) => t.id == ticketChannel.id
);
TicketData.tickets[ticket].open = false;
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(TicketData, null, 4),
(err) => {
if (err) console.error(err);
}
);
interaction.user.send(
"Your ticket has timed out. Please open a new one, and select a department."
);
} catch (e) {}
return await ticketChannel.delete();
}
let role;
let title;
if (collector.customId === "Department1") {
+4 -3
View File
@@ -17,7 +17,6 @@ SupportBot_Version: "7.4.0"
# -------------------------
Name: "SupportBot"
# No Prefix, as everything uses the new Slash (/) Commands feature!
Token: "BOT_TOKEN"
# Guild ID Ex: 123456789123456789
Guild: ""
@@ -95,6 +94,8 @@ TranscriptTitle: "Ticket Transcript"
TicketLog_Title: "Ticket Closed"
TicketBlackListMessage: "You are not allowed to open a ticket"
MaxAllowedTickets: 2
TicketSubject: "description"
# "description" will displays the ticket reason within the channel description
# "embed" will displays the ticket reason within the ticket embed
@@ -153,13 +154,13 @@ TicketDept3Emoji: "3️⃣"
TranscriptSavedMessage: "📝 **Transcript Saved!**"
TicketLockMessage: "❌ **Ticket Locked!**"
TicketDeleteMessage: "⚠ **Ticket Deleting!**" # Tickets deleting after 5 seconds by default.
TicketDeleteTime: 5000 # Time must be set in milliseconds.
# --- Departments Config ---
# --- Start ---
TicketDepartments: true
# Delete the ticket if no department selected. TIME IN MINUTES
Timeout: 5
AllowStaff: true
# If set to false users with the "Staff" role will not be able to view tickets
# without a valid department role set below.