nodbot/index.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

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;
// const config = require('./config.json');
const { prefix } = require('./config.json');
2021-06-28 03:20:21 +00:00
2021-06-28 19:28:16 +00:00
// const owner = process.env.ownerID;
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');
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-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(/ +/);
const extension = functions.getExtension(args);
if ((!message.content.startsWith(prefix) && extension != undefined) || message.author.bot) return;
2021-06-27 19:23:14 +00:00
if (message.content.startsWith(prefix)) {
2021-06-28 19:28:16 +00:00
const command = args.shift().toLowerCase().slice(prefix.length);
if (debug) console.log(args);
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-28 03:30:47 +00:00
message.guild.owner
}
}
2021-06-26 21:38:18 +00:00
2021-06-28 19:28:16 +00:00
const query = message.content.slice(0, -4);
switch (extension) {
case '.gif':
if (debug) console.log(query);
2021-06-27 23:41:25 +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-28 19:28:16 +00:00
break;
case '.pasta':
const pastaName = args[0].splice(args[0].search(/\.(?:.(?!\\))+$/gim))
if (debug) console.log(query);
if (!client.pastas.has(query)) {
message.reply('Sorry I couldn\'t find that gif.');
} else {
message.channel.send(client.pastas.get(query).content);
}
break;
default:
break;
2021-06-26 21:38:18 +00:00
}
});