add ability to save gifs in chat

This commit is contained in:
= 2021-06-27 23:20:21 -04:00
parent ae6627488a
commit 153af5008d
8 changed files with 61 additions and 38 deletions

View File

@ -1,8 +1,9 @@
/* eslint-disable quotes */
module.exports = { module.exports = {
name: "reload-gifs", name: "reload-gifs",
description: "Refresh the hardcoded gif library.", description: "Refresh the hardcoded gif library.",
execute(message, args) { execute(message, args) {
const index = require('../index.js'); const functions = require('../functions.js');
index.getGifFiles(); functions.getGifFiles(message.client);
} }
} }

View File

@ -8,9 +8,13 @@ module.exports = {
} }
const fs = require('fs'); const fs = require('fs');
fs.appendFile(`./gifs/${args[0]}.gif`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) { fs.appendFile(`./gifs/${args[0]}.js`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) {
if (err) throw err; if (err) throw err;
console.log('Saved file!'); 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!');
} }
} }

35
functions.js Normal file
View File

@ -0,0 +1,35 @@
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 debug = true;
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);
}
if (debug) console.log(client.commands);
},
getGifFiles(client) {
client.gifs = new Discord.Collection();
for (const file of gifFiles) {
const gif = require(`./gifs/${file}`);
client.gifs.set(gif.name, gif);
}
if (debug) console.log(client.gifs);
},
extCheck(content) {
const lastFour = content.slice(-4);
switch (lastFour) {
case '.gif':
return 'gif';
case '.jpg':
return 'jpg';
default:
return false;
}
}
}

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/shid.js Normal file
View File

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

View File

@ -1,59 +1,30 @@
/* eslint-disable brace-style */ /* eslint-disable brace-style */
// Variable Assignment // Variable Assignment
const fs = require('fs');
const dotenv = require('dotenv'); const dotenv = require('dotenv');
dotenv.config(); dotenv.config();
const Discord = require('discord.js'); const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
client.commands = new Discord.Collection();
client.gifs = new Discord.Collection();
const debug = true; const debug = true;
// const config = require('./config.json'); // const config = require('./config.json');
const { prefix } = require('./config.json'); const { prefix } = require('./config.json');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
// const owner = process.env.ownerID; // const owner = process.env.ownerID;
const giphy = require('giphy-api')(process.env.giphyAPIKey); const giphy = require('giphy-api')(process.env.giphyAPIKey);
const functions = require('./functions.js');
function getCommandFiles() {
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
if (debug) console.log(client.commands);
}
function getGifFiles() {
for (const file of gifFiles) {
const gif = require(`./gifs/${file}`);
client.gifs.set(gif.name, gif);
}
if (debug) console.log(client.gifs);
}
function extCheck(content) {
const lastFour = content.slice(-4);
switch (lastFour) {
case '.gif':
return 'gif';
case '.jpg':
return 'jpg';
default:
return false;
}
}
client.once('ready', () => { client.once('ready', () => {
console.log('Ready'); console.log('Ready');
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error); client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
getCommandFiles(); functions.getCommandFiles(client);
getGifFiles(); functions.getGifFiles(client);
}); });
client.login(process.env.TOKEN); client.login(process.env.TOKEN);
client.on('message', message => { client.on('message', message => {
const ext = extCheck(message.content); const ext = functions.extCheck(message.content);
if (debug) console.log(ext); if (debug) console.log(ext);
if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return; if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return;