More command conversions

This commit is contained in:
= 2021-07-01 18:12:21 -04:00
parent 3bdfbf0e44
commit e810a78fac
12 changed files with 872 additions and 105 deletions

View File

@ -1,10 +0,0 @@
module.exports = {
name: "get-ext",
description: "Test function to capture the extension from the content of a message.",
execute(message, args) {
const finalWord = args.pop();
const file = finalWord.split('.');
console.log(file);
message.reply('The extension is: ' + file[1] + '\nThe filename is: ' + file[0]);
}
}

View File

@ -1,16 +1,14 @@
const { prefix } = require('../config.json');
module.exports = {
name: 'help',
description: 'Shows the help page.',
execute(message, args) {
execute(message, file) {
const data = [];
const { commands } = message.client;
if (!args.length) {
if (!file.name) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);
data.push('\nYou can send `[command name].help` to get info on a specific command!');
return message.author.send(data, { split: true })
.then(() => {
@ -19,15 +17,14 @@ module.exports = {
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
message.reply('It seems like I can\'t DM you! Do you have DMs disabled?');
});
}
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
const command = commands.get(file.name) || commands.find(c => c.aliases && c.aliases.includes(file.name));
if (!command) {
return message.reply('that\'s not a valid command!');
return message.reply('That\'s not a valid command!');
}
data.push(`**Name:** ${command.name}`);

View File

@ -1,8 +1,8 @@
module.exports = {
name: 'request',
description: 'Submit a request to the bot developer.',
execute(message, args) {
const request = args.join(' ');
execute(message, file) {
const request = file.name;
message.channel.send('Your request has been submitted:\n```\n' + request + '\n```');
message.client.users.fetch(process.env.ownerID).then(user => {user.send('New request or feedback:\n```\n' + request + '\n```');}).catch(error => { console.error(error);} );
}

View File

@ -1,20 +0,0 @@
module.exports = {
name: 'save-gif',
description: 'Adds a given gif to the hardcoded list.',
execute(message, args) {
if (args.length != 2) {
message.reply('This command requires exactly two arguments, gif name and url. Please try again.');
return;
}
const fs = require('fs');
fs.appendFile(`./gifs/${args[0]}.js`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) {
if (err) throw err;
console.log('Saved file!');
const gif = require(`../gifs/${args[0]}.js`);
message.client.gifs.set(gif.name, gif);
});
message.reply('GIF saved as: ' + args[0] + '.gif!');
}
}

View File

@ -1,17 +0,0 @@
module.exports = {
name: 'save-pasta',
description: 'Adds a given copypasta to the hardcoded list.',
execute(message, args) {
const fs = require('fs');
const filename = args.shift();
const pastaText = args.join(' ');
fs.appendFile(`./pastas/${filename}.js`, `module.exports = {\n\tname: '${filename}',\n\tcontent: '${pastaText}'\n}`, function(err) {
if (err) throw err;
console.log('Saved file!');
const pasta = require(`../pastas/${filename}.js`);
message.client.pastas.set(pasta.name, pasta);
});
message.reply('GIF saved as: ' + filename + '.pasta!');
}
}

19
commands/savegif.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
name: 'savegif',
description: 'Adds a given gif to the hardcoded list.',
execute(message, file) {
const tempArray = file.name.split(' ');
const embedURL = tempArray.shift();
const gifName = tempArray.join(' ');
const fs = require('fs');
fs.appendFile(`./gifs/${gifName}.js`, `module.exports = {\n\tname: '${gifName}',\n\tembed_url: '${embedURL}'\n}`, function(err) {
if (err) throw err;
console.log('Saved file!');
const gif = require(`../gifs/${gifName}.js`);
message.client.gifs.set(gif.name, gif);
});
message.reply('GIF saved as: ' + gifName + '.gif!');
}
}

21
commands/savepasta.js Normal file
View File

@ -0,0 +1,21 @@
const functions = require('../functions.js');
module.exports = {
name: 'savepasta',
description: 'Adds a given copypasta to the hardcoded list.',
execute(message, file) {
const fs = require('fs');
const pastaTextArray = message.content.split(' ');
const pastaFile = functions.getFileInfo(pastaTextArray.pop());
const pastaText = pastaTextArray.join(' ');
const pastaTextEscaped = pastaText.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
fs.appendFile(`./pastas/${pastaFile.name}.js`, `module.exports = {\n\tname: '${pastaFile.name}',\n\tcontent: '${pastaTextEscaped}'\n}`, function(err) {
if (err) throw err;
console.log('Saved file!');
const pasta = require(`../pastas/${pastaFile.name}.js`);
message.client.pastas.set(pasta.name, pasta);
});
message.reply('GIF saved as: ' + pastaFile.name + '.pasta!');
}
}

View File

@ -3,5 +3,14 @@
"serverID": "760701839427108874",
"logChannel": "859249300894908447",
"bootMessage": "NodBot v2 Starting Up",
"shutdownMessage": "NodBot v2 Shutting Down"
"shutdownMessage": "NodBot v2 Shutting Down",
"validExtensions": [
"gif",
"pasta",
"help",
"spongebob",
"savepasta",
"request",
"savegif"
]
}

View File

@ -31,7 +31,8 @@ module.exports = {
if (debug) console.log(client.pastas);
},
getFileInfo(content) {
const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim);
// const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim);
const finalPeriod = content.lastIndexOf('.');
if (finalPeriod < 0) return false;
const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
const filename = content.slice(0,finalPeriod).toLowerCase();
@ -39,23 +40,10 @@ module.exports = {
'name': filename,
'extension': extension
};
console.log(finalPeriod, file);
return file;
},
extIsValid(extension) {
switch (extension) {
case 'gif':
return true;
case 'jpg':
return false;
case 'pasta':
return true;
case 'admin':
return true;
case 'spongebob':
return true;
default:
return false;
}
const extensions = require('./config.json').validExtensions;
return extensions.includes(extension);
}
}

View File

@ -33,7 +33,6 @@ client.login(process.env.TOKEN);
client.on('message', message => {
// Get the filename and extension as an array
// TODO Rename this function to something more appropriate
const file = functions.getFileInfo(message.content);
if (!file) return;
// If the message is from a bot, or doesn't have a valid file extension, stop here.

836
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"dependencies": {
"discord.js": "^12.5.3",
"dotenv": "^10.0.0",
"giphy-api": "^2.0.1"
"giphy-api": "^2.0.1",
"nodemon": "^2.0.9"
},
"devDependencies": {
"eslint": "^7.29.0"