From b73b670f6f5950af645655e1d8282296dc683cac Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 6 Feb 2017 08:35:45 +0100 Subject: [PATCH] .shardstats improved --- src/NadekoBot/Modules/Utility/Utility.cs | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 035acf74..7f002e1f 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -312,23 +312,32 @@ namespace NadekoBot.Modules.Utility [NadekoCommand, Usage, Description, Aliases] public async Task ShardStats(int page = 1) { - page -= 1; - if (page < 0) + if (page < 1) return; - var shards = NadekoBot.Client.Shards.Skip(page * 25).Take(25); + var status = string.Join(", ", NadekoBot.Client.Shards.GroupBy(x => x.ConnectionState) + .Select(x => $"{x.Count()} shards {x.Key}") + .ToArray()); - var info = string.Join("\n", - shards.Select(x => $"Shard **#{x.ShardId.ToString()}** is in {Format.Bold(x.ConnectionState.ToString())} state with {Format.Bold(x.Guilds.Count.ToString())} servers")); + var allShardStrings = NadekoBot.Client.Shards + .Select(x => $"Shard **#{x.ShardId.ToString()}** is in {Format.Bold(x.ConnectionState.ToString())} state with {Format.Bold(x.Guilds.Count.ToString())} servers") + .ToArray(); - if (string.IsNullOrWhiteSpace(info)) - info = "No shard stats on this page."; - await Context.Channel.EmbedAsync(new EmbedBuilder() - .WithOkColor() - .WithTitle("Shard Stats - page " + (page + 1)) - .WithDescription(info)) - .ConfigureAwait(false); + + await Context.Channel.SendPaginatedConfirmAsync(page, (curPage) => { + + var str = string.Join("\n", allShardStrings.Skip(25 * (curPage - 1)).Take(25)); + + if (string.IsNullOrWhiteSpace(str)) + str = "No shards on this page."; + + return new EmbedBuilder() + .WithAuthor(a => a.WithName("Shard Stats")) + .WithTitle(status) + .WithOkColor() + .WithDescription(str); + }, allShardStrings.Length / 25); } [NadekoCommand, Usage, Description, Aliases]