Merge pull request #4 from voidf1sh/v2-dev

V2 dev
This commit is contained in:
Skylar Grant 2021-07-08 22:48:17 -04:00 committed by GitHub
commit 78bc5420ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 1203 additions and 90 deletions

4
.gitignore vendored
View File

@ -2,6 +2,10 @@
.vscode
.eslintrc.json
# Custom folders
gifs/*
pastas/*
# Logs
logs
*.log

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# NodBot
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
Dynamic Help Message
Ability to save favorite gifs and copypastas
## Usage
Search for any gif with `search query here.gif`
Save a favorite gif with `/save-gif <gif_name> <gif link>`
Recall a saved gif with `gif_name.gif`
Save a favorite copypasta with `/save-pasta <pasta_name> <pasta text>`
Recall a saved copypasta with `pasta_name.pasta`
## To Do
Clean up text input for copypastas, line breaks and apostrophes break the bot.
Add ability to reload commands, gifs, pastas, etc without rebooting the bot manually.

34
commands/gif.js Normal file
View File

@ -0,0 +1,34 @@
const functions = require('../functions');
const giphy = require('giphy-api')(process.env.giphyAPIKey);
module.exports = {
name: 'gif',
description: 'Send a GIF',
execute(message, file) {
const client = message.client;
if (!client.gifs.has(file.name)) {
giphy.search(file.name, (err, res) => {
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);
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 {
message.channel.send('I was unable to find a gif of ' + file.name);
}
if (err) console.error(err);
});
} else {
// 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));
}
}
}

40
commands/help.js Normal file
View File

@ -0,0 +1,40 @@
module.exports = {
name: 'help',
description: 'Shows the help page.',
execute(message, file) {
const data = [];
const { commands } = message.client;
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 `[command name].help` to get info on a specific command!');
return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.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?');
});
}
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!');
}
data.push(`**Name:** ${command.name}`);
if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
if (command.description) data.push(`**Description:** ${command.description}`);
if (command.usage) data.push(`**Usage:** \`${command.usage}.${command.name}\``);
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
message.channel.send(data, { split: true });
},
};

9
commands/joint.js Normal file
View 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);
}
}

24
commands/kill.js Normal file
View File

@ -0,0 +1,24 @@
const ownerID = process.env.ownerID;
module.exports = {
name: 'kill',
description: 'Kills the bot OWNER ONLY',
execute(message, args) {
if (message.author.id == ownerID) {
message.channel.send('Shutting down the bot...')
.then(() => {
message.client.destroy();
process.exit();
});
} else {
message.reply('Sorry, only the owner can do that.');
message.client.users.fetch(ownerID)
.then(user => {
user.send(message.author.username + ' attempted to shutdown the bot.')
.then()
.catch(err => console.error(err));
})
.catch(err => console.error(err));
}
}
}

15
commands/pasta.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = {
name: 'pasta',
description: 'Send a copypasta.',
execute(message, file) {
const client = message.client;
const replyHeader = `\'${file.name}\' requested by: ${message.author.username}\n`;
let replyBody = '';
if (!client.pastas.has(file.name)) {
replyBody = 'Sorry I couldn\'t find that pasta.';
} else {
replyBody = client.pastas.get(file.name).content;
}
message.channel.send(replyHeader + replyBody);
}
}

10
commands/request.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
name: 'request',
description: 'Submit a request to the bot developer.',
usage: '<request or feedback>',
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);} );
}
}

20
commands/savegif.js Normal file
View File

@ -0,0 +1,20 @@
module.exports = {
name: 'savegif',
description: 'Adds a given gif to the hardcoded list.',
usage: '<https://link.to.gif> <gif_name>',
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!');
}
}

22
commands/savepasta.js Normal file
View File

@ -0,0 +1,22 @@
const functions = require('../functions.js');
module.exports = {
name: 'savepasta',
description: 'Adds a given copypasta to the hardcoded list.',
usage: '<Copy Pasta Text> <pasta_name>',
execute(message, file) {
const fs = require('fs');
const pastaTextArray = message.content.split(' ');
const pastaFile = functions.getFileInfo(pastaTextArray.pop());
const pastaText = pastaTextArray.join(' ');
const pastaTextEscaped = functions.cleanInput(pastaText);
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!');
}
}

20
commands/spongebob.js Normal file
View File

@ -0,0 +1,20 @@
module.exports = {
name: 'spongebob',
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
usage: '<text you want spongebob-ified',
execute(message, file) {
const replyHeader = `Requested by: ${message.author.username}\n`;
let flipper = 0;
let newText = '';
for (const letter of file.name) {
if (flipper == 0) {
newText = newText + letter.toUpperCase();
flipper = 1;
} else {
newText = newText + letter;
flipper = 0;
}
}
message.channel.send(replyHeader + newText);
}
}

7
commands/template Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: '',
description: '',
execute(message, args) {
message.channel.send('');
}
}

7
commands/truth.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: "truth",
description: "The truth about MHFS",
execute(message, args) {
message.channel.send("https://www.twitch.tv/hochmania/clip/EsteemedSlickDootStinkyCheese-hncmP8aIP8_WQb_a?filter=clips&range=all&sort=time");
}
}

9
commands/wrongbad.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
name: "wrongbad",
description: "",
execute(message, args) {
const wrongbad = "<:wrongbad:853304921969393684>";
message.channel.send("");
}
}

21
config.json Normal file
View File

@ -0,0 +1,21 @@
{
"prefix": "/",
"serverID": "760701839427108874",
"logChannel": "859249300894908447",
"bootMessage": "NodBot v2 Starting Up",
"shutdownMessage": "NodBot v2 Shutting Down",
"validExtensions": [
"gif",
"pasta",
"help",
"spongebob",
"savepasta",
"request",
"savegif",
"truth",
"joint"
],
"emoji": {
"joint": "<:joint:862082955902976000>"
}
}

56
functions.js Normal file
View File

@ -0,0 +1,56 @@
const Discord = require('discord.js');
const fs = require('fs');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
const pastaFiles = fs.readdirSync('./pastas').filter(file => file.endsWith('.js'));
module.exports = {
getCommandFiles(client) {
client.commands = new Discord.Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
},
getGifFiles(client) {
client.gifs = new Discord.Collection();
for (const file of gifFiles) {
const gif = require(`./gifs/${file}`);
client.gifs.set(gif.name, gif);
}
},
getPastaFiles(client) {
client.pastas = new Discord.Collection();
for (const file of pastaFiles) {
const pasta = require(`./pastas/${file}`);
client.pastas.set(pasta.name, pasta);
}
},
getFileInfo(content) {
// 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();
const file = {
'name': filename,
'extension': extension
};
return file;
},
extIsValid(extension) {
const extensions = require('./config.json').validExtensions;
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);
}
}

4
gifs/bobsaget.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: 'bobsaget',
embed_url: 'https://tenor.com/view/bob-saget-tourettes-mad-angry-gif-8840899'
}

4
gifs/cumb.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: 'cumb',
embed_url: 'https://tenor.com/view/sperm-gif-gif-13292476'
}

4
gifs/dab.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: "dab",
embed_url: "https://giphy.com/embed/lae7QSMFxEkkE"
}

4
gifs/deeznuts.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: 'deeznuts',
embed_url: 'https://giphy.com/embed/z0XEX0BeuPGmY'
}

4
gifs/nod.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: "nod",
embed_url: "https://tenor.com/view/smile-nod-yes-robert-redford-beard-gif-10489927"
}

4
gifs/psh.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: "psh",
embed_url: "https://tenor.com/view/ed-bassmaster-youtuber-youtube-influencer-psh-gif-10556767"
}

4
gifs/shedsalive.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: "shedsalive",
embed_url: "https://giphy.com/embed/glL1yvxJ4KvYc"
}

4
gifs/shedsdead.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: "shedsdead",
embed_url: "http://voidf1sh.me/shedsdead.gif"
}

4
gifs/shid.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
name: 'shid',
embed_url: 'https://tenor.com/view/sheet-gif-19721309'
}

1
gifs/template Normal file
View File

@ -0,0 +1 @@
module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}

View File

@ -1,80 +1,56 @@
/* eslint-disable brace-style */
// Variable Assignment
const dotenv = require('dotenv');
dotenv.config();
const Discord = require('discord.js');
const client = new Discord.Client();
// const config = require('./config.json');
// const { prefix, logChannel, bootMessage, shutdownMessage } = require('./config.json');
// const owner = process.env.ownerID;
const giphy = require('giphy-api')(process.env.giphyAPIKey);
const debug = false;
const links = require('./links.json');
const functions = require('./functions.js');
dotenv.config();
const owner = process.env.ownerID;
if (debug) {
console.log(links);
}
client.once('ready', () => {
console.log('Ready');
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
functions.getCommandFiles(client);
functions.getGifFiles(client);
functions.getPastaFiles(client);
// client.channels.fetch(logChannel)
// .then(channel => {
// channel.send(bootMessage)
// .then()
// .catch(err => console.error(err));
// })
// .catch(err => console.error(err));
});
client.login(process.env.TOKEN);
client.on('message', message => {
if (message.author.bot) return;
// Get the filename and extension as an array
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.
if (functions.extIsValid(file.extension) == false || message.author.bot) return;
const pre = message.content.slice(0, -4);
const ext = message.content.slice(-4);
let gifFound = false;
// If the command collection doesn't contain the given command, stop here.
if (!client.commands.has(file.extension)) return;
switch (ext) {
case '.gif':
if (debug) {
console.log('pre: ' + pre);
console.log('ext: ' + ext);
}
for (let index = 0; index < links.gifs.length; index++) {
const gif = links.gifs[index];
if (gif.name == pre) {
message.channel.send(gif.embed_url);
gifFound = true;
}
}
if (gifFound == false) {
try {
giphy.search(pre, function(err, res) {
if (res.data[0] != undefined) {
message.channel.send(res.data[0].embed_url);
} else {
message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.');
}
if (err) {
console.log(err);
}
});
} catch (error) {
console.log(error);
}
}
break;
// Admin Commands
case '.adm':
if (message.member.id == process.env.ownerID) {
switch (pre) {
case 'kill':
client.destroy();
process.exit();
break;
default:
break;
}
}
break;
case '.req':
message.channel.send('Feedback Submitted: ' + pre);
client.users.fetch(owner).then(user => { user.send('Feedback/Request: ' + pre);});
break;
default:
break;
try {
// Attempt to execute the command
client.commands.get(file.extension).execute(message, file);
} catch (error) {
// Log errors and let the user know something went wrong.
console.error(error);
message.channel.send('There was an error trying to execute that command.');
}
// Try to delete the requester's message
if (message.deletable) {
message.delete().then().catch(err => console.error(err));
}
});

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"