"add" command

This commit is contained in:
Isaac 2021-05-16 18:37:08 +01:00
parent 002240d777
commit 2fd18218e2
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
3 changed files with 89 additions and 4 deletions

View File

@ -30,5 +30,69 @@ module.exports = class AddCommand extends Command {
async execute(message, args) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); 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}`);
} }
}; };

View File

@ -64,7 +64,7 @@ module.exports = class SettingsCommand extends Command {
if (cat_channel) { if (cat_channel) {
if (cat_channel.name !== c.name) 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) { for (let r of c.roles) {
await cat_channel.updateOverwrite(r, { await cat_channel.updateOverwrite(r, {
@ -72,7 +72,7 @@ module.exports = class SettingsCommand extends Command {
READ_MESSAGE_HISTORY: true, READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true, SEND_MESSAGES: true,
ATTACH_FILES: 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']; const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
let cat_channel = await message.guild.channels.create(c.name, { let cat_channel = await message.guild.channels.create(c.name, {
type: 'category', type: 'category',
reason: `Tickets category created by ${message.member.user.tag}`, reason: `Tickets category created by ${message.author.tag}`,
position: 1, position: 1,
permissionOverwrites: [ permissionOverwrites: [
...[ ...[

View File

@ -37,7 +37,24 @@
}, },
"description": "Add a member to a ticket", "description": "Add a member to a ticket",
"name": "add", "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": { "blacklist": {
"aliases": { "aliases": {
@ -353,6 +370,10 @@
"description": "This ticket has been closed: `%s`\nThe channel will be deleted in 5 seconds.", "description": "This ticket has been closed: `%s`\nThe channel will be deleted in 5 seconds.",
"title": "✅ Ticket closed" "title": "✅ Ticket closed"
}, },
"member_added": {
"description": "%s has been added by %s",
"title": "Member added"
},
"released": { "released": {
"description": "%s has released this ticket.", "description": "%s has released this ticket.",
"title": "✅ Ticket released" "title": "✅ Ticket released"