Node.js ReplDB Leaderboard
h
1Mage (0)

I'm just wondering if you can create a ReplDB Leaderoard in Node.js.

I understand how to make use the ReplDB but don't know how to make a Leaderboard.

Can anyone help me?

You are viewing a single comment. View All
EpicGamer007 (1755)

@ICUP3339 This is an example leaderboard:

RandomUser#0001=310
RandomUser#0002=994
RandomUser#0003=58
RandomUser#0004=411
etc.

Or if you use the db for more than the leaderboard, you can make it something like

leaderboard={"RandomUser#0002": 914, "RandomUser#0001": 414, [etc]}

For the first example, you can do something like:

bot.on("message", (message) => {
  if(message.text == botPrefix + "gainMoney") {

     if(db.get(message.sender) {
        db.set(message.sender, db.get(message.sender) + 1)
     } else {
        db.set(message.sender, 1)
     }

  }
});

// This aint perfect code obv

and for the second way

bot.on("message", (message) => {
  if(message.text == botPrefix + "gainMoney") {

     if(JSON.parse(db.get("leaderboard")).containsKey(message.sender)) {
      const thing = JSON.parse(db.get("leaderboard"));
      thing[message.sender] = thing[message.sender] + 1;
      db.set("leaderboard", JSON.stringify(thing));
    } else {
       const thing = JSON.parse(db.get("leaderboard"));
       thing[message.sender] = 1;
       db.set("leaderboard", JSON.stringify(thing));
    }

  }
});

// This aint perfect code either

this is not perfect code, but you should be able to get the concept of what to do.