Move CommandData and checkCommand to NodBot Classes
This commit is contained in:
parent
1a0817a89c
commit
23f081c6c1
@ -1,4 +1,22 @@
|
||||
module.exports = {
|
||||
CommandData: class {
|
||||
constructor(message) {
|
||||
// Get the location of the final period in the message
|
||||
this.finalPeriod = message.content.lastIndexOf('.');
|
||||
this.isCommand = finalPeriod >= 0 ? true : false; // Check if there is a period somewhere in the message to flag as a possible command
|
||||
this.args = message.content.slice(0,finalPeriod).toLowerCase(); // Grab everything leading up to the final period
|
||||
this.command = message.content.slice(finalPeriod + 1).toLowerCase(); // Grab everything after the final period
|
||||
this.author = message.author.username;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
isValid(validCommands) {
|
||||
if (this.args.startsWith('http')) return false;
|
||||
if (this.args.startsWith('www')) return false;
|
||||
return validCommands.includes(this.command);
|
||||
}
|
||||
},
|
||||
GifData: class {
|
||||
constructor() {
|
||||
this.id = 0;
|
||||
|
33
functions.js
33
functions.js
@ -34,6 +34,7 @@ const config = require('./config.json');
|
||||
const strings = require('./strings.json');
|
||||
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
||||
const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js'));
|
||||
const { CommandData } = require('./CustomModules/NodBot.js');
|
||||
|
||||
// MySQL database connection
|
||||
const mysql = require('mysql');
|
||||
@ -172,36 +173,8 @@ const functions = {
|
||||
},
|
||||
dot: {
|
||||
getCommandData(message) {
|
||||
const commandData = {};
|
||||
// Split the message content at the final instance of a period
|
||||
const finalPeriod = message.content.lastIndexOf('.');
|
||||
// if(isDev) console.log(message.content);
|
||||
// If the final period is the last character, or doesn't exist
|
||||
if (finalPeriod < 0) {
|
||||
if (isDev) console.log(finalPeriod);
|
||||
commandData.isCommand = false;
|
||||
return commandData;
|
||||
}
|
||||
commandData.isCommand = true;
|
||||
// Get the first part of the message, everything leading up to the final period
|
||||
commandData.args = message.content.slice(0,finalPeriod).toLowerCase();
|
||||
// Get the last part of the message, everything after the final period
|
||||
commandData.command = message.content.slice(finalPeriod + 1).toLowerCase();
|
||||
commandData.author = `${message.author.username}`;
|
||||
return this.checkCommand(commandData);
|
||||
},
|
||||
checkCommand(commandData) {
|
||||
if (commandData.isCommand) {
|
||||
const validCommands = require('./config.json').validCommands;
|
||||
commandData.isValid = validCommands.includes(commandData.command);
|
||||
// Add exceptions for messages that contain only a link
|
||||
if (commandData.args.startsWith('http')) commandData.isValid = false;
|
||||
}
|
||||
else {
|
||||
commandData.isValid = false;
|
||||
console.error('Somehow a non-command made it to checkCommands()');
|
||||
}
|
||||
return commandData;
|
||||
const commandData = new CommandData(message);
|
||||
return commandData.isValid(require('./config.json').validCommands);
|
||||
}
|
||||
},
|
||||
embeds: {
|
||||
|
Loading…
Reference in New Issue
Block a user