diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index ce1644f..2dbb827 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; +using System.Text; using System.Threading.Tasks; +using System.Linq; using Discord; using Discord.Commands; using Geekbot.net.Lib; @@ -59,6 +62,38 @@ namespace Geekbot.net.Modules await ReplyAsync("", false, eb.Build()); } - + [Alias("highscore")] + [Command("rank", RunMode = RunMode.Async), Summary("get user top 10")] + public async Task Rank() + { + await ReplyAsync("this will take a moment..."); + var guildKey = Context.Guild.Id.ToString(); + var guildMessages = (int)redis.Client.StringGet(guildKey + "-messages"); + var allGuildUsers = await Context.Guild.GetUsersAsync(); + var unsortedDict = new Dictionary(); + foreach(var user in allGuildUsers) + { + var key = Context.Guild.Id + "-" + user.Id; + var messages = (int)redis.Client.StringGet(key + "-messages"); + if(messages > 0) { + unsortedDict.Add($"{user.Username}#{user.Discriminator}", messages); + } + } + var sortedDict = unsortedDict.OrderByDescending(x => x.Value); + var reply = new StringBuilder(); + reply.AppendLine($"Total Messages on {Context.Guild.Name}: {guildMessages}"); + var count = 1; + foreach(KeyValuePair entry in sortedDict) + { + if(count < 11){ + var percent = Math.Round((double)(100 * entry.Value) / guildMessages, 2); + reply.AppendLine($"#{count} - **{entry.Key}** - {percent}% of total - {entry.Value} messages"); + count++; + } else { + break; + } + } + await ReplyAsync(reply.ToString()); + } } } \ No newline at end of file diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index cc33b50..cf0487c 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -103,44 +103,28 @@ namespace Geekbot.net return true; } - public async Task Reconnect(Exception exception) - { - Console.WriteLine("========================================="); - Console.WriteLine("Geekbot Disconnected from the Discord Gateway..."); - Console.WriteLine(exception.Message); - Console.WriteLine("Attempting Reconnect..."); - Console.WriteLine("========================================="); - await client.StopAsync(); - System.Threading.Thread.Sleep(10000); - await Login(); - } - - public async Task FinishStartup() - { - - } - public async Task HandleCommand(SocketMessage messageParam) { var message = messageParam as SocketUserMessage; if (message == null) return; if (message.Author.IsBot) return; int argPos = 0; - if (message.ToString().ToLower().StartsWith("ping")) + var lowCaseMsg = message.ToString().ToLower(); + if (lowCaseMsg.StartsWith("ping")) { await message.Channel.SendMessageAsync("pong"); return; } - if (message.ToString().ToLower().StartsWith("hui")) + if (lowCaseMsg.StartsWith("hui")) { await message.Channel.SendMessageAsync("hui!!!"); return; } - if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype")) - { - await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ"); - return; - } + // if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype")) + // { + // await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ"); + // return; + // } if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; var context = new CommandContext(client, message); Task.Run(async () => await commands.ExecuteAsync(context, argPos, map));