Inventory update, added the 'buy', 'shop', 'work', 'rank', and 'inventory' commands

This commit is contained in:
ION606
2022-05-12 17:38:08 +03:00
parent 6b0abdb65a
commit bb1db36473
9 changed files with 970 additions and 24 deletions
+58 -15
View File
@@ -1,5 +1,10 @@
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
const { MongoClient, ServerApiVersion } = require('mongodb');
const fs = require('fs');
const { exit } = require('process');
const BASE_LVL_XP = 20;
// const { token } = require('./config.json');
//Heroku part
// const { token } = process.env.token;
@@ -17,10 +22,27 @@ const prefix = '/';
//MongoDB integration
const uri = process.env.MONGODB_URI;
const mongouri = "mongodb+srv://discordbot:Nivi8395@bot.t5ghb.mongodb.net/myFirstDatabase?retryWrites=true";//process.env.MONGODB_URI;
const GuildModel = require('./commands/inventory/models/guild');
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'; });
const fs = require('fs');
const { exit } = require('process');
bot.commands = new Discord.Collection();
bot.commNames = new Discord.Collection();
@@ -40,25 +62,44 @@ for (const file of commandFiles) {
i ++;
}
// const econFiles = fs.readdirSync('./commands/currency').filter(file => file.endsWith('.js'));;
// const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));;
// ECON SECTION
// bot.commands.set('ECON', require(`./commands/currency/app.js`));
bot.commands.set('ECON', require(`./commands/inventory/models/app`));
// const currency = new Discord.Collection();
// const { Users } = require('./commands/currency/dbObjects.js');
// i++;
bot.commNames.set('length', i);
//XP Table section
let xp_collection = new Map();
let items;
bot.on('ready', async () => {
// bot.once('ready', async () => {
// Another Econ Section
// const storedBalances = await Users.findAll();
// storedBalances.forEach(b => currency.set(b.user_id, b));
//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();
});
});
//XP section (start at 2 bc you're already at lvl 1)
//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);
}
// console.log(`Logged in as ${bot.user.tag}!`);
console.log('SLEEMER BOT ONLINE!!!!! OH MY GOD OH MY GOD!!!');
console.log("Look into integrating MySQL into SelmerBot instead of SQLite");
});
@@ -69,7 +110,6 @@ bot.on('messageCreate', (message) => {
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
//Check if the user has sufficient permission
//Performes the command
@@ -101,7 +141,7 @@ bot.on('messageCreate', (message) => {
case 'kareoke': bot.commands.get('kareoke').execute(message, args);
break;
default: message.channel.send("'" + message.content + "' is not a command!");
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);
}
@@ -109,5 +149,8 @@ bot.on('messageCreate', (message) => {
//Look into integrating MySQL into SelmerBot instead of SQLite
//Last Line
bot.login(process.env.token);
//Last Line(s)
const { token } = require('./config.json');
bot.login(token);
// bot.login(process.env.token);