diff --git a/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Command/Result.cs b/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Command/Result.cs index 9e775c8..cd12cf4 100644 --- a/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Command/Result.cs +++ b/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Command/Result.cs @@ -14,18 +14,21 @@ namespace LaDOSE.DiscordBot.Command this.dep = d; } - [Command("result")] - public async Task ResultAsync(CommandContext ctx) + + [RequireRolesAttribute("Staff")] + [Command("update")] + public async Task UpdateAsync(CommandContext ctx) { - await ctx.RespondAsync("Resultat"); - + var tournament = await dep.ChallongeService.GetLastTournament(); + await ctx.RespondAsync($"Mise à jour effectuée"); + } [Command("last")] public async Task LastAsync(CommandContext ctx) { - var tournament = await dep.ChallongeService.GetLastTournament(); - await ctx.RespondAsync($"Dernier tournois: {tournament}"); + var lastTournamentMessage = dep.ChallongeService.GetLastTournamentMessage(); + await ctx.RespondAsync(lastTournamentMessage); } } diff --git a/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Service/ChallongeService.cs b/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Service/ChallongeService.cs index 867fd22..a74dd27 100644 --- a/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Service/ChallongeService.cs +++ b/LaDOSE.DiscordBot/LaDOSE.DiscordBot/LaDOSE.DiscordBot/Service/ChallongeService.cs @@ -13,34 +13,56 @@ namespace LaDOSE.DiscordBot.Service { public class ChallongeService { + private ChallongeConfig Config; public string ApiKey { get; set; } + public ChallongeHTTPClientAPICaller ApiCaller { get; set; } + + public string DernierTournois { get; set; } + public ChallongeService(string apiKey) { this.ApiKey = apiKey; - + this.Config = new ChallongeConfig(this.ApiKey); + this.ApiCaller = new ChallongeHTTPClientAPICaller(Config); + DernierTournois = "Aucun tournois."; } - public async Task GetLastTournament() + + public async Task GetLastTournament() { - ChallongeConfig config = new ChallongeConfig(this.ApiKey); - var caller = new ChallongeHTTPClientAPICaller(config); - var tournaments = new Tournaments(caller); + try + { + + List tournamentResultList = await new TournamentsQuery() { state = TournamentState.Ended } - .call(caller); - List tournamentList = new List(); - foreach (TournamentResult result in tournamentResultList) + .call(this.ApiCaller); + + + var lastDate = tournamentResultList.Max(e => e.completed_at); + var lastRankingDate = new DateTime(lastDate.Year, lastDate.Month, lastDate.Day); + var lastTournament = tournamentResultList.Where(e => e.completed_at > lastRankingDate).ToList(); + string returnValue = "Les derniers tournois : \n"; + foreach (var tournamentResult in lastTournament) { - tournamentList.Add(new TournamentObject(result, caller)); + returnValue += $"{tournamentResult.name} : \n"; } - var startedTournament = tournamentList.Last(); - - return startedTournament.ToString(); + DernierTournois = returnValue; + return true; + } + catch + { + return false; + } + } + public string GetLastTournamentMessage() + { + return DernierTournois; } } } \ No newline at end of file diff --git a/LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll b/LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll index ef33388..ad6a5f3 100644 Binary files a/LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll and b/LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll differ