telegraf-xp

1.5.0 • Public • Published

telegraf-xp

  • A lightweight and easy to use xp framework for Telegraf, uses MongoDB.

  • If you encounter any of those fell free to open an issue in our github repository.

  • یک پکیج واسه امتیاز و رتبه بندیه که میتونین تو ربات های تلگرامیتون استفاده کنید

Download & Update

You can download it from npm:

npm i telegraf-xp

You can update to a newer version to receive updates using npm.

npm update telegraf-xp

Changelog

  • 25 February 2021 (v1.1.8) - Preventing further deprection warnings to be displayed, if you encounter any of these deprecation issues, update the module.

  • 22 November 2020 (v1.1.7) WARNING: This semi-major version contains breaking changes in the way leaderboard computing function works.

  1. Added an optional fetchPosition argument to the Levels.fetch which will add the leaderboard rank as the position property. Caution: Will be slower on larger servers.
  2. Levels.computeLeaderboard is now asynchronous and can take in a third parameter called fetchUsers which will fetch all users on the leaderboard. This parameter does not require additional Gateway Intents. Caution: Will be substantially slower if you do not have Group_Members intent and catch some users beforehand.
  • 16 July 2020 - Added xpFor method to calculate xp required for a specific level.
/* xpFor Example */
const Levels = require("telegraf-xp");
// Returns the xp required to reach level 30.
var xpRequired = Levels.xpFor(30);

console.log(xpRequired); // Output: 90000

Setting Up

First things first, we include the module into the project.

const Levels = require("telegraf-xp");

After that, you need to provide a valid mongo database url, and set it. You can do so by:

Levels.setURL("mongodb://..."); // You only need to do this ONCE per process.

Examples

Examples can be found in /test

Methods

createUser

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

Levels.createUser(<UserID - String>, <chatID - String>);
  • Output:
Promise<Object>

deleteUser

If the entry exists, it deletes it from database.

Levels.deleteUser(<UserID - String>, <chatID - String>);
  • Output:
Promise<Object>

appendXp

It adds a specified amount of xp to the current amount of xp for that user, in that Group. It re-calculates the level. It creates a new user with that amount of xp, if there is no entry for that user.

Levels.appendXp(<UserID - String>, <chatID - String>, <Amount - Integer>);
  • Output:
Promise<Boolean>

appendLevel

It adds a specified amount of levels to current amount, re-calculates and sets the xp reqired to reach the new amount of levels.

Levels.appendLevel(<UserID - String>, <chatID - String>, <Amount - Integer>);
  • Output:
Promise<Boolean/Object>

setXp

It sets the xp to a specified amount and re-calculates the level.

Levels.setXp(<UserID - String>, <chatID - String>, <Amount - Integer>);
  • Output:
Promise<Boolean/Object>

setLevel

Calculates the xp required to reach a specified level and updates it.

Levels.setLevel(<UserID - String>, <chatID - String>, <Amount - Integer>);
  • Output:
Promise<Boolean/Object>

fetch (Updated recently!)

Retrives selected entry from the database, if it exists.

Levels.fetch(<UserID - String>, <chatID - String>, <FetchPosition - Boolean>);
  • Output:
Promise<Object>

subtractXp

It removes a specified amount of xp to the current amount of xp for that user, in that Group. It re-calculates the level.

Levels.subtractXp(<UserID - String>, <chatID - String>, <Amount - Integer>);
  • Output:
Promise<Boolean/Object>

subtractLevel

It removes a specified amount of levels to current amount, re-calculates and sets the xp reqired to reach the new amount of levels.

Levels.subtractLevel(<UserID - String>, <chatID - String>, <Amount - Number>);
  • Output:
Promise<Boolean/Object>

fetchLeaderboard

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

Levels.fetchLeaderboard(<chatID - String>, <Limit - Integer>);
  • Output:
Promise<Array [Objects]>

computeLeaderboard (Updated recently!)

It returns a new array of object that include level, xp, Group id, user id, leaderboard position, username and discriminator.

Levels.computeLeaderboard(<Client - telegraf.js Client>, <Leaderboard - fetchLeaderboard output>, <fetchUsers - boolean, disabled by default>);
  • Output:
Promise<Array [Objects]>

xpFor

It returns a number that indicates amount of xp required to reach a level based on the input.

Levels.xpFor(<TargetLevel - Integer>);
  • Output:
Integer

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.5.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.5.01
1.4.00
1.3.00

Package Sidebar

Install

npm i telegraf-xp

Weekly Downloads

1

Version

1.5.0

License

ISC

Unpacked Size

17.5 kB

Total Files

4

Last publish

Collaborators

  • sajjadmrx