README
THIS PACKAGE IS IN BETA VERSION USE AT YOUR OWN RISK
What is 'mysq-glob-economy'
It is a global economy package that allows you to create, delete, edit data for the user and much more
Why mysql-glob-economy?
- Easy to use
- Uses MySQL database which is 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 mysq database
const { setDatabase } = require("mysq-glob-economy"); //requireing the package
var dbOptions = {
host: 'localhost', // location of your mysql database host
user: 'root', // Login to your mysql database
pass: '1234QWERTY', // Password to your mysql database
database: 'mysql-glob-economy', //Optional field with name of your database
}
setDataBase(dbOptions);
Fill up dbOptions
with your mysql database credentials and settings
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 message event.
Following example assumes that you are able to write asynchronous code (the one using async/await
).
- Increasing the value of bank limit by a bit each time the author sends a message
const { findUser, createProfile, incBankLimit } = require("mysql-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) return await incBankLimit(message.author.id, randomValue); //using the function to inc bank limit
});
- Bal command
const {
findUser,
getBalance,
} = require("mysql-glob-economy");
const Discord = require("discord.js");
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, create one to start earning currency");
const userData = await getBalance(target.id);
const embed = new Discord.MessageEmbed()
.setTitle("Balance")
.addFields(
{
name: "wallet",
value: userData,
},
{
name: "bank",
value: bankCoins + "/" + bankLimit,
}
);
message.channel.send(embed);
Time for you to get creative
Functions
In the following list of functions < >
are used for mandatory parameters and [ ]
are used for optional parameters
setDataBase
Function used to create pool with database connections
economy.setDataBase(<dbOptions: object>);
generateTables
Function that generates tables if they do not exist, run with setDataBase
economy.genTable([tableName: string])
dropTables
Function that removes tables if they do exist, suggested is to use generateTables afterwards as no Table will cause errors
!!! USE WITH CAUTION !!!
economy.dropTable([tableName: string])
findUser
Function to check if there is an entry with that user
eceonomy.findUser(<userID: string>);
createProfile
Function to create user profile
economy.createProfile(<userID: string>);
deleteProfile
Function to delete user profile
economy.deleteProfile(<userID: string>)
getBalance
Function that gets user data such such as pocket or bank balance, alongside with bank limit
economy.getBalance(<userID: string>)
updateUserData
Function that updates user data such such as pocket or bank balance, alongside with bank limit
Action | Other Accepted Values | Effect |
---|---|---|
Increase | 1, increase, add, inc, gain, growth, profit, accession | Increases by submitted value |
Decrease | 2, decrease, remove, substract, sub, dec, rem, reduction, reduce, red | Substracts by submitted value |
economy.updateUserData(<userID: string>, )