mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Rewrite Permission Checks and Validators
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const memecodes = require('./memecodes.json');
|
||||
const memecodes = require('./memecodes');
|
||||
|
||||
module.exports = class MemeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'meme',
|
||||
aliases: [
|
||||
'memegen'
|
||||
],
|
||||
group: 'imageedit',
|
||||
memberName: 'meme',
|
||||
description: 'Sends a Meme with text of your choice, and a background of your choice.',
|
||||
@@ -17,9 +14,8 @@ module.exports = class MemeCommand extends Command {
|
||||
prompt: 'What meme type do you want to use?',
|
||||
type: 'string',
|
||||
validate: type => {
|
||||
if (memecodes.includes(type.toLowerCase())) {
|
||||
if (memecodes.includes(type.toLowerCase()))
|
||||
return true;
|
||||
}
|
||||
return `${type.toLowerCase()} is not a valid meme type. Use \`x;help meme\` to view a list of types.`;
|
||||
},
|
||||
parse: text => text.toLowerCase()
|
||||
@@ -28,10 +24,9 @@ module.exports = class MemeCommand extends Command {
|
||||
prompt: 'What should the top row of the meme to be?',
|
||||
type: 'string',
|
||||
validate: toprow => {
|
||||
if (toprow.match(/^[a-zA-Z0-9.,!?'\s]+$/) && toprow.length < 100) {
|
||||
if (/[a-zA-Z0-9.,!?'\s]+$/g.test(toprow) && toprow.length < 100)
|
||||
return true;
|
||||
}
|
||||
return `Please do not use special characters and keep the rows under 100 characters each, you have ${toprow.length}.`;
|
||||
return `Please do not use special characters and keep the rows under 100 characters each, top row has ${toprow.length}.`;
|
||||
},
|
||||
parse: text => text.replace(/[ ]/g, '-').replace(/[?]/g, '~q')
|
||||
}, {
|
||||
@@ -39,10 +34,9 @@ module.exports = class MemeCommand extends Command {
|
||||
prompt: 'What should the bottom row of the meme to be?',
|
||||
type: 'string',
|
||||
validate: bottomrow => {
|
||||
if (bottomrow.match(/^[a-zA-Z0-9.,!?'\s]+$/) && bottomrow.length < 100) {
|
||||
if (/[a-zA-Z0-9.,!?'\s]+$/g.test(bottomrow) && bottomrow.length < 100)
|
||||
return true;
|
||||
}
|
||||
return `Please do not use special characters and keep the rows under 100 characters each, you have ${bottomrow.length}.`;
|
||||
return `Please do not use special characters and keep the rows under 100 characters each, bottom row has ${bottomrow.length}.`;
|
||||
},
|
||||
parse: text => text.replace(/[ ]/g, '-').replace(/[?]/g, '~q')
|
||||
}]
|
||||
@@ -50,9 +44,9 @@ module.exports = class MemeCommand extends Command {
|
||||
}
|
||||
|
||||
run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
}
|
||||
if (message.channel.type !== 'dm')
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('ATTACH_FILES'))
|
||||
return message.say(':x: Error! I don\'t have the Attach Files Permission!');
|
||||
const { type, toprow, bottomrow } = args;
|
||||
return message.channel.send({files: [`https://memegen.link/${type}/${toprow}/${bottomrow}.jpg`]});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user