From e7d9d3558a420bab6941d571d5b9fca38cf40f40 Mon Sep 17 00:00:00 2001 From: o5pxels Date: Sun, 20 Dec 2020 19:49:41 -0600 Subject: [PATCH 1/7] Options for confirm on close/delete on/off for new --- src/commands/close.js | 203 +++++++++++++++++-------------- src/commands/delete.js | 161 ++++++++++++------------ src/commands/new.js | 6 +- src/events/messageReactionAdd.js | 2 +- user/config.js | 15 ++- 5 files changed, 207 insertions(+), 180 deletions(-) diff --git a/src/commands/close.js b/src/commands/close.js index eadb383..c859380 100644 --- a/src/commands/close.js +++ b/src/commands/close.js @@ -82,46 +82,115 @@ module.exports = { let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log) ? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` : ''; - - let confirm = await message.channel.send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('❔ Are you sure?') - .setDescription(`${pre}\n**React with ✅ to confirm.**`) - .setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL()) - ); - - await confirm.react('✅'); - - const collector = confirm.createReactionCollector( - (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { - time: 15000 - }); - - collector.on('collect', async () => { - let users = []; - if (channel.id !== message.channel.id) { - channel.send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('**Ticket closed**') - .setDescription(`Ticket closed by ${message.author}`) - .setFooter(guild.name, guild.iconURL()) - ); - } - - confirm.reactions.removeAll(); - confirm.edit( + if (config.commands.close.confirmation) { + let confirm = await message.channel.send( new MessageEmbed() .setColor(config.colour) .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(`✅ **Ticket ${ticket.id} closed**`) - .setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.') - .setFooter(guild.name, guild.iconURL()) + .setTitle('❔ Are you sure?') + .setDescription(`${pre}\n**React with ✅ to confirm.**`) + .setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL()) ); + await confirm.react('✅'); + + const collector = confirm.createReactionCollector( + (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { + time: 15000 + }); + + collector.on('collect', async () => { + let users = []; + if (channel.id !== message.channel.id) { + channel.send( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('**Ticket closed**') + .setDescription(`Ticket closed by ${message.author}`) + .setFooter(guild.name, guild.iconURL()) + ); + } + + confirm.reactions.removeAll(); + confirm.edit( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(`✅ **Ticket ${ticket.id} closed**`) + .setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.') + .setFooter(guild.name, guild.iconURL()) + ); + success = true; + closeTicket(); + if (config.commands.close.send_transcripts) { + sendTranscript(); + } + }); + + + collector.on('end', () => { + if (!success) { + confirm.reactions.removeAll(); + confirm.edit( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('❌ **Expired**') + .setDescription('You took too long to react; confirmation failed.') + .setFooter(guild.name, guild.iconURL())); + + message.delete({ + timeout: 10000 + }) + .then(() => confirm.delete()); + } + }); + } else { + success = true; + closeTicket(); + } + + async function closeTicket() { + // update database + ticket.update({ + open: false + }, { + where: { + channel: channel.id + } + }); + + // delete messages and channel + setTimeout(() => { + channel.delete(); + if (channel.id !== message.channel.id) + message.delete() + .then(() => confirm.delete()); + }, 5000); + + log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`); + + if (config.logs.discord.enabled) { + let embed = new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(`Ticket ${ticket.id} closed`) + .addField('Creator', `<@${ticket.creator}>`, true) + .addField('Closed by', message.author, true) + .setFooter(guild.name, guild.iconURL()) + .setTimestamp(); + + if (users.length > 1) + embed.addField('Members', users.map(u => `<@${u}>`).join('\n')); + + client.channels.cache.get(config.logs.discord.channel).send(embed); + } + } + if (config.commands.close.send_transcripts) { + sendTranscript(); + } + async function sendTranscript() { if (config.transcripts.text.enabled || config.transcripts.web.enabled) { let u = await client.users.fetch(ticket.creator); @@ -160,71 +229,17 @@ module.exports = { } res.embed = embed; - try { - dm.send(res); - if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res); + if (success) { + dm.send(res); + if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res); + } } catch (e) { message.channel.send('❌ Couldn\'t send DM or transcript log message'); } } } - - // update database - success = true; - ticket.update({ - open: false - }, { - where: { - channel: channel.id - } - }); - - // delete messages and channel - setTimeout(() => { - channel.delete(); - if (channel.id !== message.channel.id) - message.delete() - .then(() => confirm.delete()); - }, 5000); - - log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`); - - if (config.logs.discord.enabled) { - let embed = new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(`Ticket ${ticket.id} closed`) - .addField('Creator', `<@${ticket.creator}>`, true) - .addField('Closed by', message.author, true) - .setFooter(guild.name, guild.iconURL()) - .setTimestamp(); - - if (users.length > 1) - embed.addField('Members', users.map(u => `<@${u}>`).join('\n')); - - client.channels.cache.get(config.logs.discord.channel).send(embed); - } - }); - - - collector.on('end', () => { - if (!success) { - confirm.reactions.removeAll(); - confirm.edit( - new MessageEmbed() - .setColor(config.err_colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('❌ **Expired**') - .setDescription('You took too long to react; confirmation failed.') - .setFooter(guild.name, guild.iconURL())); - - message.delete({ - timeout: 10000 - }) - .then(() => confirm.delete()); - } - }); + } } }; diff --git a/src/commands/delete.js b/src/commands/delete.js index 42d236a..8be94f9 100644 --- a/src/commands/delete.js +++ b/src/commands/delete.js @@ -64,7 +64,7 @@ module.exports = { } } - if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) return channel.send( new MessageEmbed() .setColor(config.err_colour) @@ -75,103 +75,100 @@ module.exports = { .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) .setFooter(guild.name, guild.iconURL()) ); - + let success; - - let confirm = await message.channel.send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('❔ Are you sure?') - .setDescription( - `:warning: This action is **irreversible**, the ticket will be completely removed from the database. - You will **not** be able to view a transcript/archive of the channel later. - Use the \`close\` command instead if you don't want this behaviour.\n**React with ✅ to confirm.**`) - .setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL()) - ); - - await confirm.react('✅'); - - const collector = confirm.createReactionCollector( - (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { - time: 15000 - }); - - collector.on('collect', async () => { - if (channel.id !== message.channel.id) - channel.send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('**Ticket deleted**') - .setDescription(`Ticket deleted by ${message.author}`) - .setFooter(guild.name, guild.iconURL()) - ); - - confirm.reactions.removeAll(); - confirm.edit( + if (config.commands.delete.confirmation) { + let confirm = await message.channel.send( new MessageEmbed() .setColor(config.colour) .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(`✅ **Ticket ${ticket.id} deleted**`) - .setDescription('The channel will be automatically deleted in a few seconds.') - .setFooter(guild.name, guild.iconURL()) + .setTitle('❔ Are you sure?') + .setDescription( + `:warning: This action is **irreversible**, the ticket will be completely removed from the database. + You will **not** be able to view a transcript/archive of the channel later. + Use the \`close\` command instead if you don't want this behaviour.\n**React with ✅ to confirm.**`) + .setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL()) ); - let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), - raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), - json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`); + await confirm.react('✅'); - if (fs.existsSync(txt)) fs.unlinkSync(txt); - if (fs.existsSync(raw)) fs.unlinkSync(raw); - if (fs.existsSync(json)) fs.unlinkSync(json); + const collector = confirm.createReactionCollector( + (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { + time: 15000 + }); - // update database - success = true; - ticket.destroy(); // remove ticket from database - - // delete messages and channel - setTimeout(() => { - channel.delete(); + collector.on('collect', async () => { if (channel.id !== message.channel.id) - message.delete() - .then(() => confirm.delete()); - }, 5000); + channel.send( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('**Ticket deleted**') + .setDescription(`Ticket deleted by ${message.author}`) + .setFooter(guild.name, guild.iconURL()) + ); - log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`); - - if (config.logs.discord.enabled) { - client.channels.cache.get(config.logs.discord.channel).send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('Ticket deleted') - .addField('Creator', `<@${ticket.creator}>`, true) - .addField('Deleted by', message.author, true) - .setFooter(guild.name, guild.iconURL()) - .setTimestamp() - ); - } - }); - - - collector.on('end', () => { - if (!success) { confirm.reactions.removeAll(); confirm.edit( new MessageEmbed() - .setColor(config.err_colour) + .setColor(config.colour) .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('❌ **Expired**') - .setDescription('You took too long to react; confirmation failed.') - .setFooter(guild.name, guild.iconURL())); + .setTitle(`✅ **Ticket ${ticket.id} deleted**`) + .setDescription('The channel will be automatically deleted in a few seconds.') + .setFooter(guild.name, guild.iconURL()) + ); + }); + collector.on('end', () => { + if (!success) { + confirm.reactions.removeAll(); + confirm.edit( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('❌ **Expired**') + .setDescription('You took too long to react; confirmation failed.') + .setFooter(guild.name, guild.iconURL())); - message.delete({ - timeout: 10000 - }) + message.delete({ + timeout: 10000 + }) + .then(() => confirm.delete()); + } + }); + } + let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), + raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), + json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`); + + if (fs.existsSync(txt)) fs.unlinkSync(txt); + if (fs.existsSync(raw)) fs.unlinkSync(raw); + if (fs.existsSync(json)) fs.unlinkSync(json); + + // update database + success = true; + ticket.destroy(); // remove ticket from database + + // delete messages and channel + setTimeout(() => { + channel.delete(); + if (channel.id !== message.channel.id) + message.delete() .then(() => confirm.delete()); - } - }); + }, 5000); + log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`); + + if (config.logs.discord.enabled) { + client.channels.cache.get(config.logs.discord.channel).send( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('Ticket deleted') + .addField('Creator', `<@${ticket.creator}>`, true) + .addField('Deleted by', message.author, true) + .setFooter(guild.name, guild.iconURL()) + .setTimestamp() + ); + } } }; \ No newline at end of file diff --git a/src/commands/new.js b/src/commands/new.js index b4a545f..2e76bc2 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -23,7 +23,8 @@ module.exports = { const guild = client.guilds.cache.get(config.guild); const supportRole = guild.roles.cache.get(config.staff_role); - if (!supportRole) + if (config.commands.new.enabled) { + if (!supportRole) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) @@ -75,7 +76,7 @@ module.exports = { .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setFooter(guild.name, guild.iconURL()) ); - else if (topic.length < 1) topic = 'No topic given'; + else if (topic.length < 1) topic = config.default_topic; let ticket = await Ticket.create({ channel: '', @@ -192,5 +193,6 @@ module.exports = { }).catch(log.error); + } }, }; diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index 80da3e7..250006f 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -89,7 +89,7 @@ module.exports = { } } - let topic = 'No topic given (created via panel)'; + let topic = config.default_topic; let ticket = await Ticket.create({ channel: '', diff --git a/user/config.js b/user/config.js index 67623e5..f5fff1e 100644 --- a/user/config.js +++ b/user/config.js @@ -47,10 +47,23 @@ module.exports = { colour: '#009999', err_colour: 'RED', cooldown: 3, - + default_topic: 'Support Needed', guild: '', // ID of your guild (REQUIRED) staff_role: '', // ID of your Support Team role (REQUIRED) + commands: { + close: { + confirmation: true, + send_transcripts: true + }, + delete: { + confirmation: true + }, + new: { + enabled: true + }, + }, + tickets: { category: '', // ID of your tickets category (REQUIRED) send_img: true, From 641f13169e8862dea9383b6e3fffdb6a1278646e Mon Sep 17 00:00:00 2001 From: o5pxels Date: Sun, 20 Dec 2020 20:14:35 -0600 Subject: [PATCH 2/7] Implement placeholder for default_topic --- src/commands/new.js | 9 +++++++-- src/events/messageReactionAdd.js | 8 +++++++- user/config.js | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/commands/new.js b/src/commands/new.js index 2e76bc2..0a81bb4 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -67,7 +67,7 @@ module.exports = { let topic = args.join(' '); - if (topic.length > 256) + if (topic.length > 256) { return message.channel.send( new MessageEmbed() .setColor(config.err_colour) @@ -76,7 +76,12 @@ module.exports = { .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setFooter(guild.name, guild.iconURL()) ); - else if (topic.length < 1) topic = config.default_topic; + } else if (/^[a-zA-Z0-9]+$/.test(config.default_topic)) { + topic = config.default_topic; + } + else if (topic.length < 1) { + topic = 'No topic given'; + } let ticket = await Ticket.create({ channel: '', diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index 250006f..e43cf79 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -89,7 +89,13 @@ module.exports = { } } - let topic = config.default_topic; + + if (/^[a-zA-Z0-9]+$/.test(config.default_topic)) { + topic = config.default_topic; + } else { + topic = 'No topic given (created via panel)'; + } + let ticket = await Ticket.create({ channel: '', diff --git a/user/config.js b/user/config.js index f5fff1e..f0cf424 100644 --- a/user/config.js +++ b/user/config.js @@ -47,7 +47,7 @@ module.exports = { colour: '#009999', err_colour: 'RED', cooldown: 3, - default_topic: 'Support Needed', + default_topic: '', guild: '', // ID of your guild (REQUIRED) staff_role: '', // ID of your Support Team role (REQUIRED) From cc23cb6fa987bb21ca2e8a003e5b5509f93ec8b5 Mon Sep 17 00:00:00 2001 From: o5pxels Date: Sun, 20 Dec 2020 23:01:26 -0600 Subject: [PATCH 3/7] Fix regex expression test on default_topic --- src/events/messageReactionAdd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index e43cf79..8418d38 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -90,7 +90,7 @@ module.exports = { } - if (/^[a-zA-Z0-9]+$/.test(config.default_topic)) { + if (!/("|'|`)("|'|`)/.test(config.default_topic)) { topic = config.default_topic; } else { topic = 'No topic given (created via panel)'; From c194b74d239b9310ccea63163683023a69c5705a Mon Sep 17 00:00:00 2001 From: o5pxels Date: Sun, 20 Dec 2020 23:02:57 -0600 Subject: [PATCH 4/7] Fix regex test in the new command --- src/commands/new.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/new.js b/src/commands/new.js index 0a81bb4..4ba559f 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -76,7 +76,7 @@ module.exports = { .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setFooter(guild.name, guild.iconURL()) ); - } else if (/^[a-zA-Z0-9]+$/.test(config.default_topic)) { + } if (!/("|'|`)("|'|`)/.test(config.default_topic)) { topic = config.default_topic; } else if (topic.length < 1) { From 29b7665279b69605da264ad9c5bc11b40e26e72c Mon Sep 17 00:00:00 2001 From: o5pxels Date: Sun, 20 Dec 2020 23:03:44 -0600 Subject: [PATCH 5/7] Add else to fix topic testing --- src/commands/new.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/new.js b/src/commands/new.js index 4ba559f..5e157f1 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -76,7 +76,7 @@ module.exports = { .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setFooter(guild.name, guild.iconURL()) ); - } if (!/("|'|`)("|'|`)/.test(config.default_topic)) { + } else if (!/("|'|`)("|'|`)/.test(config.default_topic)) { topic = config.default_topic; } else if (topic.length < 1) { From 234d1cd511869ed5cd018789d930afe98b5c58e7 Mon Sep 17 00:00:00 2001 From: o5pxels Date: Mon, 21 Dec 2020 10:38:40 -0600 Subject: [PATCH 6/7] Rearrange default_topic in config, remove new test --- src/commands/new.js | 4 +--- src/events/messageReactionAdd.js | 4 +--- user/config.js | 5 ++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/commands/new.js b/src/commands/new.js index 5e157f1..f5795c9 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -76,11 +76,9 @@ module.exports = { .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setFooter(guild.name, guild.iconURL()) ); - } else if (!/("|'|`)("|'|`)/.test(config.default_topic)) { - topic = config.default_topic; } else if (topic.length < 1) { - topic = 'No topic given'; + topic = config.tickets.default_topic.command; } let ticket = await Ticket.create({ diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index 8418d38..707df13 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -89,14 +89,12 @@ module.exports = { } } - if (!/("|'|`)("|'|`)/.test(config.default_topic)) { - topic = config.default_topic; + topic = config.tickets.default_topic.panel; } else { topic = 'No topic given (created via panel)'; } - let ticket = await Ticket.create({ channel: '', creator: u.id, diff --git a/user/config.js b/user/config.js index f0cf424..0813b3a 100644 --- a/user/config.js +++ b/user/config.js @@ -47,7 +47,6 @@ module.exports = { colour: '#009999', err_colour: 'RED', cooldown: 3, - default_topic: '', guild: '', // ID of your guild (REQUIRED) staff_role: '', // ID of your Support Team role (REQUIRED) @@ -65,6 +64,10 @@ module.exports = { }, tickets: { + default_topic: { + command: 'No topic given', + panel: 'Created via panel' + }, category: '', // ID of your tickets category (REQUIRED) send_img: true, ping: 'here', From ae1d24236f35fd96275c44f04a17dcc42921632a Mon Sep 17 00:00:00 2001 From: "Isaac (eartharoid)" Date: Fri, 1 Jan 2021 15:41:12 +0000 Subject: [PATCH 7/7] Improvements and fixes --- src/commands/close.js | 117 +++++++++++++++---------------- src/commands/delete.js | 79 ++++++++++++--------- src/commands/help.js | 2 +- src/commands/new.js | 12 +++- src/events/messageReactionAdd.js | 6 +- user/config.js | 30 ++++---- 6 files changed, 128 insertions(+), 118 deletions(-) diff --git a/src/commands/close.js b/src/commands/close.js index c859380..79ecdc8 100644 --- a/src/commands/close.js +++ b/src/commands/close.js @@ -78,11 +78,13 @@ module.exports = { .setFooter(guild.name, guild.iconURL()) ); - let success; - let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log) - ? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` - : ''; + if (config.commands.close.confirmation) { + let success; + let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log) + ? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` + : ''; + let confirm = await message.channel.send( new MessageEmbed() .setColor(config.colour) @@ -96,11 +98,10 @@ module.exports = { const collector = confirm.createReactionCollector( (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { - time: 15000 - }); + time: 15000 + }); collector.on('collect', async () => { - let users = []; if (channel.id !== message.channel.id) { channel.send( new MessageEmbed() @@ -121,11 +122,15 @@ module.exports = { .setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.') .setFooter(guild.name, guild.iconURL()) ); + + + if (channel.id !== message.channel.id) + message.delete({ + timeout: 5000 + }).then(() => confirm.delete()); + success = true; - closeTicket(); - if (config.commands.close.send_transcripts) { - sendTranscript(); - } + close(); }); @@ -142,58 +147,19 @@ module.exports = { message.delete({ timeout: 10000 - }) - .then(() => confirm.delete()); + }).then(() => confirm.delete()); } }); } else { - success = true; - closeTicket(); + close(); } - async function closeTicket() { - // update database - ticket.update({ - open: false - }, { - where: { - channel: channel.id - } - }); + + async function close () { + let users = []; - // delete messages and channel - setTimeout(() => { - channel.delete(); - if (channel.id !== message.channel.id) - message.delete() - .then(() => confirm.delete()); - }, 5000); - - log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`); - - if (config.logs.discord.enabled) { - let embed = new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(`Ticket ${ticket.id} closed`) - .addField('Creator', `<@${ticket.creator}>`, true) - .addField('Closed by', message.author, true) - .setFooter(guild.name, guild.iconURL()) - .setTimestamp(); - - if (users.length > 1) - embed.addField('Members', users.map(u => `<@${u}>`).join('\n')); - - client.channels.cache.get(config.logs.discord.channel).send(embed); - } - } - if (config.commands.close.send_transcripts) { - sendTranscript(); - } - async function sendTranscript() { if (config.transcripts.text.enabled || config.transcripts.web.enabled) { let u = await client.users.fetch(ticket.creator); - if (u) { let dm; try { @@ -202,7 +168,6 @@ module.exports = { log.warn(`Could not create DM channel with ${u.tag}`); } - let res = {}; const embed = new MessageEmbed() .setColor(config.colour) @@ -229,17 +194,47 @@ module.exports = { } res.embed = embed; + try { - if (success) { - dm.send(res); - if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res); - } + if (config.commands.close.send_transcripts) dm.send(res); + if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res); } catch (e) { message.channel.send('❌ Couldn\'t send DM or transcript log message'); } } } - } + // update database + ticket.update({ + open: false + }, { + where: { + channel: channel.id + } + }); + + // delete channel + channel.delete({ + timeout: 5000 + }); + + log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`); + + if (config.logs.discord.enabled) { + let embed = new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(`Ticket ${ticket.id} closed`) + .addField('Creator', `<@${ticket.creator}>`, true) + .addField('Closed by', message.author, true) + .setFooter(guild.name, guild.iconURL()) + .setTimestamp(); + + if (users.length > 1) + embed.addField('Members', users.map(u => `<@${u}>`).join('\n')); + + client.channels.cache.get(config.logs.discord.channel).send(embed); + } + } } }; diff --git a/src/commands/delete.js b/src/commands/delete.js index 8be94f9..a5347cd 100644 --- a/src/commands/delete.js +++ b/src/commands/delete.js @@ -76,8 +76,9 @@ module.exports = { .setFooter(guild.name, guild.iconURL()) ); - let success; + if (config.commands.delete.confirmation) { + let success; let confirm = await message.channel.send( new MessageEmbed() .setColor(config.colour) @@ -94,8 +95,8 @@ module.exports = { const collector = confirm.createReactionCollector( (r, u) => r.emoji.name === '✅' && u.id === message.author.id, { - time: 15000 - }); + time: 15000 + }); collector.on('collect', async () => { if (channel.id !== message.channel.id) @@ -117,7 +118,16 @@ module.exports = { .setDescription('The channel will be automatically deleted in a few seconds.') .setFooter(guild.name, guild.iconURL()) ); + + if (channel.id !== message.channel.id) + message.delete({ + timeout: 5000 + }).then(() => confirm.delete()); + + success = true; + del(); }); + collector.on('end', () => { if (!success) { confirm.reactions.removeAll(); @@ -131,44 +141,47 @@ module.exports = { message.delete({ timeout: 10000 - }) - .then(() => confirm.delete()); + }).then(() => confirm.delete()); } }); + } else { + del(); } - let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), - raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), - json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`); - if (fs.existsSync(txt)) fs.unlinkSync(txt); - if (fs.existsSync(raw)) fs.unlinkSync(raw); - if (fs.existsSync(json)) fs.unlinkSync(json); - // update database - success = true; - ticket.destroy(); // remove ticket from database + async function del () { + let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), + raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), + json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`); - // delete messages and channel - setTimeout(() => { - channel.delete(); - if (channel.id !== message.channel.id) - message.delete() - .then(() => confirm.delete()); - }, 5000); + if (fs.existsSync(txt)) fs.unlinkSync(txt); + if (fs.existsSync(raw)) fs.unlinkSync(raw); + if (fs.existsSync(json)) fs.unlinkSync(json); - log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`); + // update database + ticket.destroy(); // remove ticket from database - if (config.logs.discord.enabled) { - client.channels.cache.get(config.logs.discord.channel).send( - new MessageEmbed() - .setColor(config.colour) - .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle('Ticket deleted') - .addField('Creator', `<@${ticket.creator}>`, true) - .addField('Deleted by', message.author, true) - .setFooter(guild.name, guild.iconURL()) - .setTimestamp() - ); + // channel + channel.delete({ + timeout: 5000 + }); + + + log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`); + + if (config.logs.discord.enabled) { + client.channels.cache.get(config.logs.discord.channel).send( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('Ticket deleted') + .addField('Creator', `<@${ticket.creator}>`, true) + .addField('Deleted by', message.author, true) + .setFooter(guild.name, guild.iconURL()) + .setTimestamp() + ); + } } + } }; \ No newline at end of file diff --git a/src/commands/help.js b/src/commands/help.js index 8366065..ff27d12 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -26,7 +26,7 @@ module.exports = { let cmds = []; for (let command of commands) { - if (command.hide) continue; + if (command.hide || command.disabled) continue; if (command.permission && !message.member.hasPermission(command.permission)) continue; let desc = command.description; diff --git a/src/commands/new.js b/src/commands/new.js index f5795c9..b3170d3 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -11,6 +11,7 @@ const log = new Logger(); const { MessageEmbed } = require('discord.js'); const fs = require('fs'); const { join } = require('path'); +const config = require(join(__dirname, '../../user/', require('../').config)); module.exports = { name: 'new', @@ -19,12 +20,17 @@ module.exports = { aliases: ['ticket', 'open'], example: 'new my server won\'t start', args: false, + disabled: !config.commands.new.enabled, async execute(client, message, args, {config, Ticket}) { + + if (!config.commands.new.enabled) return; // stop if the command is disabled + + const guild = client.guilds.cache.get(config.guild); const supportRole = guild.roles.cache.get(config.staff_role); - if (config.commands.new.enabled) { - if (!supportRole) + + if (!supportRole) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) @@ -196,6 +202,6 @@ module.exports = { }).catch(log.error); - } + }, }; diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index 707df13..3ca336a 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -89,11 +89,7 @@ module.exports = { } } - if (!/("|'|`)("|'|`)/.test(config.default_topic)) { - topic = config.tickets.default_topic.panel; - } else { - topic = 'No topic given (created via panel)'; - } + let topic = config.tickets.default_topic.command; let ticket = await Ticket.create({ channel: '', diff --git a/user/config.js b/user/config.js index 0813b3a..7e182e5 100644 --- a/user/config.js +++ b/user/config.js @@ -50,6 +50,21 @@ module.exports = { guild: '', // ID of your guild (REQUIRED) staff_role: '', // ID of your Support Team role (REQUIRED) + tickets: { + category: '', // ID of your tickets category (REQUIRED) + send_img: true, + ping: 'here', + text: `Hello there, {{ tag }}! + A member of staff will assist you shortly. + In the mean time, please describe your issue in as much detail as possible! :)`, + pin: false, + max: 3, + default_topic: { + command: 'No topic given', + panel: 'Created via panel' + } + }, + commands: { close: { confirmation: true, @@ -63,21 +78,6 @@ module.exports = { }, }, - tickets: { - default_topic: { - command: 'No topic given', - panel: 'Created via panel' - }, - category: '', // ID of your tickets category (REQUIRED) - send_img: true, - ping: 'here', - text: `Hello there, {{ tag }}! - A member of staff will assist you shortly. - In the mean time, please describe your issue in as much detail as possible! :)`, - pin: false, - max: 3 - }, - transcripts: { text: { enabled: true,