"topic" command

This commit is contained in:
Isaac 2021-05-16 21:31:23 +01:00
parent 82473db65c
commit ceac5801fd
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
3 changed files with 73 additions and 11 deletions

View File

@ -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}`);
}
};

View File

@ -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"

View File

@ -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())
);
}