sanitizing inputs and creating embeds
This commit is contained in:
parent
2c6d424baa
commit
5dc2a1ab53
@ -1,6 +1,9 @@
|
|||||||
# NodBot
|
# NodBot
|
||||||
A simple Discord bot created by @voidf1sh#0420 for retreiving gifs, saving copypastas, and more coming soon.
|
A simple Discord bot created by @voidf1sh#0420 for retreiving gifs, saving copypastas, and more coming soon.
|
||||||
|
|
||||||
|
## Dependancies
|
||||||
|
NodBot depends on `fs`, `discord.js`, `dotenv`, and `giphy-api`.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
Dynamic Help Message
|
Dynamic Help Message
|
||||||
Ability to save favorite gifs and copypastas
|
Ability to save favorite gifs and copypastas
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
const functions = require('../functions');
|
||||||
|
|
||||||
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'gif',
|
name: 'gif',
|
||||||
@ -7,14 +9,26 @@ module.exports = {
|
|||||||
if (!client.gifs.has(file.name)) {
|
if (!client.gifs.has(file.name)) {
|
||||||
giphy.search(file.name, (err, res) => {
|
giphy.search(file.name, (err, res) => {
|
||||||
if (res.data[0] != undefined) {
|
if (res.data[0] != undefined) {
|
||||||
message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
|
// message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
|
||||||
|
const gifInfo = {
|
||||||
|
'name': file.name,
|
||||||
|
'embed_url': res.data[0].images.original.url,
|
||||||
|
'requestor': '@' + message.author.username + '#' + message.author.discriminator,
|
||||||
|
};
|
||||||
|
message.channel.send(functions.createGifEmbed(gifInfo));
|
||||||
} else {
|
} else {
|
||||||
message.channel.send('I was unable to find a gif of ' + file.name);
|
message.channel.send('I was unable to find a gif of ' + file.name);
|
||||||
}
|
}
|
||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + client.gifs.get(file.name).embed_url);
|
// message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + client.gifs.get(file.name).embed_url);
|
||||||
|
const gifInfo = {
|
||||||
|
'name': file.name,
|
||||||
|
'embed_url': file.embed_url,
|
||||||
|
'requestor': message.author.username + '#' + message.author.discriminator,
|
||||||
|
};
|
||||||
|
message.channel.send(functions.createGifEmbed(gifInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
|
if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
|
||||||
if (command.description) data.push(`**Description:** ${command.description}`);
|
if (command.description) data.push(`**Description:** ${command.description}`);
|
||||||
if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);
|
if (command.usage) data.push(`**Usage:** \`${command.usage}.${command.name}\``);
|
||||||
|
|
||||||
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
|
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
|
||||||
|
|
||||||
|
9
commands/joint.js
Normal file
9
commands/joint.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const { emoji } = require('../config.json');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'joint',
|
||||||
|
description: 'Pass the joint!',
|
||||||
|
execute(message, args) {
|
||||||
|
message.channel.send('It\'s dangerous to go alone... take this: ' + emoji.joint);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: "log-message",
|
|
||||||
description: "Logs the message to console for debugging purposes.",
|
|
||||||
execute(message, args) {
|
|
||||||
console.log(message);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: 'ping',
|
|
||||||
description: 'Ping!',
|
|
||||||
execute(message, args) {
|
|
||||||
message.channel.send('Pong.');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
/* eslint-disable quotes */
|
|
||||||
module.exports = {
|
|
||||||
name: "reload-gifs",
|
|
||||||
description: "Refresh the hardcoded gif library.",
|
|
||||||
execute(message, args) {
|
|
||||||
const functions = require('../functions.js');
|
|
||||||
functions.getGifFiles(message.client);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'request',
|
name: 'request',
|
||||||
description: 'Submit a request to the bot developer.',
|
description: 'Submit a request to the bot developer.',
|
||||||
|
usage: '<request or feedback>',
|
||||||
execute(message, file) {
|
execute(message, file) {
|
||||||
const request = file.name;
|
const request = file.name;
|
||||||
message.channel.send('Your request has been submitted:\n```\n' + request + '\n```');
|
message.channel.send('Your request has been submitted:\n```\n' + request + '\n```');
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'savegif',
|
name: 'savegif',
|
||||||
description: 'Adds a given gif to the hardcoded list.',
|
description: 'Adds a given gif to the hardcoded list.',
|
||||||
|
usage: '<https://link.to.gif> <gif_name>',
|
||||||
execute(message, file) {
|
execute(message, file) {
|
||||||
const tempArray = file.name.split(' ');
|
const tempArray = file.name.split(' ');
|
||||||
const embedURL = tempArray.shift();
|
const embedURL = tempArray.shift();
|
||||||
|
@ -3,12 +3,13 @@ const functions = require('../functions.js');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'savepasta',
|
name: 'savepasta',
|
||||||
description: 'Adds a given copypasta to the hardcoded list.',
|
description: 'Adds a given copypasta to the hardcoded list.',
|
||||||
|
usage: '<Copy Pasta Text> <pasta_name>',
|
||||||
execute(message, file) {
|
execute(message, file) {
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const pastaTextArray = message.content.split(' ');
|
const pastaTextArray = message.content.split(' ');
|
||||||
const pastaFile = functions.getFileInfo(pastaTextArray.pop());
|
const pastaFile = functions.getFileInfo(pastaTextArray.pop());
|
||||||
const pastaText = pastaTextArray.join(' ');
|
const pastaText = pastaTextArray.join(' ');
|
||||||
const pastaTextEscaped = pastaText.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
|
const pastaTextEscaped = functions.cleanInput(pastaText);
|
||||||
fs.appendFile(`./pastas/${pastaFile.name}.js`, `module.exports = {\n\tname: '${pastaFile.name}',\n\tcontent: '${pastaTextEscaped}'\n}`, function(err) {
|
fs.appendFile(`./pastas/${pastaFile.name}.js`, `module.exports = {\n\tname: '${pastaFile.name}',\n\tcontent: '${pastaTextEscaped}'\n}`, function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('Saved file!');
|
console.log('Saved file!');
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'spongebob',
|
name: 'spongebob',
|
||||||
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
|
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
|
||||||
|
usage: '<text you want spongebob-ified',
|
||||||
execute(message, file) {
|
execute(message, file) {
|
||||||
const replyHeader = `Requested by: ${message.author.username}\n`;
|
const replyHeader = `Requested by: ${message.author.username}\n`;
|
||||||
let flipper = 0;
|
let flipper = 0;
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
name: "test-textconv",
|
|
||||||
description: "Give the bot some text to convert and send back.",
|
|
||||||
execute(message, args) {
|
|
||||||
console.log(args);
|
|
||||||
const textPre = args.join(' ');
|
|
||||||
const textPost1 = textPre.replace(/\n/,'\n');
|
|
||||||
const textPost2 = textPost1.replace(/\'/,'\'');
|
|
||||||
console.log(textPost1);
|
|
||||||
console.log(textPost2);
|
|
||||||
}
|
|
||||||
}
|
|
11
functions.js
11
functions.js
@ -45,5 +45,16 @@ module.exports = {
|
|||||||
extIsValid(extension) {
|
extIsValid(extension) {
|
||||||
const extensions = require('./config.json').validExtensions;
|
const extensions = require('./config.json').validExtensions;
|
||||||
return extensions.includes(extension);
|
return extensions.includes(extension);
|
||||||
|
},
|
||||||
|
cleanInput(input) {
|
||||||
|
return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
|
||||||
|
},
|
||||||
|
createGifEmbed(data) {
|
||||||
|
return new Discord.MessageEmbed()
|
||||||
|
.setAuthor('NodBot v2 - GIF')
|
||||||
|
.setTitle(data.name)
|
||||||
|
.setImage(data.embed_url)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(data.requestor);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user