From 0c15496579d1b01c802bc7a6f2f3399ee4325a91 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 2 Jul 2020 16:35:19 -0700 Subject: [PATCH] Implement wordbot leaderboard command Signed-off-by: Alek Ratzloff --- lib/contrib/wordbot/bot.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/contrib/wordbot/bot.ex b/lib/contrib/wordbot/bot.ex index 94237a7..344d484 100644 --- a/lib/contrib/wordbot/bot.ex +++ b/lib/contrib/wordbot/bot.ex @@ -10,7 +10,13 @@ defmodule Omnibot.Contrib.Wordbot.Bot do ## Bot commands 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 ## Client API