From 2fd18218e218de1de2a417eca95c8770537651ce Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 16 May 2021 18:37:08 +0100 Subject: [PATCH] "add" command --- src/commands/add.js | 64 ++++++++++++++++++++++++++++++++++++++++ src/commands/settings.js | 6 ++-- src/locales/en-GB.json | 23 ++++++++++++++- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/commands/add.js b/src/commands/add.js index d41e931..9749be8 100644 --- a/src/commands/add.js +++ b/src/commands/add.js @@ -30,5 +30,69 @@ module.exports = class AddCommand extends Command { async execute(message, args) { let settings = await message.guild.settings; const i18n = this.client.i18n.getLocale(settings.locale); + + let ticket = message.mentions.channels.first() ?? message.channel; + let t_row = await this.client.tickets.resolve(ticket.id, message.guild.id); + + if (!t_row) { + return await message.channel.send( + new MessageEmbed() + .setColor(settings.error_colour) + .setTitle(i18n('commands.add.response.not_a_ticket.title')) + .setDescription(i18n('commands.add.response.not_a_ticket.description')) + .setFooter(settings.footer, message.guild.iconURL()) + ); + } + + let member = message.mentions.members.first() ?? message.guild.members.cache.get(args); + + if (!member) { + return await message.channel.send( + new MessageEmbed() + .setColor(settings.error_colour) + .setTitle(i18n('commands.add.response.no_member.title')) + .setDescription(i18n('commands.add.response.no_member.description')) + .setFooter(settings.footer, message.guild.iconURL()) + ); + } + + if (t_row.creator !== message.author.id && !await message.member.isStaff()) { + return await message.channel.send( + new MessageEmbed() + .setColor(settings.error_colour) + .setTitle(i18n('commands.add.response.no_permission.title')) + .setDescription(i18n('commands.add.response.no_permission.description')) + .setFooter(settings.footer, message.guild.iconURL()) + ); + } + + if (message.channel.id !== ticket.id) { + await message.channel.send( + new MessageEmbed() + .setColor(settings.success_colour) + .setAuthor(member.user.username, member.user.displayAvatarURL()) + .setTitle(i18n('commands.add.response.added.title')) + .setDescription(i18n('commands.add.response.added.description', member.toString(), ticket.toString())) + .setFooter(settings.footer, message.guild.iconURL()) + ); + } + + await ticket.send( + new MessageEmbed() + .setColor(settings.colour) + .setAuthor(member.user.username, member.user.displayAvatarURL()) + .setTitle(i18n('ticket.member_added.title')) + .setDescription(i18n('ticket.member_added.description', member.toString(), message.author.toString())) + .setFooter(settings.footer, message.guild.iconURL()) + ); + + await ticket.updateOverwrite(member, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + ATTACH_FILES: true + }, `${message.author.tag} added ${member.user.tag} to the ticket`); + + this.client.log.info(`${message.author.tag} added ${member.user.tag} to ${ticket.id}`); } }; \ No newline at end of file diff --git a/src/commands/settings.js b/src/commands/settings.js index a20a861..156bdbc 100644 --- a/src/commands/settings.js +++ b/src/commands/settings.js @@ -64,7 +64,7 @@ module.exports = class SettingsCommand extends Command { if (cat_channel) { if (cat_channel.name !== c.name) - await cat_channel.setName(c.name, `Tickets category updated by ${message.member.user.tag}`); + await cat_channel.setName(c.name, `Tickets category updated by ${message.author.tag}`); for (let r of c.roles) { await cat_channel.updateOverwrite(r, { @@ -72,7 +72,7 @@ module.exports = class SettingsCommand extends Command { READ_MESSAGE_HISTORY: true, SEND_MESSAGES: true, ATTACH_FILES: true - }, `Tickets category updated by ${message.member.user.tag}`); + }, `Tickets category updated by ${message.author.tag}`); } } @@ -82,7 +82,7 @@ module.exports = class SettingsCommand extends Command { const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES']; let cat_channel = await message.guild.channels.create(c.name, { type: 'category', - reason: `Tickets category created by ${message.member.user.tag}`, + reason: `Tickets category created by ${message.author.tag}`, position: 1, permissionOverwrites: [ ...[ diff --git a/src/locales/en-GB.json b/src/locales/en-GB.json index 6f4927d..1fcefe4 100644 --- a/src/locales/en-GB.json +++ b/src/locales/en-GB.json @@ -37,7 +37,24 @@ }, "description": "Add a member to a ticket", "name": "add", - "response": {} + "response": { + "added": { + "description": "%s has been added to %s.", + "title": "✅ Member added" + }, + "no_member": { + "description": "Please mention the member you want to add.", + "title": "❌ Unknown member" + }, + "no_permission": { + "description": "You are not the creator of this ticket and you are not a staff member; you can't add members to this ticket.", + "title": "❌ Insufficient permission" + }, + "not_a_ticket": { + "description": "Please use this command in the ticket channel, or mention the channel.", + "title": "❌ This isn't a ticket channel" + } + } }, "blacklist": { "aliases": { @@ -353,6 +370,10 @@ "description": "This ticket has been closed: `%s`\nThe channel will be deleted in 5 seconds.", "title": "✅ Ticket closed" }, + "member_added": { + "description": "%s has been added by %s", + "title": "Member added" + }, "released": { "description": "%s has released this ticket.", "title": "✅ Ticket released"