add !rank seasons to the rank command
This commit is contained in:
parent
29c0def713
commit
29bb8035fe
6 changed files with 58 additions and 18 deletions
|
@ -18,7 +18,7 @@ namespace Geekbot.Core.Highscores
|
|||
|
||||
}
|
||||
|
||||
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount)
|
||||
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount, string season = null)
|
||||
{
|
||||
var list = type switch
|
||||
{
|
||||
|
@ -26,6 +26,7 @@ namespace Geekbot.Core.Highscores
|
|||
HighscoreTypes.karma => GetKarmaList(guildId, amount),
|
||||
HighscoreTypes.rolls => GetRollsList(guildId, amount),
|
||||
HighscoreTypes.cookies => GetCookiesList(guildId, amount),
|
||||
HighscoreTypes.seasons => GetMessageSeasonList(guildId, amount, season),
|
||||
_ => new Dictionary<ulong, int>()
|
||||
};
|
||||
|
||||
|
@ -75,6 +76,19 @@ namespace Geekbot.Core.Highscores
|
|||
.ToDictionary(key => key.UserId.AsUlong(), key => key.MessageCount);
|
||||
}
|
||||
|
||||
public Dictionary<ulong, int> GetMessageSeasonList(ulong guildId, int amount, string season)
|
||||
{
|
||||
if (string.IsNullOrEmpty(season))
|
||||
{
|
||||
season = SeasonsUtils.GetCurrentSeason();
|
||||
}
|
||||
return _database.MessagesSeasons
|
||||
.Where(k => k.GuildId.Equals(guildId.AsLong()) && k.Season.Equals(season))
|
||||
.OrderByDescending(o => o.MessageCount)
|
||||
.Take(amount)
|
||||
.ToDictionary(key => key.UserId.AsUlong(), key => key.MessageCount);
|
||||
}
|
||||
|
||||
public Dictionary<ulong, int> GetKarmaList(ulong guildId, int amount)
|
||||
{
|
||||
return _database.Karma
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
messages,
|
||||
karma,
|
||||
rolls,
|
||||
cookies
|
||||
cookies,
|
||||
seasons
|
||||
}
|
||||
}
|
|
@ -4,8 +4,9 @@ namespace Geekbot.Core.Highscores
|
|||
{
|
||||
public interface IHighscoreManager
|
||||
{
|
||||
Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount);
|
||||
Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount, string season = null);
|
||||
Dictionary<ulong, int> GetMessageList(ulong guildId, int amount);
|
||||
Dictionary<ulong, int> GetMessageSeasonList(ulong guildId, int amount, string season);
|
||||
Dictionary<ulong, int> GetKarmaList(ulong guildId, int amount);
|
||||
Dictionary<ulong, int> GetRollsList(ulong guildId, int amount);
|
||||
}
|
||||
|
|
16
src/Core/Highscores/SeasonsUtils.cs
Normal file
16
src/Core/Highscores/SeasonsUtils.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Geekbot.Core.Highscores
|
||||
{
|
||||
public class SeasonsUtils
|
||||
{
|
||||
public static string GetCurrentSeason()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var year = (now.Year - 2000).ToString(CultureInfo.InvariantCulture);
|
||||
var quarter = Math.Ceiling(now.Month / 3.0).ToString(CultureInfo.InvariantCulture);
|
||||
return $"{year}Q{quarter}";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue