coins-manager
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

coins-manager

Source code of coins manager

This manager can be configured for a global usage or to split economy servers.

Important

This manager works with MySQL.

Documentation

Here is how to use the manager

First install the package (yarn add coins-manager, npm i coins-manager or pnpm add coins-manager)

Typescript initialisation

import { CoinsManager } from 'coins-manager';
import { createConnection } from 'mysql';

const database = createConnection({/* database informations */})

const manager = new CoinsManager<'global' | 'multiguild'>(database, {
    options: 'global' | 'multiguild'
});
manager.start();

Javascript initialisation

const { CoinsManager } = require('coins-manager');
const { createConnection } = require('mysql');

const database = createConnection({/* database informations */})

const manager = new CoinsManager<'global' | 'multiguild'>(database, {
    options: 'global' | 'multiguild'
});
manager.start();

Returns

The manager return this format :

{
    coins: number;
    bank: number;
    user_id: string;
}

And if it's set to a multiguild usage :

{
    guild_id: string;
    user_id: string;
    coins: number;
    bank: number;
}

Methods

Here are the documentation for the methods

Remember that if you set it on a multiguild usage, it will require a guild_id parameter

Add Coins

Add coins to an user

manager.addCoins({
    user_id: '1234',
    coins: 100
    // Optional guild_id: '4321' value is required for a multiguild usage
});

Remove Coins

Remove coins to an user

manager.removeCoins({
    user_id: '1234',
    coins: 100
    // Optional guild_id: '4321' value is required for a multiguild usage
});

Add bank

Add bank amount to an user

manager.addBank({
    user_id: '1234',
    bank: 100
    // Optional guild_id: '4321' value is required for a multiguild usage
});

Remove bank

Remove coins in bank from an user

manager.removeBank({
    user_id: '1234',
    bank: 100
    // Optional guild_id: '4321' value is required for a multiguild usage
});

Get leaderboard

This method returns the leaderboard of coins + bank

manager.getLeaderboard();

If you set it to a multiguild usage, you can add guild_id parameter to get the leaderboard of a specific server

manager.getLeaderboard('4321');

Get Data

Get the data of an user

manager.getData({
    user_id: '1324'
});

If you set it to a multiguild usage, you have to add the guild_id paramter :

manager.getData({
    user_id: '1324',
    guild_id: '4321'
});

Get Code

The manager's cache works with a code system, in a global usage it's just the user ID, but if you set it to a multiguild usage, you maybe want to get the code of the user, so use :

manager.getCode({
    user_id: '1234'
})

And for multiguild usage :

manager.getCode({
    user_id: '1324',
    guild_id: '4321'
});

Has Account

This method is used to know if a user is in the database

manager.hasAccount({
    user_id: '1324'
});
// Boolean

And on a multiguild usage :

manager.hasAccount({
    user_id: '1234',
    guild_id: '4321'
});
// Boolean

Propreties

Here are the proprety of the manager : array

This get method returns you an array with all the returns data

Readme

Keywords

Package Sidebar

Install

npm i coins-manager

Weekly Downloads

4

Version

1.0.7

License

MIT

Unpacked Size

10.6 kB

Total Files

8

Last publish

Collaborators

  • greenskywastaken