From 075c3d503d96d75e85e19f6c322c46ff1839392f Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 11 May 2016 11:37:19 +0200 Subject: [PATCH] $lb command added. Lists top 10 richest people (without name atm) --- NadekoBot/Classes/DBHandler.cs | 8 +++++++ NadekoBot/Modules/Gambling/GamblingModule.cs | 22 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index caf1cd22..b87dce4f 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -176,6 +176,14 @@ Order By mp.DateAdded desc Limit 20 OFFSET ?", num * 20); } } + + internal IEnumerable GetTopRichest(int n = 10) + { + using (var conn = new SQLiteConnection(FilePath)) + { + return conn.Table().Take(n).ToList().OrderBy(cs => -cs.Value); + } + } } } diff --git a/NadekoBot/Modules/Gambling/GamblingModule.cs b/NadekoBot/Modules/Gambling/GamblingModule.cs index 24e32377..ef12919f 100644 --- a/NadekoBot/Modules/Gambling/GamblingModule.cs +++ b/NadekoBot/Modules/Gambling/GamblingModule.cs @@ -2,10 +2,12 @@ using Discord.Commands; using Discord.Modules; using NadekoBot.Classes; +using NadekoBot.DataModels; using NadekoBot.Extensions; using NadekoBot.Modules.Permissions.Classes; using System; using System.Linq; +using System.Text; using System.Threading.Tasks; namespace NadekoBot.Modules.Gambling @@ -114,6 +116,26 @@ namespace NadekoBot.Modules.Gambling await e.Channel.SendMessage($"{e.User.Mention} successfully took {amount} {NadekoBot.Config.CurrencyName}s from {mentionedUser.Mention}!").ConfigureAwait(false); }); + + cgb.CreateCommand(Prefix + "leaderboard") + .Alias(Prefix + "lb") + .Do(async e => + { + var richestTemp = DbHandler.Instance.GetTopRichest(); + var richest = richestTemp as CurrencyState[] ?? richestTemp.ToArray(); + if (richest.Length == 0) + return; + await e.Channel.SendMessage( + richest.Aggregate(new StringBuilder( +$@"```xl +┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ +┃ Id ┃ $$$ ┃ +"), + (cur, cs) => cur.AppendLine( +$@"┣━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫ +┃{cs.UserId,-18} ┃ {cs.Value,5} ┃") + ).ToString() + "┗━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```"); + }); }); }