Bot permissions check

This commit is contained in:
Isaac 2021-05-03 15:01:46 +01:00
parent b7b039af6e
commit 25980b7db3
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
12 changed files with 67 additions and 31 deletions

View File

@ -155,7 +155,7 @@
"description": "Během provádění příkazu došlo k neočekávané chybě.\nPožádejte správce serveru, aby zkontroloval výstup konzole / log pro více detailů."
},
"message_will_be_deleted_in": "Tato zpráva bude smazána za %d sekund",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "Na provedení tohoto příkazu nemáte dostatečné oprávnění:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -1,5 +1,9 @@
{
"bot": {
"missing_permissions": {
"title": "⚠️",
"description": "Discord Tickets requires the following permissions:\n%s"
},
"version": "[Discord Tickets](%s) v%s by [eartharoid](%s)"
},
"cmd_usage": {
@ -155,7 +159,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "Eror tak terduga ketika mengeksekusi command.\nTolong tanya seorang adminstrator untuk memeriksa console atau log konsol untuk detail."
},
"message_will_be_deleted_in": "Pesan ini akan dihapus dalam %d detik",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "Anda tidak memiliki izin yang diperlukan untuk menggunakan command ini:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "Det oppstod en uventet feil under kommandoutførelsen.\nBe en administrator kontrollere konsollutdataene/-loggene for mer informasjon."
},
"message_will_be_deleted_in": "Denne meldingen vil bli slettet om %d sekunder",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "Du har ikke tillatelsene som kreves for å bruke denne kommandoen:\n%s"
},

View File

@ -155,7 +155,7 @@
"description": "An unexpected error occurred during command execution.\nPlease ask an administrator to check the console output / logs for details."
},
"message_will_be_deleted_in": "This message will be deleted in %d seconds",
"missing_perms": {
"missing_permissions": {
"title": "❌",
"description": "You do not have the permissions required to use this command:\n%s"
},

View File

@ -61,6 +61,8 @@ module.exports = class CommandManager {
* @param {Message} message - Command message
*/
async handle(message) {
if (message.author.bot) return; // ignore self and other bots
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
@ -98,6 +100,56 @@ module.exports = class CommandManager {
const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name));
if (!cmd) return;
let bot_permissions = message.guild.me.permissionsIn(message.channel);
let required_bot_permissions = [
'ADD_REACTIONS',
'ATTACH_FILES',
'EMBED_LINKS',
'MANAGE_CHANNELS',
'MANAGE_MESSAGES',
'READ_MESSAGE_HISTORY',
'SEND_MESSAGES',
];
if (!bot_permissions.has(required_bot_permissions)) {
let perms = required_bot_permissions.map(p => `\`${p}\``).join(', ');
if (bot_permissions.has(['EMBED_LINKS', 'SEND_MESSAGES'])) {
await message.channel.send(
new MessageEmbed()
.setColor('ORANGE')
.setTitle(i18n('bot.missing_permissions.title'))
.setDescription(i18n('bot.missing_permissions.description', perms))
);
} else if (bot_permissions.has('SEND_MESSAGES')) {
await message.channel.send('⚠️ ' + i18n('bot.missing_permissions.description', perms));
} else if (bot_permissions.has('ADD_REACTIONS')) {
await message.react('⚠️');
} else {
this.client.log.warn('Unable to respond to command due to missing permissions');
}
return;
}
const missing_permissions = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
if (missing_permissions) {
let perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('missing_permissions.title'))
.setDescription(i18n('missing_permissions.description', perms))
);
}
if (cmd.staff_only && await message.member.isStaff() === false) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('staff_only.title'))
.setDescription(i18n('staff_only.description'))
);
}
let args = raw_args;
if (cmd.process_args) {
@ -116,26 +168,6 @@ module.exports = class CommandManager {
return await cmd.sendUsage(message.channel, cmd_name);
}
}
const missing_perms = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
if (missing_perms) {
let perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('missing_perms.title'))
.setDescription(i18n('missing_perms.description', perms))
);
}
if (cmd.staff_only && await message.member.isStaff() === false) {
return await message.channel.send(
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('staff_only.title'))
.setDescription(i18n('staff_only.description'))
);
}
try {
this.client.log.commands(`Executing "${cmd.name}" command (invoked by ${message.author.tag})`);