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
|
@ -30,9 +30,12 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
}
|
||||
|
||||
[Command("rank", RunMode = RunMode.Async)]
|
||||
[Summary("get user top 10 in messages or karma")]
|
||||
[Summary("Get the highscore for various stats like message count, karma, correctly guessed roles, etc...")]
|
||||
[DisableInDirectMessage]
|
||||
public async Task RankCmd([Summary("type")] string typeUnformated = "messages", [Summary("amount")] int amount = 10)
|
||||
public async Task RankCmd(
|
||||
[Summary("type")] string typeUnformated = "messages",
|
||||
[Summary("amount")] int amount = 10,
|
||||
[Summary("season")] string season = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -59,7 +62,7 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
Dictionary<HighscoreUserDto, int> highscoreUsers;
|
||||
try
|
||||
{
|
||||
highscoreUsers = _highscoreManager.GetHighscoresWithUserData(type, guildId, amount);
|
||||
highscoreUsers = _highscoreManager.GetHighscoresWithUserData(type, guildId, amount, season);
|
||||
}
|
||||
catch (HighscoreListEmptyException)
|
||||
{
|
||||
|
@ -80,7 +83,18 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
|
||||
if (failedToRetrieveUser) replyBuilder.AppendLine(Localization.Rank.FailedToResolveAllUsernames).AppendLine();
|
||||
|
||||
replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, type.ToString().CapitalizeFirst(), Context.Guild.Name));
|
||||
if (type == HighscoreTypes.seasons)
|
||||
{
|
||||
if (string.IsNullOrEmpty(season))
|
||||
{
|
||||
season = SeasonsUtils.GetCurrentSeason();
|
||||
}
|
||||
replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, $"{type.ToString().CapitalizeFirst()} ({season})", Context.Guild.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, type.ToString().CapitalizeFirst(), Context.Guild.Name));
|
||||
}
|
||||
|
||||
var highscorePlace = 1;
|
||||
foreach (var (user, value) in highscoreUsers)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Highscores;
|
||||
using Geekbot.Core.Logger;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace Geekbot.Bot.Handlers
|
|||
{
|
||||
_logger = logger;
|
||||
_database = database;
|
||||
_season = GetSeason();
|
||||
_season = SeasonsUtils.GetCurrentSeason();
|
||||
_seasonsStarted = DateTime.Now.Year == 2021;
|
||||
|
||||
var timer = new Timer()
|
||||
|
@ -34,7 +34,9 @@ namespace Geekbot.Bot.Handlers
|
|||
};
|
||||
timer.Elapsed += (sender, args) =>
|
||||
{
|
||||
_season = GetSeason();
|
||||
var current = SeasonsUtils.GetCurrentSeason();
|
||||
if (current == _season) return;
|
||||
_season = SeasonsUtils.GetCurrentSeason();
|
||||
_seasonsStarted = DateTime.Now.Year == 2021;
|
||||
};
|
||||
}
|
||||
|
@ -108,13 +110,5 @@ namespace Geekbot.Bot.Handlers
|
|||
await _database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSeason()
|
||||
{
|
||||
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