Files
selmerBot/main.js
T

106 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-02-17 21:42:57 -05:00
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
2022-04-30 17:02:26 -04:00
//const { token } = require('./commands/currency/config.json');
//Heroku part
const { token } = require('process.env');
2022-04-17 08:51:30 -04:00
2022-02-17 21:42:57 -05:00
2022-04-30 15:51:55 -04:00
const bot = new Client({
2022-02-17 21:42:57 -05:00
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
2022-04-30 15:51:55 -04:00
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES
2022-02-17 21:42:57 -05:00
],
});
const prefix = '/';
const fs = require('fs');
const { exit } = require('process');
2022-04-30 15:51:55 -04:00
bot.commands = new Discord.Collection();
2022-02-17 21:42:57 -05:00
2022-04-30 15:51:55 -04:00
bot.commNames = new Discord.Collection();
2022-02-17 21:42:57 -05:00
2022-04-30 15:51:55 -04:00
bot.econ = new Discord.Collection();
2022-04-17 08:51:30 -04:00
2022-02-17 21:42:57 -05:00
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
2022-04-17 08:51:30 -04:00
const econFiles = fs.readdirSync('./commands/currency').filter(file => file.endsWith('.js'));;
2022-02-17 21:42:57 -05:00
let i = 0;
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
2022-04-30 15:51:55 -04:00
bot.commands.set(command.name, command);
bot.commNames.set(i, [command.name, command.description]);
2022-02-17 21:42:57 -05:00
i ++;
}
2022-04-17 08:51:30 -04:00
//ECON SECTION
2022-04-30 15:51:55 -04:00
bot.commands.set('ECON', require(`./commands/currency/app.js`));
2022-04-17 08:51:30 -04:00
const currency = new Discord.Collection();
const { Users } = require('./commands/currency/dbObjects.js');
i++;
2022-02-17 21:42:57 -05:00
2022-04-30 15:51:55 -04:00
bot.commNames.set('length', i);
2022-02-17 21:42:57 -05:00
2022-04-30 15:51:55 -04:00
bot.on('ready', async () => {
// bot.once('ready', async () => {
2022-04-17 08:51:30 -04:00
const storedBalances = await Users.findAll();
storedBalances.forEach(b => currency.set(b.user_id, b));
2022-04-30 15:51:55 -04:00
// console.log(`Logged in as ${bot.user.tag}!`);
2022-02-17 21:42:57 -05:00
console.log('SLEEMER BOT ONLINE!!!!! OH MY GOD OH MY GOD!!!');
});
2022-04-30 15:51:55 -04:00
bot.on('messageCreate', (message) => {
2022-02-17 21:42:57 -05:00
//COMMAND AREA
//Check if the prefix exists
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
2022-02-17 23:37:48 -05:00
2022-02-17 21:42:57 -05:00
//Check if the user has sufficient permission
//Performes the command
switch(command) {
2022-04-30 15:51:55 -04:00
case 'test': bot.commands.get('Hello World').execute(message, args);
2022-02-17 21:42:57 -05:00
break;
2022-04-30 15:51:55 -04:00
case 'profile': bot.commands.get('profile').execute(message, args, Discord);
2022-02-17 22:02:18 -05:00
break;
2022-04-30 15:51:55 -04:00
case 'links': bot.commands.get('links').execute(message, args, Discord);
2022-02-17 22:18:51 -05:00
break;
2022-04-30 15:51:55 -04:00
case 'arrow': bot.commands.get('arrow').execute(message, args, Discord);
2022-02-17 23:37:48 -05:00
break;
2022-04-30 15:51:55 -04:00
case 'playaudio': bot.commands.get('playaudio').execute(message, args, bot, Discord);
2022-04-14 13:25:01 -04:00
break;
2022-03-10 20:30:03 -05:00
2022-04-30 15:51:55 -04:00
case 'quotes': bot.commands.get('quotes').execute(message, args, Discord, Client);
break;
2022-04-30 15:51:55 -04:00
case 'extracredit': bot.commands.get('EC').execute(message);
break;
2022-04-30 15:51:55 -04:00
case 'scrape': bot.commands.get('scraper').execute(message, args);
2022-03-10 20:30:03 -05:00
break;
2022-04-30 15:51:55 -04:00
case 'kareoke': bot.commands.get('kareoke').execute(message, args);
2022-03-10 20:30:03 -05:00
break;
2022-04-30 15:51:55 -04:00
default: bot.commands.get('ECON').execute(bot, prefix, message, args, command, Users, currency);
2022-02-17 21:42:57 -05:00
}
})
//Last Line
2022-04-30 15:51:55 -04:00
bot.login(token);