agenthyped-simulation

1.2.0 • Public • Published

Introducing "Simulation" a NPM package for economy

DISCLAIMER! THIS PROJECT IS STILL IN DEVELOPMENT. USE AT YOUR OWN RISK

Welcome to Simulation, the global economy package specifically targeted for use with Discord bots. The most important thing to remember about Simulation is that it is a 'global' economy system. What does this mean? this means that no matter what Discord server you are in progression will always roll over and all users can access anything from any server at anytime. At this moment Simulation does not include nor support per guild economy progression yet, this feature may come as a seperate NPM package as I have no idea whether it's possible to include this in this current package due to how different the code is.

Installation

To download the package just do:

npm i agenthyped-simulation

If any updates are released just do:

npm update agenthyped-simulation

How to get started

First lets start of with the mandatory things. Include the module into your project.

const Simulation = require('agenthyped-simulation');

Next you must provide a valid mongoDB url, as this module uses mongoDB to store data.

Simulation.mongoURL("YOUR MONGODB CONNECTION STRING");

Functions

Before looking at the functions note you can always add a custom error message that is returned when using these functions. For example, if the daily functions returns the string "Daily cooldown has not expired yet." you can add a check to be able to send your own custom response.

const dailyReward = await Simulation.daily(UserId, IncomeThreshold)

if (dailyReward === "Daily cooldown has not expired yet.") {
    return `Your own response message or custom coding here.` // This will return any code that you put in this block if the daily function is on cooldown
} else {
    return dailyReward // And this will return the amount the user earned if the cooldown is expired
}

balance

Check the balance of a user.

const balance = await Simulation.balance(UserId)

console.log(balance) // Returns the amount you have stored in the database

affixMoney

Add money to someones bank account.

Simulation.affixMoney(UserId, Money)

daily

Recieve a random amount of money between 1 and the income threshold that is set, you can set the income threshold as high as you want.

const dailyReward = await Simulation.daily(UserId, IncomeThreshold)

console.log(dailyReward) // Returns either the amount that is earned, or a cooldown message.

removeMoney

Remove money from a users bank account.

Simulation.removeMoney(UserId, Money)

/*
 For future reference you can just use the affixMoney function to remove money, for example doing this "-200".
 But this function is here if anyone needs it anyway.
/

createUser

Creates a user in the database by providing the ID of the user.

Simulation.createUser(UserId) // Creates a document in the database tailored to the chosen user. You have to make sure you input the users id otherwise it will fail

deleteUser

Deletes a user in the database by providing an ID of the user.

Simulation.deleteUser(UserId) // This does the complete opposite of what is explained in the createUser function.

leaderboard

Displays a top 10 leaderboard of users who have the most money.

const leaderboard = await Simulation.leaderboard()

console.log(leaderboard) // Returns the top 10 users with the most money in the database.

giveMoney

Send money to another users bank account.

Simulation.giveMoney(UserId, UserIdSec, Money) // The first parameter is the user thats giving the money. The second parameter is the user that will receive it.

doubleOrNothing

A simple game where the user can place a bet with a chosen amount of money, if the user loses they lose the amount of money they bet, if they win they get the amount of money they bet.

const game = await Simulation.doubleOrNothing(UserId, Money)
// When this is ran, it will return either strings "You win." or "You lost.". You can use these to setup your custom messages.

inventory

Grab anything that is in a users inventory from the database.

const inventory = await Simulation.inventory(UserId)
console.log(inventory) // Returns either the items in the inventory or "No such user found in the database." and "You do not own anything." if there is nothing in the database.

purchase

Puts the item set in the parameter into the database. Also takes the amount set in the parameters and subtracts it from the users money.

const purchase = await Simulation.purchase(UserId, Item, ItemPrice) // Can return the message "You do not have enough money." if the amount of money in the users account is not enough

gather

Grab information on a users profile from the database.

const profile = await Simulation.gather(UserId)

console.log(profile) // This will return a users document from the database which you can then use to access any information you need.

// For example you can do this

profile.Money // This will return there amount of money
profile.CooldownExpires // This will return the date there cooldown expires, it will be in the format of a javascript "new Date()" variable

// You get the gist

Package Sidebar

Install

npm i agenthyped-simulation

Weekly Downloads

4

Version

1.2.0

License

ISC

Unpacked Size

16.7 kB

Total Files

4

Last publish

Collaborators

  • agenthyped