|
|
@@ -116,12 +116,17 @@ Question.prototype.end = function() {
|
|
|
|
|
|
const ScoreUtils = (function() {
|
|
|
const getRank = function(pseudo) {
|
|
|
+ pseudo = pseudo.toLowerCase();
|
|
|
for (var i =0, len = this.length; i < len; ++i)
|
|
|
- if (this[i].name === pseudo)
|
|
|
+ if (this[i].name.toLowerCase() === pseudo)
|
|
|
return i +1;
|
|
|
return null;
|
|
|
};
|
|
|
|
|
|
+ const withScore = function(score) {
|
|
|
+ return this.filter(i => i.score === score);
|
|
|
+ };
|
|
|
+
|
|
|
const diff = function(pseudo, pointIncrement) {
|
|
|
var oldIndex = this.getRank(pseudo) -1,
|
|
|
score = pointIncrement;
|
|
|
@@ -146,12 +151,13 @@ const ScoreUtils = (function() {
|
|
|
buildScoreArray: function(quizzBot, filter, limit) {
|
|
|
var scores = [];
|
|
|
for (var i in quizzBot.users)
|
|
|
- if (filter(i))
|
|
|
+ if (!filter || filter(i))
|
|
|
scores.push({name: quizzBot.users[i].name, score: quizzBot.users[i].score});
|
|
|
scores = scores.sort((a, b) => b.score - a.score);
|
|
|
if (limit !== undefined)
|
|
|
scores = scores.slice(0, limit);
|
|
|
scores.getRank = getRank.bind(scores);
|
|
|
+ scores.usersWithScore = withScore.bind(scores);
|
|
|
scores.diff = diff.bind(scores);
|
|
|
return scores;
|
|
|
}
|
|
|
@@ -600,10 +606,27 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
|
|
|
scores = scores.sort((a, b) => b.score - a.score);
|
|
|
this.bot.sendNotice(username, scores.map(i => i.name+":"+i.score).join(", "));
|
|
|
}
|
|
|
- else if (lmsg === "!score") {
|
|
|
- this.sendScore(true);
|
|
|
+ else if (lmsg.startsWith("!points")) {
|
|
|
+ var who = lmsg.substr("!points".length).trim().split(/\s+/)[0];
|
|
|
+ if (!who || !who.length) {
|
|
|
+ this.bot.sendMsg(this.room, "Usage: !points <pseudo>");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ who = who.trim().toLowerCase();
|
|
|
+ if (!this.users[who] || !this.users[who].score) {
|
|
|
+ this.bot.sendMsg(this.room, "Pas de points pour " +who);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var arr = ScoreUtils.buildScoreArray(this),
|
|
|
+ rank = arr.getRank(who);
|
|
|
+ var exaequo = arr.usersWithScore(arr[rank-1].score).filter(i => i.name.toLowerCase() !== who).map(i => i.name).join(", ");
|
|
|
+ exaequo = exaequo.length ? (", exaequo avec " +exaequo) : ".";
|
|
|
+ if (rank === 0)
|
|
|
+ this.bot.sendMsg(this.room, `${arr[rank-1].name} est en tête avec ${arr[rank-1].score} points${exaequo}`);
|
|
|
+ else
|
|
|
+ this.bot.sendMsg(this.room, `${arr[rank-1].name} est en ${rank}eme position avec ${arr[rank-1].score} points${exaequo}`);
|
|
|
}
|
|
|
- else if (lmsg === "!top") {
|
|
|
+ else if (lmsg === "!score" || lmsg === "!top") {
|
|
|
this.sendScore(false);
|
|
|
}
|
|
|
else if (this.currentQuestion) {
|