ranking() declares a ranking, from any file of src/, and the name of its export is the name of the ranking. It takes an object, RankingConfig, or nothing.
src/levels/best.ts
How to use a ranking, and where its scores are, is in the guide. This page lists what exists.
ranking()
src/: the name of the export is the name of the ranking. Per server unless scope: 'global' is given, the highest score first unless order: 'lowest' is.
RankingConfig
What a file gives toranking().
'guild' (the default): a ranking per server, and a function that runs in a server reads and writes the ranking of that server, with nothing to say. 'global': one ranking for the whole bot.Where the scores are kept:
'file' (the default), a file in the data/ folder of the project, or 'redis', the Redis of REDIS_URL in .env, where a ranking is a sorted set.Which end comes first:
'highest' (the default), the highest score first, or 'lowest', the lowest first (a time, a number of tries).RankingOrder
StoreScope and StoreStorage are the ones of store().
Ranking
Whatranking() returns: a declaration the framework finds in the exports of a file. It is a ScopedRanking for the server the code runs in, plus:
in()
ScopedRanking
A ranking, for one server or for the whole bot.add()
points (negative to take away) to the score of id, starting from 0, in one go: nothing added meanwhile is lost, even by another process. Resolves with the new score.
set()
id, whatever it was.
score()
id, or undefined when it has none.
rankOf()
id is, from 1, or undefined when it has no score.
top()
count (10 by default) members, after skipping skip (0 by default): top(10, 10) is the second page.
remove()
id. true when it had one.
size()
clear()
RankingEntry
A member of a ranking, astop() lists them.
Where the scores live
Withstorage: 'file', one entry per member in data/<name>.json, written like the entries of a store ([[server id, member id], score, null]). top(), rankOf() and size() put every score of the server in order on each call; add() is an update of the entry, in one go.
With storage: 'redis', one sorted set per server: <name>:<server id>, <name> for a global ranking, dev: in front in chapterjs dev. add() is ZINCRBY, set() ZADD, score() ZSCORE, rankOf() ZREVRANK (ZRANK for order: 'lowest'), top() ZREVRANGE … WITHSCORES (ZRANGE), remove() ZREM, size() ZCARD, clear() DEL.
Equal scores are ordered by the bytes of their id, as Redis does: in reverse for the highest first. Both storages give the same order.