Bugfix in rank, updated migration script

This commit is contained in:
Runebaas 2017-09-27 23:26:32 +02:00
parent 29c181ddda
commit a4cbc03202
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
3 changed files with 26 additions and 10 deletions

View file

@ -18,7 +18,7 @@ namespace Geekbot.net.Lib
public void HandleCommandException(Exception e, ICommandContext Context)
{
var errorMsg =
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\"";
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\", complete message was \"{Context.Message}\"";
logger.Error(e, errorMsg);
// await botOwnerDmChannel.SendMessageAsync($"{errorMsg}```{e.StackTrace}```");
// await Context.Channel.SendMessageAsync("Something went wrong...");

View file

@ -1,5 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using Discord;
@ -70,19 +73,33 @@ namespace Geekbot.net.Modules
try
{
var messageList = redis.HashGetAll($"{Context.Guild.Id}:Messages");
var sortedList = messageList.OrderByDescending(e => e.Value).ToList().Take(11).ToList();
var sortedList = messageList.OrderByDescending(e => e.Value).ToList();
var guildMessages = (int) sortedList.First().Value;
sortedList.RemoveAt(0);
var highScore = new StringBuilder();
highScore.AppendLine($":bar_chart: **Highscore for {Context.Guild.Name}**");
var counter = 1;
var highscoreUsers = new Dictionary<IGuildUser, int>();
var listLimiter = 1;
foreach (var user in sortedList)
{
if (listLimiter > 10) break;
var guildUser = Context.Guild.GetUserAsync((ulong) user.Name).Result;
var percent = Math.Round((double) (100 * (int) user.Value) / guildMessages, 2);
if (guildUser != null)
{
highscoreUsers.Add(guildUser, (int)user.Value);
listLimiter++;
}
}
var highScore = new StringBuilder();
highScore.AppendLine($":bar_chart: **Highscore for {Context.Guild.Name}**");
var highscorePlace = 1;
foreach (var user in highscoreUsers)
{
var percent = Math.Round((double) (100 * user.Value) / guildMessages, 2);
highScore.AppendLine(
$"{NumerToEmoji(counter)} **{guildUser.Username}#{guildUser.Discriminator}** - {percent}% of total - {user.Value} messages");
counter++;
$"{NumerToEmoji(highscorePlace)} **{user.Key.Username}#{user.Key.Discriminator}** - {percent}% of total - {user.Value} messages");
highscorePlace++;
}
await ReplyAsync(highScore.ToString());
}

View file

@ -273,9 +273,8 @@ namespace Geekbot.net
redis.HashSet($"{guildId}:Settings", new HashEntry[] { new HashEntry("WelcomeMsg", val) });
break;
}
//redis.KeyDelete(key);
}
redis.KeyDelete(key);
}
}
return Task.CompletedTask;