Highscores Bugfix, small stats changes
This commit is contained in:
parent
9f4e23ff20
commit
98a13c9069
1 changed files with 49 additions and 16 deletions
|
@ -1,8 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
|
@ -35,18 +33,17 @@ namespace Geekbot.net.Modules
|
||||||
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
|
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
|
||||||
|
|
||||||
var messages = (int) redis.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.ToString());
|
var messages = (int) redis.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.ToString());
|
||||||
var level = LevelCalc.GetLevelAtExperience(messages);
|
|
||||||
|
|
||||||
var guildKey = Context.Guild.Id.ToString();
|
|
||||||
var guildMessages = (int) redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
var guildMessages = (int) redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
||||||
|
var level = LevelCalc.GetLevelAtExperience(messages);
|
||||||
|
|
||||||
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
// eb.WithAuthor(new EmbedAuthorBuilder()
|
||||||
.WithIconUrl(userInfo.GetAvatarUrl())
|
// .WithIconUrl(userInfo.GetAvatarUrl())
|
||||||
.WithName(userInfo.Username));
|
// .WithName(userInfo.Username));
|
||||||
|
eb.Title = $":bar_chart: {userInfo.Username}#{userInfo.Discriminator}";
|
||||||
|
eb.ThumbnailUrl = userInfo.GetAvatarUrl();
|
||||||
eb.WithColor(new Color(221, 255, 119));
|
eb.WithColor(new Color(221, 255, 119));
|
||||||
|
|
||||||
eb.AddField("Discordian Since",
|
eb.AddField("Discordian Since",
|
||||||
|
@ -77,28 +74,57 @@ namespace Geekbot.net.Modules
|
||||||
var guildMessages = (int) sortedList.First().Value;
|
var guildMessages = (int) sortedList.First().Value;
|
||||||
sortedList.RemoveAt(0);
|
sortedList.RemoveAt(0);
|
||||||
|
|
||||||
var highscoreUsers = new Dictionary<IGuildUser, int>();
|
var highscoreUsers = new Dictionary<RankUserPolyfill, int>();
|
||||||
var listLimiter = 1;
|
var listLimiter = 1;
|
||||||
|
var failedToRetrieveUser = false;
|
||||||
foreach (var user in sortedList)
|
foreach (var user in sortedList)
|
||||||
{
|
{
|
||||||
if (listLimiter > 10) break;
|
if (listLimiter > 10) break;
|
||||||
|
try
|
||||||
var guildUser = Context.Guild.GetUserAsync((ulong) user.Name).Result;
|
|
||||||
if (guildUser != null)
|
|
||||||
{
|
{
|
||||||
highscoreUsers.Add(guildUser, (int)user.Value);
|
var guildUser = Context.Guild.GetUserAsync((ulong) user.Name).Result;
|
||||||
|
if (guildUser != null)
|
||||||
|
{
|
||||||
|
highscoreUsers.Add(new RankUserPolyfill()
|
||||||
|
{
|
||||||
|
Username = guildUser.Username,
|
||||||
|
Discriminator = guildUser.Discriminator
|
||||||
|
}, (int) user.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
highscoreUsers.Add(new RankUserPolyfill()
|
||||||
|
{
|
||||||
|
Id = user.Name
|
||||||
|
}, (int) user.Value);
|
||||||
|
failedToRetrieveUser = true;
|
||||||
|
}
|
||||||
listLimiter++;
|
listLimiter++;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Warning(e, $"Could not retrieve user {user.Name}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var highScore = new StringBuilder();
|
var highScore = new StringBuilder();
|
||||||
|
if (failedToRetrieveUser) highScore.AppendLine(":warning: I couldn't get all userdata, i mentioned the missing ones, sorry!\n");
|
||||||
highScore.AppendLine($":bar_chart: **Highscore for {Context.Guild.Name}**");
|
highScore.AppendLine($":bar_chart: **Highscore for {Context.Guild.Name}**");
|
||||||
var highscorePlace = 1;
|
var highscorePlace = 1;
|
||||||
foreach (var user in highscoreUsers)
|
foreach (var user in highscoreUsers)
|
||||||
{
|
{
|
||||||
var percent = Math.Round((double) (100 * user.Value) / guildMessages, 2);
|
var percent = Math.Round((double) (100 * user.Value) / guildMessages, 2);
|
||||||
highScore.AppendLine(
|
if (user.Key.Username != null)
|
||||||
$"{NumerToEmoji(highscorePlace)} **{user.Key.Username}#{user.Key.Discriminator}** - {percent}% of total - {user.Value} messages");
|
{
|
||||||
|
highScore.AppendLine(
|
||||||
|
$"{NumerToEmoji(highscorePlace)} **{user.Key.Username}#{user.Key.Discriminator}** - {percent}% of total - {user.Value} messages");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
highScore.AppendLine(
|
||||||
|
$"{NumerToEmoji(highscorePlace)} **<@{user.Key.Id}>** - {percent}% of total - {user.Value} messages");
|
||||||
|
}
|
||||||
highscorePlace++;
|
highscorePlace++;
|
||||||
}
|
}
|
||||||
await ReplyAsync(highScore.ToString());
|
await ReplyAsync(highScore.ToString());
|
||||||
|
@ -123,4 +149,11 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RankUserPolyfill
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Discriminator { get; set; }
|
||||||
|
public string Id { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue