Bots Home
|
Create an App
Cassie's Leaderboard
Author:
cassie
Description
Source Code
Launch Bot
Current Users
Created by:
Cassie
class Leaderboard { constructor() { this.users = {}; } recordTip(user, amount) { const oldAmount = this.users[user] || 0; this.users[user] = oldAmount + amount; } getLeaders(max = 10) { const e = Object.entries(this.users); e.sort((a, b) => b[1] - a[1]); return e.slice(0, max).map(e => ({'user': e[0], 'amount': e[1]})); } } class LeaderboardPrinter { constructor(numLeaders = 10) { this.numLeaders = numLeaders; } print(board) { const leaders = board.getLeaders(this.numLeaders); this.printString('### Leaders ###'); for (const [i, e] of leaders.entries()) { this.printString(`# #${i+1} ${e.user} (${e.amount})`); } this.printString('###############'); } printString(str) { //console.log(str); cb.chatNotice(str); } } cb.settings_choices = [] const board = new Leaderboard(); const boardPrinter = new LeaderboardPrinter(); cb.onTip(tip => { //cb.chatNotice(tip); board.recordTip(tip['from_user'], tip['amount']); boardPrinter.print(board); }); const value = 'haha'; cb.chatNotice(`backtick: ${value}`);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.