2022-02-17 21:42:57 -05:00
|
|
|
const { Client, Intents } = require('discord.js');
|
|
|
|
|
const Discord = require('discord.js');
|
2022-05-12 17:38:08 +03:00
|
|
|
const { MongoClient, ServerApiVersion } = require('mongodb');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const { exit } = require('process');
|
|
|
|
|
const BASE_LVL_XP = 20;
|
|
|
|
|
|
2022-04-30 17:41:44 -04:00
|
|
|
// const { token } = require('./config.json');
|
2022-04-30 17:02:26 -04:00
|
|
|
//Heroku part
|
2022-05-12 17:48:49 +03:00
|
|
|
// const { token } = process.env.token;
|
2022-04-17 08:51:30 -04: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,
|
2022-05-13 12:14:24 +03:00
|
|
|
Intents.FLAGS.GUILD_VOICE_STATES,
|
|
|
|
|
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS
|
2022-02-17 21:42:57 -05:00
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const prefix = '/';
|
|
|
|
|
|
|
|
|
|
|
2022-05-09 12:11:18 +03:00
|
|
|
//MongoDB integration
|
2022-05-12 17:44:24 +03:00
|
|
|
const mongouri = process.env.MONGODB_URI;
|
2022-05-12 17:38:08 +03:00
|
|
|
const { connect } = require('mongoose');
|
|
|
|
|
|
|
|
|
|
bot.on("guildCreate", guild => {
|
|
|
|
|
// guild.owner.send('Thanks! You can use +help to discover commands.')
|
|
|
|
|
|
|
|
|
|
//Get total inventory
|
|
|
|
|
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
|
|
|
|
client.connect(err => {
|
|
|
|
|
const collection = client.db(guild).collection("shop");
|
|
|
|
|
// perform actions on the collection object
|
|
|
|
|
console.log(guild);
|
|
|
|
|
client.close();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//MongoDB Integration end
|
|
|
|
|
// let item = items.filter(function (item) { return item.name.toLowerCase() == 'grapes'; });
|
2022-05-09 12:11:18 +03:00
|
|
|
|
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-05-09 12:14:23 +03:00
|
|
|
|
2022-04-17 08:51:30 -04:00
|
|
|
|
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-05-12 17:38:08 +03:00
|
|
|
// const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));;
|
2022-05-13 12:14:24 +03:00
|
|
|
bot.commands.set('ANIME', require(`./commands/anime_and_manga/anime_main`));
|
|
|
|
|
bot.commands.set('MANGA', require(`./commands/anime_and_manga/manga_main`));
|
2022-04-30 17:41:44 -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-05-12 17:38:08 +03:00
|
|
|
//XP Table section
|
|
|
|
|
let xp_collection = new Map();
|
|
|
|
|
let items;
|
2022-02-17 21:42:57 -05:00
|
|
|
|
2022-04-30 15:51:55 -04:00
|
|
|
bot.on('ready', async () => {
|
2022-05-12 17:38:08 +03:00
|
|
|
//Make then copy the shop
|
|
|
|
|
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
|
|
|
|
client.connect(err => {
|
|
|
|
|
const shop = client.db("main").collection("shop");
|
|
|
|
|
shop.find().toArray(function(err, itemstemp) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
|
|
items = [...itemstemp];
|
|
|
|
|
|
|
|
|
|
client.close();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Note the xp numbers are a little wonky on levels 6, 8 and 13 (why though?)
|
|
|
|
|
//See https://stackoverflow.com/questions/72212928/why-are-the-differences-between-my-numbers-inconsistent-sort-of-compund-interes
|
|
|
|
|
for (let i = 1; i < 101; i ++) {
|
|
|
|
|
// xp_collection.set(i, BASE_LVL_XP * .1);
|
|
|
|
|
let amount = BASE_LVL_XP * (Math.ceil(Math.pow((1.1), (2 * i))) + i);
|
|
|
|
|
xp_collection.set(i+1, amount);
|
|
|
|
|
}
|
2022-04-17 08:51:30 -04:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
|
|
|
|
|
//Reaction map area
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
//Check if the user has sufficient permission
|
|
|
|
|
//Performes the command
|
2022-05-13 12:14:24 +03:00
|
|
|
//Anime uses if/else, all else uses switch (can't make a multi-case case)
|
|
|
|
|
if (command.indexOf('anime') != -1) {
|
|
|
|
|
bot.commands.get('ANIME').execute(command, message, args, bot);
|
|
|
|
|
} else if (command.indexOf('MANGA')) {
|
|
|
|
|
//Do nothing for now
|
|
|
|
|
} else {
|
|
|
|
|
switch(command) {
|
|
|
|
|
case 'test': bot.commands.get('Hello World').execute(message, args);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'profile': bot.commands.get('profile').execute(message, args, Discord);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'links': bot.commands.get('links').execute(message, args, Discord);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'arrow': bot.commands.get('arrow').execute(message, args, Discord);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'audio': bot.commands.get('playaudio').execute(message, args, bot, Discord);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'quotes': bot.commands.get('quotes').execute(message, args, Discord, Client);
|
|
|
|
|
break;
|
2022-02-17 22:18:51 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
case 'extracredit': bot.commands.get('EC').execute(message);
|
|
|
|
|
break;
|
2022-02-17 23:37:48 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
case 'scrape': bot.commands.get('scraper').execute(message, args);
|
|
|
|
|
break;
|
2022-02-24 22:26:07 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
case 'kareoke': bot.commands.get('kareoke').execute(message, args);
|
|
|
|
|
break;
|
2022-02-24 22:26:07 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
case 'react': bot.commands.get('reaction').execute(message, args, bot);
|
|
|
|
|
break;
|
2022-03-10 20:30:03 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
case 'stocks': bot.commands.get('stocks').execute(message, args);
|
|
|
|
|
break;
|
2022-03-10 20:30:03 -05:00
|
|
|
|
2022-05-13 12:14:24 +03:00
|
|
|
default: bot.commands.get('ECON').execute(bot, message, args, command, Discord, mongouri, items, xp_collection);
|
|
|
|
|
//Removed because Heroku doesn't work with sqlite
|
|
|
|
|
//default: bot.commands.get('ECON').execute(bot, prefix, message, args, command, Users, currency);
|
|
|
|
|
}
|
2022-02-17 21:42:57 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-05-09 10:22:33 +03:00
|
|
|
//Look into integrating MySQL into SelmerBot instead of SQLite
|
2022-02-17 21:42:57 -05:00
|
|
|
|
2022-05-12 17:38:08 +03:00
|
|
|
//Last Line(s)
|
2022-05-12 17:48:49 +03:00
|
|
|
// bot.login(token);
|
2022-05-12 17:38:08 +03:00
|
|
|
|
2022-05-12 17:48:49 +03:00
|
|
|
bot.login(process.env.token);
|