Compare commits
No commits in common. "00df6074d6eb4c8ec477764ca1230873e01b19d5" and "e5d520a73bd67905ea50e760d2dffdce311f03c7" have entirely different histories.
00df6074d6
...
e5d520a73b
@ -1,36 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
CommandData: class {
|
|
||||||
constructor(message) {
|
|
||||||
// Get the location of the final period in the message
|
|
||||||
this.finalPeriod = message.content.lastIndexOf('.');
|
|
||||||
this.isCommand = this.finalPeriod >= 0 ? true : false; // Check if there is a period somewhere in the message to flag as a possible command
|
|
||||||
this.isValid = false;
|
|
||||||
this.args = message.content.slice(0,this.finalPeriod).toLowerCase(); // Grab everything leading up to the final period
|
|
||||||
this.command = message.content.slice(this.finalPeriod + 1).toLowerCase(); // Grab everything after the final period
|
|
||||||
this.author = message.author.username;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(dotCommands) {
|
|
||||||
if (this.args.startsWith('http')) return false;
|
|
||||||
if (this.args.startsWith('www')) return false;
|
|
||||||
|
|
||||||
for (const [key, value] of dotCommands) {
|
|
||||||
if (key === this.command) {
|
|
||||||
this.isValid = true;
|
|
||||||
return this.isValid;
|
|
||||||
} else if (value.alias && value.alias.includes(this.command)) {
|
|
||||||
this.command = key;
|
|
||||||
this.isValid = true;
|
|
||||||
return this.isValid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isValid = validCommands.includes(this.command);
|
|
||||||
return this.isValid;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
GifData: class {
|
GifData: class {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.id = 0;
|
this.id = 0;
|
||||||
|
47
functions.js
47
functions.js
@ -34,7 +34,6 @@ const config = require('./config.json');
|
|||||||
const strings = require('./strings.json');
|
const strings = require('./strings.json');
|
||||||
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
||||||
const dotCommandFiles = fs.readdirSync('./dot-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
|
// MySQL database connection
|
||||||
const mysql = require('mysql');
|
const mysql = require('mysql');
|
||||||
@ -82,13 +81,13 @@ const functions = {
|
|||||||
for (const file of dotCommandFiles) {
|
for (const file of dotCommandFiles) {
|
||||||
const dotCommand = require(`./dot-commands/${file}`);
|
const dotCommand = require(`./dot-commands/${file}`);
|
||||||
client.dotCommands.set(dotCommand.name, dotCommand);
|
client.dotCommands.set(dotCommand.name, dotCommand);
|
||||||
// if (Array.isArray(dotCommand.alias)) {
|
if (Array.isArray(dotCommand.alias)) {
|
||||||
// dotCommand.alias.forEach(element => {
|
dotCommand.alias.forEach(element => {
|
||||||
// client.dotCommands.set(element, dotCommand);
|
client.dotCommands.set(element, dotCommand);
|
||||||
// });
|
});
|
||||||
// } else if (dotCommand.alias != undefined) {
|
} else if (dotCommand.alias != undefined) {
|
||||||
// client.dotCommands.set(dotCommand.alias, dotCommand);
|
client.dotCommands.set(dotCommand.alias, dotCommand);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
if (isDev) console.log('Dot Commands Collection Built');
|
if (isDev) console.log('Dot Commands Collection Built');
|
||||||
},
|
},
|
||||||
@ -173,9 +172,35 @@ const functions = {
|
|||||||
},
|
},
|
||||||
dot: {
|
dot: {
|
||||||
getCommandData(message) {
|
getCommandData(message) {
|
||||||
const commandData = new CommandData(message);
|
const commandData = {};
|
||||||
const { validCommands } = require('./config.json');
|
// Split the message content at the final instance of a period
|
||||||
commandData.validate(message.client.dotCommands);
|
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;
|
return commandData;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nodbot",
|
"name": "nodbot",
|
||||||
"version": "3.3.3",
|
"version": "3.3.2",
|
||||||
"description": "Nods and Nod Accessories, now with ChatGPT!",
|
"description": "Nods and Nod Accessories, now with ChatGPT!",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
Loading…
Reference in New Issue
Block a user