mongo-glob-economy

A easy to use npm economy package

Usage no npm install needed!

<script type="module">
  import mongoGlobEconomy from 'https://cdn.skypack.dev/mongo-glob-economy';
</script>

README

What is 'mongo-glob-economy'

It is a global economy package that allows you to create, delete, edit data for the user and much more

Why mongo-glob-economy?

  • Easy to use
  • Uses mongo databases which are encrypted
  • Provides a global economy system
  • Has a bank system
  • Has a bank limit

Setting up

Here is the basic code to connect to your mongo database

const { setURL } = require("mongo-glob-economy"); //requireing the package

setURL("mongodb://localhost/quickmongo"); //The mongo database url

but instead of mongodb://localhost/quickmongo you would provide your actual mongo database url

Examples

Examples assume that you have setted up the module as presented in 'Setting Up' section. Following examples assume that your Discord.Client is called client.

Following examples assume that your client.on("message", message is called message.

Following example contains isolated code which you need to integrate in your own command handler.

Following example assumes that you are able to write asynchronous code (use await).

  • Increasing the value of bank limit by a bit each time the author sends a message
const { findUser, createProfile, incBankLimit } = require("mongo-glob-economy");

client.on("message", async (message) => {
  if (!message.guild) return;
  if (message.author.bot) return;

  const randomValue = Math.floor(Math.random() * 9) + 1; // Min 1, Max 10
  const user = await findUser(message.author.id);
  if (!user) return await createProfile(message.author.id); //using this function to create the profile if one dosnt have 1 alredy

  if (user) await incBankLimit(message.author.id, randomValue); //using the function to inc bank limit
});
  • Bal command
const {
  findUser,
  getCoinsInWallet,
  getCoinsInBank,
  getBankLimit,
} = require("mongo-glob-economy");
const Discord = require("discord.js");

//from here starts the actual code
const target = message.mentions.members.first() || message.member;
const user = await findUser(target.id);

if (!user) return message.channel.send("You dont have a profile");

const coins = await getCoinsInWallet(target.id);
const bankCoins = await getCoinsInBank(target.id);
const bankLimit = await getBankLimit(target.id);

const embed = new Discord.MessageEmbed().setTitle("Balance").addFields(
  {
    name: "wallet",
    value: coins,
  },
  {
    name: "bank",
    value: bankCoins + "/" + bankLimit,
  }
);

message.channel.send(embed);

Time for you to get creative

Functions

setURL

setURL(<dbUrl: string>);

This is used to connect to the database

findUser

findUser(<userID: string>);

This is used to find if there is an entry in the db for a certain user

createProfile

createProfile(<userID: string>);

This is used to create a profile if the user dosnt have one alredy

deleteProfile

deleteProfile(<userID: string>)

This is used to delete profile of the user if they have one

getCoinsInWallet

getCoinsInWallet(<userID: string>)

This is used to get the value of coins for the target

incCoinsInWallet

incCoinsInWallet(<userID: string>, <coins: Number>)

This is used to increase the value of coins for the target

decCoinsInWallet

decCoinsInWallet(<userID: string>, <coins: Number>)

This is used to decrease the value of coins for the target

getCoinsInBank

getCoinsInBank(<userID: string>)

This is used to get the value of bank for the target

incCoinsInBank

incCoinsInBank(<userID: string>, <coins: Number>)

This is used to increase the value of bank for the target

decCoinsInBank

decCoinsInBank(<userID: string>, <coins: Number>)

This is used to decrease the value of bank for the target

getBankLimit

getBankLimit(<userID: string>)

This is used to get the value of banklimit for the target

incBankLimit

incBankLimit(<userID: string>, <value: Number>)

This is used to increase the value of banklimit for the target

decBankLimit

decBankLimit(<userID: string>, <value: Number>)

This is used to decrease the value of banklimit for the target