2021-06-26 21:38:18 +00:00
|
|
|
/* eslint-disable brace-style */
|
|
|
|
// Variable Assignment
|
2021-06-27 23:41:25 +00:00
|
|
|
const fs = require('fs');
|
2021-06-26 21:38:18 +00:00
|
|
|
const dotenv = require('dotenv');
|
2021-06-27 23:41:25 +00:00
|
|
|
dotenv.config();
|
2021-06-26 21:38:18 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const client = new Discord.Client();
|
2021-06-27 23:41:25 +00:00
|
|
|
client.commands = new Discord.Collection();
|
2021-06-28 00:24:58 +00:00
|
|
|
client.gifs = new Discord.Collection();
|
2021-06-27 23:41:25 +00:00
|
|
|
const debug = true;
|
2021-06-28 00:24:58 +00:00
|
|
|
// const config = require('./config.json');
|
|
|
|
const { prefix } = require('./config.json');
|
2021-06-27 23:41:25 +00:00
|
|
|
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
2021-06-28 00:24:58 +00:00
|
|
|
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
|
2021-06-27 23:41:25 +00:00
|
|
|
// const owner = process.env.ownerID;
|
2021-06-28 00:24:58 +00:00
|
|
|
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
2021-06-26 21:38:18 +00:00
|
|
|
|
2021-06-27 23:41:25 +00:00
|
|
|
function getCommandFiles() {
|
|
|
|
for (const file of commandFiles) {
|
|
|
|
const command = require(`./commands/${file}`);
|
|
|
|
client.commands.set(command.name, command);
|
|
|
|
}
|
|
|
|
if (debug) console.log(client.commands);
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
|
2021-06-28 00:24:58 +00:00
|
|
|
function getGifFiles() {
|
|
|
|
for (const file of gifFiles) {
|
|
|
|
const gif = require(`./gifs/${file}`);
|
|
|
|
client.gifs.set(gif.name, gif);
|
|
|
|
}
|
|
|
|
if (debug) console.log(client.gifs);
|
|
|
|
}
|
|
|
|
|
2021-06-27 23:41:25 +00:00
|
|
|
function extCheck(content) {
|
|
|
|
const lastFour = content.slice(-4);
|
|
|
|
switch (lastFour) {
|
|
|
|
case '.gif':
|
|
|
|
return 'gif';
|
|
|
|
case '.jpg':
|
|
|
|
return 'jpg';
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.once('ready', () => {
|
|
|
|
console.log('Ready');
|
2021-06-28 00:24:58 +00:00
|
|
|
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
|
2021-06-27 23:41:25 +00:00
|
|
|
getCommandFiles();
|
2021-06-28 00:24:58 +00:00
|
|
|
getGifFiles();
|
2021-06-26 21:38:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.login(process.env.TOKEN);
|
|
|
|
|
|
|
|
client.on('message', message => {
|
2021-06-28 00:24:58 +00:00
|
|
|
const ext = extCheck(message.content);
|
|
|
|
if (debug) console.log(ext);
|
|
|
|
if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return;
|
2021-06-27 19:23:14 +00:00
|
|
|
|
2021-06-28 00:24:58 +00:00
|
|
|
if (message.content.startsWith(prefix)) {
|
|
|
|
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
|
|
|
const command = args.shift().toLowerCase();
|
|
|
|
|
|
|
|
if (!client.commands.has(command)) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
client.commands.get(command).execute(message, args);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
message.channel.send('There was an error trying to execute that command.');
|
|
|
|
}
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
|
2021-06-28 00:24:58 +00:00
|
|
|
if (ext == 'gif') {
|
|
|
|
const query = message.content.slice(0, -4);
|
|
|
|
if (debug) console.log(query);
|
2021-06-27 23:41:25 +00:00
|
|
|
|
2021-06-28 00:24:58 +00:00
|
|
|
if (!client.gifs.has(query)) {
|
|
|
|
giphy.search(query, (err, res) => {
|
|
|
|
if (res.data[0] != undefined) {
|
|
|
|
message.channel.send(res.data[0].embed_url).then().catch(console.error);
|
|
|
|
} else {
|
|
|
|
message.channel.send('I was unable to find a gif of ' + query);
|
|
|
|
}
|
|
|
|
if (err) console.error(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
message.channel.send(client.gifs.get(query).embed_url);
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
}
|
|
|
|
});
|