Update Challonge
This commit is contained in:
@@ -14,18 +14,21 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
this.dep = d;
|
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")]
|
[Command("last")]
|
||||||
public async Task LastAsync(CommandContext ctx)
|
public async Task LastAsync(CommandContext ctx)
|
||||||
{
|
{
|
||||||
var tournament = await dep.ChallongeService.GetLastTournament();
|
var lastTournamentMessage = dep.ChallongeService.GetLastTournamentMessage();
|
||||||
await ctx.RespondAsync($"Dernier tournois: {tournament}");
|
await ctx.RespondAsync(lastTournamentMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,34 +13,56 @@ namespace LaDOSE.DiscordBot.Service
|
|||||||
{
|
{
|
||||||
public class ChallongeService
|
public class ChallongeService
|
||||||
{
|
{
|
||||||
|
private ChallongeConfig Config;
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
|
|
||||||
|
public ChallongeHTTPClientAPICaller ApiCaller { get; set; }
|
||||||
|
|
||||||
|
public string DernierTournois { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ChallongeService(string apiKey)
|
public ChallongeService(string apiKey)
|
||||||
{
|
{
|
||||||
this.ApiKey = apiKey;
|
this.ApiKey = apiKey;
|
||||||
|
this.Config = new ChallongeConfig(this.ApiKey);
|
||||||
|
this.ApiCaller = new ChallongeHTTPClientAPICaller(Config);
|
||||||
|
DernierTournois = "Aucun tournois.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<String> GetLastTournament()
|
|
||||||
|
public async Task<Boolean> GetLastTournament()
|
||||||
{
|
{
|
||||||
ChallongeConfig config = new ChallongeConfig(this.ApiKey);
|
try
|
||||||
var caller = new ChallongeHTTPClientAPICaller(config);
|
{
|
||||||
var tournaments = new Tournaments(caller);
|
|
||||||
|
|
||||||
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
||||||
{
|
{
|
||||||
state = TournamentState.Ended
|
state = TournamentState.Ended
|
||||||
}
|
}
|
||||||
.call(caller);
|
.call(this.ApiCaller);
|
||||||
List<StartedTournament> tournamentList = new List<StartedTournament>();
|
|
||||||
foreach (TournamentResult result in tournamentResultList)
|
|
||||||
|
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} : <https://challonge.com/{tournamentResult.url}> \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
var startedTournament = tournamentList.Last();
|
DernierTournois = returnValue;
|
||||||
|
return true;
|
||||||
return startedTournament.ToString();
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string GetLastTournamentMessage()
|
||||||
|
{
|
||||||
|
return DernierTournois;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user