npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-simple-economy

v2.7.0

Published

Simple and easy-to-use Discord economy module with leaderboard and wallet-bank based cash system!

Downloads

33

Readme

discord-simple-economy

Hey! This module was created for economics on Discord. If you are unfamiliar with databases or want to save some time, this module is for you!

You can start by installing this npm:

npm install discord-simple-economy --save

How it's working?

Easy and fast. Data is saved to a sqlite3 or mongodb database using quick-db. Economiy is divided into wallet and bank balance, so you have more room to act!

Simple economy system

Discord.js economy system has never been so easy to use before. discord-simple-economy supports activities such as add, set, get, subtract, reset, delete, with, dep and daily! (with, dep, reset and delete not in there already in v2.0.0...)

Introduction

To start, you need to select a driver and create a economy client with this module. It is not difficult. Example:

const Discord = require('discord.js');
const eco = require('discord-simple-economy');

const client = new Discord.Client();

(async () => {
    await eco.selectDriver("sqlite");
})(); // see 'Selecting a driver' later in this document

client.on('message', async (message) => {
    const ecoClient = new eco.guildUser(message.author, message.guild);
    //eco stuff with ecoClient with author and guild :]
});

client.login("token");
  • Note: you can use message.author.id instead of message.author in member and message.guild.id instead of message.guild in guild

Functions List

|METHOD |WALLET |BANK | |----------------|-------------------------------|-----------------------------| |add|ecoClient.add(amount, "wallet") |ecoClient.add(amount, "bank")
|set|ecoClient.set(amount, "wallet") |ecoClient.set(amount, "bank")
|subtract |ecoClient.subtract(amount, "wallet") |ecoClient.subtract(amount, "bank")
|get |ecoClient.get("wallet") |ecoClient.get("bank") | |daily |ecoClient.daily(amount, "wallet") |ecoClient.daily(amount, "bank") |

  • amount should be an number

|METHOD |USAGE | |----------------|-------------------------------| |randomNumber|eco.randomNumber(minNumber, maxNumber)| |selectDriver|eco.selectDriver(driver, options)| |all|ecoClient.all()| |lb|ecoClient.lb(type)|

Please note:

  • randomNumber and selectDriver can be used only with eco, no with ecoClient
  • To use selectDriver, see 'Selecting a driver' later in this document
  • The all() method returns all guild data (cash and daily stuff)

Examples

Add

async function add(message, amount, type){
    await ecoClient.add(amount, type);
    const amountNow = await ecoClient.get(type);
    message.reply(`You have now **${amountNow}** in *${type}*!`);
}

add(message, 100, "bank");

All

async function all() {
    const allGuildData = await ecoClient.all();
    /*
    returns:
    {
        "cash": guildUsersCashData,
        "daily": guildUsersDailyData
    }
    */
   console.log(allGuildData);
}

all();

Lb

async function lb() {
    const lb = await ecoClient.lb('wallet');
    /*
    returns sorted Array with leaderboard (if type is not provided or type=null, it's sorting by both wallet and bank values).
    [
    {
        user: 'id',
        cash: 143423432
    },
    {
        user: 'id',
        cash: 45433
    },
    {
        user: 'id',
        cash: 4353
    }
    ]
    */
   console.log(lb);
}

lb();

Daily

async function collectDaily(message, type) {
    const amount = eco.randomNumber(1,50);
    const daily = await ecoClient.daily(amount, type);
    if(daily.error == 'alreadyCollected')return message.reply("You have already collected your daily reward. Go back tommorow.");
    
    message.reply(`Success. You have now **${amount}** more cash in *${type}*!`)
}

collectDaily(message);

Get

async function get(message, type){
    const amount = await ecoClient.get(type);
    message.reply(`Your amount of *${type}* is **${amount}**.`);
}

get(message, "bank");

Random Number

const randomNumber = eco.randomNumber(1,100);

Set

async function set(message, amount, type){
    await ecoClient.set(amount, type);
    message.reply(`Success. Your amount of cash in *${type}* is now **${amount}**.`);
}

set(message, 60, "bank");

Subtract

async function subtract(message, amount, type){
    await ecoClient.subtract(amount, type);
    const amountNow = await ecoClient.get(type);
    message.reply(`Successfully subtracted **${amount}** from *${type}*. You have now *${amountNow}* left in there.`);
}

subtract(message, 10, "wallet");

Selecting a driver

Since 2.7.0, you need to select the driver used to store data, select mongodb or sqlite via selectDriver:

await eco.selectDriver("mongodb", { mongoUri: "mongodb://user:pass@localhost" }); //mongodb
await eco.selectDriver("sqlite") // sqlite

Notes:

  • selectDriver is exposed directly, you don't need to call ecoClient
  • selectDriver is asynchronous

Need help?

Join our Discord Support Server!