From ceac5801fd71db5d2b26495feb6a8de080335de1 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 16 May 2021 21:31:23 +0100 Subject: [PATCH] "topic" command --- src/commands/topic.js | 53 ++++++++++++++++++++++++++++++++++ src/locales/en-GB.json | 23 ++++++++++----- src/modules/tickets/manager.js | 8 ++--- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/commands/topic.js b/src/commands/topic.js index 69e5bef..36a1f15 100644 --- a/src/commands/topic.js +++ b/src/commands/topic.js @@ -24,5 +24,58 @@ module.exports = class TopicCommand extends Command { async execute(message, args) { let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); + + let t_row = await this.client.db.models.Ticket.findOne({ + where: { + id: message.channel.id + } + }); + + if (!t_row) { + return await message.channel.send( + new MessageEmbed() + .setColor(settings.error_colour) + .setTitle(i18n('commands.topic.response.not_a_ticket.title')) + .setDescription(i18n('commands.topic.response.not_a_ticket.description')) + .setFooter(settings.footer, message.guild.iconURL()) + ); + } + + await t_row.update({ + topic: this.client.cryptr.encrypt(args) + }); + + let member = await message.guild.members.fetch(t_row.creator); + /* await */message.channel.setTopic(`${member} | ${args}`, { reason: 'User updated ticket topic' }); + + let cat_row = await this.client.db.models.Category.findOne({ + where: { + id: t_row.category + } + }); + let description = cat_row.opening_message + .replace(/{+\s?(user)?name\s?}+/gi, member.displayName) + .replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString()); + let opening_message = await message.channel.messages.fetch(t_row.opening_message); + + await opening_message.edit( + new MessageEmbed() + .setColor(settings.colour) + .setAuthor(member.user.username, member.user.displayAvatarURL()) + .setDescription(description) + .addField(i18n('ticket.opening_message.fields.topic'), args) + .setFooter(settings.footer, message.guild.iconURL()) + ); + + await message.channel.send( + new MessageEmbed() + .setColor(settings.success_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(i18n('commands.topic.response.changed.title')) + .setDescription(i18n('commands.topic.response.changed.description')) + .setFooter(settings.footer, message.guild.iconURL()) + ); + + this.client.log.info(`${message.author.tag} changed the topic of ${message.channel.id}`); } }; \ No newline at end of file diff --git a/src/locales/en-GB.json b/src/locales/en-GB.json index 7681819..e1da46d 100644 --- a/src/locales/en-GB.json +++ b/src/locales/en-GB.json @@ -206,12 +206,6 @@ }, "description": "Create a new ticket", "name": "new", - "opening_message": { - "fields": { - "topic": "Topic" - } - }, - "questions": "Please answer the following questions:\n\n%s", "response": { "created": { "description": "Your ticket has been created: %s.", @@ -350,7 +344,16 @@ }, "description": "Change the topic of the ticket", "name": "topic", - "response": {} + "response": { + "changed": { + "description": "This ticket's topic has been changed.", + "title": "✅ Topic changed" + }, + "not_a_ticket": { + "description": "Please use this command in the ticket channel you want to change the topic of.", + "title": "❌ This isn't a ticket channel" + } + } } }, "command_execution_error": { @@ -395,6 +398,12 @@ "description": "%s has been removed by %s", "title": "Member removed" }, + "opening_message": { + "fields": { + "topic": "Topic" + } + }, + "questions": "Please answer the following questions:\n\n%s", "released": { "description": "%s has released this ticket.", "title": "✅ Ticket released" diff --git a/src/modules/tickets/manager.js b/src/modules/tickets/manager.js index 026603b..b7982b7 100644 --- a/src/modules/tickets/manager.js +++ b/src/modules/tickets/manager.js @@ -110,7 +110,7 @@ module.exports = class TicketManager extends EventEmitter { .setDescription(description) .setFooter(settings.footer, guild.iconURL()); - if (topic) embed.addField(i18n('commands.new.opening_message.fields.topic'), topic); + if (topic) embed.addField(i18n('ticket.opening_message.fields.topic'), topic); let sent = await t_channel.send(member.user.toString(), embed); await sent.pin({ reason: 'Ticket opening message' }); @@ -164,7 +164,7 @@ module.exports = class TicketManager extends EventEmitter { .setColor(settings.colour) .setAuthor(member.user.username, member.user.displayAvatarURL()) .setDescription(description) - .addField(i18n('commands.new.opening_message.fields.topic'), topic) + .addField(i18n('ticket.opening_message.fields.topic'), topic) .setFooter(settings.footer, guild.iconURL()) ); await message.react('✅'); @@ -179,7 +179,7 @@ module.exports = class TicketManager extends EventEmitter { await t_channel.send( new MessageEmbed() .setColor(settings.colour) - .setDescription(i18n('commands.new.questions', questions)) + .setDescription(i18n('ticket.questions', questions)) .setFooter(settings.footer, guild.iconURL()) ); } @@ -189,7 +189,7 @@ module.exports = class TicketManager extends EventEmitter { await t_channel.send( new MessageEmbed() .setColor(settings.colour) - .setDescription(i18n('commands.new.questions', questions)) + .setDescription(i18n('ticket.questions', questions)) .setFooter(settings.footer, guild.iconURL()) ); }