mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 22:34:46 +02:00
Rewrite Permission Checks and Validators
This commit is contained in:
@@ -35,14 +35,16 @@ module.exports = class BanCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS')) return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
}
|
||||
if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS'))
|
||||
return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
const modlogs = message.guild.channels.find('name', 'mod_logs');
|
||||
if (!modlogs)
|
||||
return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!modlogs.permissionsFor(this.client.user).hasPermission('EMBED_LINKS'))
|
||||
return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
const { member, reason } = args;
|
||||
if (!member.bannable) return message.say(':x: Error! This member cannot be banned! Perhaps they have a higher role than me?');
|
||||
if (!member.bannable)
|
||||
return message.say(':x: Error! This member cannot be banned! Perhaps they have a higher role than me?');
|
||||
try {
|
||||
await member.ban(7);
|
||||
await message.say(':ok_hand:');
|
||||
@@ -51,7 +53,7 @@ module.exports = class BanCommand extends Command {
|
||||
.setColor(0xFF0000)
|
||||
.setTimestamp()
|
||||
.setDescription(`**Member:** ${member.user.tag} (${member.id})\n**Action:** Ban\n**Reason:** ${reason}`);
|
||||
return message.guild.channels.find('name', 'mod_logs').send({embed});
|
||||
return modlogs.send({embed});
|
||||
} catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
|
||||
@@ -32,14 +32,16 @@ module.exports = class KickCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('KICK_MEMBERS')) return message.say(':x: Error! I don\'t have the Kick Members Permission!');
|
||||
}
|
||||
if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS'))
|
||||
return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
const modlogs = message.guild.channels.find('name', 'mod_logs');
|
||||
if (!modlogs)
|
||||
return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!modlogs.permissionsFor(this.client.user).hasPermission('EMBED_LINKS'))
|
||||
return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
const { member, reason } = args;
|
||||
if (!member.bannable) return message.say(':x: Error! This member cannot be kicked! Perhaps they have a higher role than me?');
|
||||
if (!member.bannable)
|
||||
return message.say(':x: Error! This member cannot be kicked! Perhaps they have a higher role than me?');
|
||||
try {
|
||||
await member.kick();
|
||||
await message.say(':ok_hand:');
|
||||
@@ -48,7 +50,7 @@ module.exports = class KickCommand extends Command {
|
||||
.setColor(0xFFA500)
|
||||
.setTimestamp()
|
||||
.setDescription(`**Member:** ${member.user.tag} (${member.id})\n**Action:** Kick\n**Reason:** ${reason}`);
|
||||
return message.guild.channels.find('name', 'mod_logs').send({embed});
|
||||
return modlogs.send({embed});
|
||||
} catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ module.exports = class LockdownCommand extends Command {
|
||||
prompt: 'Please enter either start or stop.',
|
||||
type: 'string',
|
||||
validate: type => {
|
||||
if (type.toLowerCase() === 'start' || type.toLowerCase() === 'stop') {
|
||||
if (['start', 'stop'].includes(type.toLowerCase()))
|
||||
return true;
|
||||
}
|
||||
return 'Please enter either `start` or `stop`.';
|
||||
},
|
||||
parse: text => text.toLowerCase()
|
||||
@@ -28,10 +27,8 @@ module.exports = class LockdownCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['READ_MESSAGES', 'SEND_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('ADMINISTRATOR')) return message.say(':x: Error! I don\'t have the Administrator permission! This is not given by default, as that\'s quite bad practice. Please give it to me to use the lockdown command!');
|
||||
}
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('ADMINISTRATOR'))
|
||||
return message.say(':x: Error! I don\'t have the Administrator Permission!');
|
||||
const { type } = args;
|
||||
if (type === 'start') {
|
||||
try {
|
||||
@@ -42,8 +39,7 @@ module.exports = class LockdownCommand extends Command {
|
||||
} catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
}
|
||||
if (type === 'stop') {
|
||||
} else if (type === 'stop') {
|
||||
try {
|
||||
await message.channel.overwritePermissions(message.guild.defaultRole, {
|
||||
SEND_MESSAGES: true
|
||||
|
||||
@@ -4,10 +4,6 @@ module.exports = class PruneCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'prune',
|
||||
aliases: [
|
||||
'clean',
|
||||
'bulkdelete'
|
||||
],
|
||||
group: 'moderation',
|
||||
memberName: 'prune',
|
||||
description: 'Deletes a specified number of messages from the current channel, up to 99.',
|
||||
@@ -21,9 +17,8 @@ module.exports = class PruneCommand extends Command {
|
||||
prompt: 'How many messages do you want to delete? Limit of up to 99.',
|
||||
type: 'integer',
|
||||
validate: count => {
|
||||
if (count < 100 && count > 0) {
|
||||
if (count < 100 && count > 0)
|
||||
return true;
|
||||
}
|
||||
return `${count} is not a valid amount of messages. Limit 1-99.`;
|
||||
}
|
||||
}]
|
||||
@@ -35,11 +30,10 @@ module.exports = class PruneCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGE_HISTORY')) return message.say(':x: Error! I don\'t have the Read Message History Permission!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES')) return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
|
||||
}
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGE_HISTORY'))
|
||||
return message.say(':x: Error! I don\'t have the Read Message History Permission!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES'))
|
||||
return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
|
||||
let { count } = args;
|
||||
count = count + 1;
|
||||
try {
|
||||
|
||||
@@ -17,9 +17,8 @@ module.exports = class UnbanCommand extends Command {
|
||||
prompt: 'What member do you want to unban? Please enter the ID of the user.',
|
||||
type: 'string',
|
||||
validate: userID => {
|
||||
if (userID.length === 18) {
|
||||
if (userID.length === 18)
|
||||
return true;
|
||||
}
|
||||
return `${userID} is not a valid ID. Please enter the user you wish to unban's ID.`;
|
||||
}
|
||||
}, {
|
||||
@@ -27,9 +26,8 @@ module.exports = class UnbanCommand extends Command {
|
||||
prompt: 'What do you want to set the reason as?',
|
||||
type: 'string',
|
||||
validate: reason => {
|
||||
if (reason.length < 140) {
|
||||
if (reason.length < 140)
|
||||
return true;
|
||||
}
|
||||
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
|
||||
}
|
||||
}]
|
||||
@@ -41,15 +39,17 @@ module.exports = class UnbanCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS')) return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
}
|
||||
if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS'))
|
||||
return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
const modlogs = message.guild.channels.find('name', 'mod_logs');
|
||||
if (!modlogs)
|
||||
return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!modlogs.permissionsFor(this.client.user).hasPermission('EMBED_LINKS'))
|
||||
return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
const { memberID, reason } = args;
|
||||
const bans = await message.guild.fetchBans();
|
||||
if (!bans.has(memberID)) return message.say(':x: Error! Could not find this user in the bans.');
|
||||
if (!bans.has(memberID))
|
||||
return message.say(':x: Error! Could not find this user in the bans.');
|
||||
const unbanUser = await bans.get(memberID);
|
||||
try {
|
||||
await message.guild.unban(unbanUser);
|
||||
@@ -59,7 +59,7 @@ module.exports = class UnbanCommand extends Command {
|
||||
.setColor(0x00AE86)
|
||||
.setTimestamp()
|
||||
.setDescription(`**Member:** ${unbanUser.tag} (${unbanUser.id})\n**Action:** Unban\n**Reason:** ${reason}`);
|
||||
return message.guild.channels.find('name', 'mod_logs').send({embed});
|
||||
return modlogs.send({embed});
|
||||
} catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
|
||||
@@ -18,9 +18,8 @@ module.exports = class WarnCommand extends Command {
|
||||
prompt: 'What do you want to set the reason as?',
|
||||
type: 'string',
|
||||
validate: reason => {
|
||||
if (reason.length < 140) {
|
||||
if (reason.length < 140)
|
||||
return true;
|
||||
}
|
||||
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
|
||||
}
|
||||
}]
|
||||
@@ -32,12 +31,14 @@ module.exports = class WarnCommand extends Command {
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
}
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('BAN_MEMBERS'))
|
||||
return message.say(':x: Error! I don\'t have the Ban Members Permission!');
|
||||
const modlogs = message.guild.channels.find('name', 'mod_logs');
|
||||
if (!modlogs)
|
||||
return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
if (!modlogs.permissionsFor(this.client.user).hasPermission('EMBED_LINKS'))
|
||||
return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
const { member, reason } = args;
|
||||
if (!message.guild.channels.exists('name', 'mod_logs')) return message.say(':x: Error! Could not find the mod_logs channel! Please create it!');
|
||||
try {
|
||||
await message.say(':ok_hand:');
|
||||
const embed = new RichEmbed()
|
||||
@@ -45,7 +46,7 @@ module.exports = class WarnCommand extends Command {
|
||||
.setColor(0xFFFF00)
|
||||
.setTimestamp()
|
||||
.setDescription(`**Member:** ${member.user.tag} (${member.id})\n**Action:** Warn\n**Reason:** ${reason}`);
|
||||
return message.guild.channels.find('name', 'mod_logs').send({embed});
|
||||
return modlogs.send({embed});
|
||||
} catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user