Implement wordbot leaderboard command

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-07-02 16:35:19 -07:00
parent 7f8a886550
commit 0c15496579

View File

@@ -10,7 +10,13 @@ defmodule Omnibot.Contrib.Wordbot.Bot do
## Bot commands ## Bot commands
command "!wordbot", ["leaderboard"] do command "!wordbot", ["leaderboard"] do
Irc.send_to(irc, channel, "leaderboard logic here") Wordbot.Db.leaderboard(channel)
|> Enum.sort_by(& &1.score)
|> Enum.reverse()
|> Enum.take(5)
|> Enum.with_index()
|> Enum.map(fn {%{user: nick, score: score}, rank} -> "#{rank + 1}. #{nick}. #{score}" end)
|> Enum.each(&Irc.send_to(irc, channel, &1))
end end
## Client API ## Client API