2021-06-26 21:38:18 +00:00
|
|
|
/* eslint-disable brace-style */
|
|
|
|
// Variable Assignment
|
|
|
|
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-28 03:20:21 +00:00
|
|
|
|
2021-06-27 23:41:25 +00:00
|
|
|
const debug = true;
|
2021-06-28 00:24:58 +00:00
|
|
|
// const config = require('./config.json');
|
2021-06-29 01:42:14 +00:00
|
|
|
const { prefix, logChannel, bootMessage, shutdownMessage } = require('./config.json');
|
2021-06-28 03:20:21 +00:00
|
|
|
|
2021-06-28 19:28:16 +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-28 03:20:21 +00:00
|
|
|
const functions = require('./functions.js');
|
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-28 03:20:21 +00:00
|
|
|
functions.getCommandFiles(client);
|
|
|
|
functions.getGifFiles(client);
|
2021-06-28 19:28:16 +00:00
|
|
|
functions.getPastaFiles(client);
|
2021-06-29 01:42:14 +00:00
|
|
|
client.channels.fetch(logChannel)
|
|
|
|
.then(channel => {
|
|
|
|
channel.send(bootMessage)
|
|
|
|
.then()
|
|
|
|
.catch(err => console.error(err));
|
|
|
|
})
|
|
|
|
.catch(err => console.error(err));
|
2021-06-26 21:38:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.login(process.env.TOKEN);
|
|
|
|
|
|
|
|
client.on('message', message => {
|
2021-06-28 19:28:16 +00:00
|
|
|
const args = message.content.trim().split(/ +/);
|
2021-06-28 22:11:32 +00:00
|
|
|
// TODO this will surely break something when trying to use non-filename commands
|
|
|
|
const file = functions.getExtension(args);
|
|
|
|
// If the message is from a bot, or doesn't have the prefix or a file extension, stop here.
|
|
|
|
if ((!message.content.startsWith(prefix) && file[1] == undefined) || message.author.bot) return;
|
2021-06-27 19:23:14 +00:00
|
|
|
|
2021-06-28 22:11:32 +00:00
|
|
|
// If the message starts with the prefix,
|
2021-06-28 00:24:58 +00:00
|
|
|
if (message.content.startsWith(prefix)) {
|
2021-06-28 22:11:32 +00:00
|
|
|
// Extract the command
|
2021-06-28 19:28:16 +00:00
|
|
|
const command = args.shift().toLowerCase().slice(prefix.length);
|
2021-06-28 00:24:58 +00:00
|
|
|
|
2021-06-28 02:19:16 +00:00
|
|
|
if (debug) console.log(args);
|
2021-06-28 22:11:32 +00:00
|
|
|
// If the command collection doesn't contain the given command, stop here.
|
2021-06-28 00:24:58 +00:00
|
|
|
if (!client.commands.has(command)) return;
|
|
|
|
|
|
|
|
try {
|
2021-06-28 22:11:32 +00:00
|
|
|
// Attempt to execute the command
|
2021-06-28 00:24:58 +00:00
|
|
|
client.commands.get(command).execute(message, args);
|
|
|
|
} catch (error) {
|
2021-06-28 22:11:32 +00:00
|
|
|
// Log errors and let the user know something went wrong.
|
2021-06-28 00:24:58 +00:00
|
|
|
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 22:11:32 +00:00
|
|
|
// If there is a file extension
|
|
|
|
if (file[1] != undefined) {
|
|
|
|
const query = message.content.slice(0, -4);
|
|
|
|
switch (file[1]) {
|
|
|
|
case 'gif':
|
|
|
|
if (debug) console.log(query);
|
2021-06-27 23:41:25 +00:00
|
|
|
|
2021-06-28 22:11:32 +00:00
|
|
|
if (!client.gifs.has(file[0])) {
|
|
|
|
giphy.search(query, (err, res) => {
|
|
|
|
if (res.data[0] != undefined) {
|
2021-06-29 02:38:03 +00:00
|
|
|
message.channel.send(query + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
|
2021-06-28 22:11:32 +00:00
|
|
|
} else {
|
|
|
|
message.channel.send('I was unable to find a gif of ' + query);
|
|
|
|
}
|
|
|
|
if (err) console.error(err);
|
|
|
|
});
|
|
|
|
} else {
|
2021-06-29 02:38:03 +00:00
|
|
|
message.channel.send(query + ' requested by ' + message.author.username + '\n' + client.gifs.get(query).embed_url);
|
2021-06-28 22:11:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'pasta':
|
|
|
|
// const pastaName = args[0].splice(args[0].search(/\.(?:.(?!\\))+$/gim))
|
|
|
|
if (debug) console.log(file[0]);
|
2021-06-28 19:28:16 +00:00
|
|
|
|
2021-06-28 22:11:32 +00:00
|
|
|
if (!client.pastas.has(file[0])) {
|
|
|
|
message.reply('Sorry I couldn\'t find that gif.');
|
|
|
|
} else {
|
2021-06-29 01:42:14 +00:00
|
|
|
message.channel.send(client.pastas.get(file[0]).content, { split: { char: ' ' } });
|
2021-06-28 22:11:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-06-28 19:28:16 +00:00
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
}
|
2021-06-28 22:11:32 +00:00
|
|
|
|
2021-06-29 02:38:03 +00:00
|
|
|
// Try to delete the requester's message
|
|
|
|
if (message.deletable) {
|
|
|
|
message.delete().then().catch(err => console.error(err));
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
});
|