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

easy-discord-economy

v1.1.6

Published

A discord economy package that use mongo database for beginner

Downloads

33

Readme

Installation

With npm

npm i easy-discord-economy

With yarn

yarn add easy-discord-economy

Documentation

Settings

We need to include the module to our project

const Eco = require('easy-discord-economy');

And set the mongodb url

Eco.setUrl('mongodb://...'); //You only need to set this up once

Methods

createUser

Creates an entry in database for that user if it doesnt exist.

Eco.createUser(userId: string, guildId: string);
  • Output:
Promise<Object>

deleteUser

If the entry exists, it deletes it from database.

Eco.deleteUser(userId: string, guildId: string);
  • Output:
Promise<Object>

add

Add a specific amount of money to wallet or bank in the database

Eco.add(userId: string, guildId: string, amount: number);
  • Output:
Promise<Boolean>

subtract

Subtract specific amount of money in wallet or bank in the database

Eco.subtract(userId: string, guildId: string, amount: number);
  • Output:
Promise<Boolean>

setMoney

Set a specific amount of money for a user

Eco.setMoney(userId: string, guildId: string, amount: number);
  • Output:
Promise<Boolean/Object>

setBank

Set a specific amount of money for a user

Eco.setBank(userId: string, guildId: string, amount: number);
  • Output:
Promise<Boolean/Object>

fetch

Retrives selected entry from the database, if it exists.

Eco.fetch(userId: string, (guildId: string);
  • Output:
Promise<Object>

fetchLeaderboard

It gets a specified amount of entries from the database, ordered from higgest to lowest within the specified limit of entries.

Eco.fetchLeaderboard(guildId: string, limit: number);
  • Output:
Promise<Array [Objects]>

computeLeaderboard

It returns a new array of object that include money, bank, guild id, user id, leaderboard position, username and discriminator.

Eco.computeLeaderboard(client: Your discord client, guildId: string);
// Yes ik i borrowed some code from https://github.com/MrAugu/discord-xp
  • Output:
Promise<Array [Objects]>

work

A built in work command kinda useless :l

Eco.work(userId: string, guildId: string);
  • Output:
Promise<Boolean>

deleteAll

Delete all data from current guild

Eco.deleteAll(guild: string);
  • Output:
Promise<Boolean>

Example

const { Client } = require('discord.js')
const Eco = require('easy-discord-economy');

const client = new Client()

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}`)
})

client.on('message' async message => {
    const args = message.content
    .slice('eco '.length),
    .trim()
    .split(/ +/g)

    const command = args
    .shift()
    .toLowerCase()

    switch (command) {
        case 'addmoney':
            const user = message.mentions.users.first();
            const amount = args[0];
            if (!user) return message.channel.send('You need to mentions a user first.')
            if (!amount) return message.channel.send('You need to provide an amount to add.')
            await Eco.add(user.id, message.guild.id, amount) // Add money the user data.

            return message.channel.send(`Added ${amount} coins in ${user} wallet.`)

        case 'deposit':
            const money = args[0]
            await Eco.add(user.id, message.guild.id, money, 'bank') // Add money to the bank
            await Eco.subtract(user.id, message.guild.id, money) // Remove money from the bank.
            return message.channel.send(`Successfully deposited ${amount} coins to the bank.`)

        case 'withdraw':
            const withdraw = args[0]
            await Eco.subtract(user.id, message.guild.id, money, 'bank') // Remove money from the bank.
            await Eco.add(user.id, message.guild.id, money) // Add the money back to wallet.
            return message.channel.send(`Successfully withdrawed ${withdraw} coins from the bank.`)

        case 'balance':
            case 'bal':
                const bal = await Eco.fetch(user, guild) // This return an object { money: amount, bank: amount }
                return message.channel.send(`**Wallet**: ${bal.money} coins.\n**Bank**: ${bal.bank} coins.`)

        default:
            return message.channel.send(`\`${command}\` is not a command.`)
    }
})

client.login('You discord token')