Challonge Test
This commit is contained in:
@@ -20,6 +20,14 @@ namespace LaDOSE.DiscordBot.Command
|
||||
await ctx.RespondAsync("Resultat");
|
||||
|
||||
}
|
||||
|
||||
[Command("last")]
|
||||
public async Task LastAsync(CommandContext ctx)
|
||||
{
|
||||
var tournament = await dep.ChallongeService.GetLastTournament();
|
||||
await ctx.RespondAsync($"Dernier tournois: {tournament}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
public partial class Result
|
||||
public class Result
|
||||
{
|
||||
|
||||
internal class Twitch
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Threading;
|
||||
using DSharpPlus.Interactivity;
|
||||
using LaDOSE.DiscordBot.Service;
|
||||
|
||||
namespace LaDOSE.DiscordBot
|
||||
{
|
||||
@@ -7,5 +8,6 @@ namespace LaDOSE.DiscordBot
|
||||
{
|
||||
internal InteractivityModule Interactivity { get; set; }
|
||||
internal CancellationTokenSource Cts { get; set; }
|
||||
public ChallongeService ChallongeService { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,12 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="ChallongeCSharpDriver">
|
||||
<HintPath>..\..\Library\ChallongeCSharpDriver.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="settings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@@ -8,6 +8,7 @@ using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.EventArgs;
|
||||
using LaDOSE.DiscordBot.Command;
|
||||
using LaDOSE.DiscordBot.Service;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace LaDOSE.DiscordBot
|
||||
@@ -15,7 +16,6 @@ namespace LaDOSE.DiscordBot
|
||||
class Program
|
||||
{
|
||||
static DiscordClient discord;
|
||||
static InteractivityModule _interactivity;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
@@ -29,6 +29,7 @@ namespace LaDOSE.DiscordBot
|
||||
.AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build();
|
||||
|
||||
var discordToken = builder["Discord:Token"].ToString();
|
||||
var challongeToken = builder["Challonge:Token"].ToString();
|
||||
|
||||
|
||||
Console.WriteLine($"LaDOSE.Net Discord Bot");
|
||||
@@ -40,22 +41,18 @@ namespace LaDOSE.DiscordBot
|
||||
TokenType = TokenType.Bot
|
||||
});
|
||||
|
||||
var _interactivity = discord.UseInteractivity(new InteractivityConfiguration()
|
||||
{
|
||||
PaginationBehaviour = TimeoutBehaviour.Delete,
|
||||
PaginationTimeout = TimeSpan.FromSeconds(30),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
});
|
||||
|
||||
var _cts = new CancellationTokenSource();
|
||||
var challongeService = new ChallongeService(challongeToken);
|
||||
var cts = new CancellationTokenSource();
|
||||
DependencyCollection dep = null;
|
||||
|
||||
using (var d = new DependencyCollectionBuilder())
|
||||
{
|
||||
d.AddInstance(new Dependencies()
|
||||
{
|
||||
Interactivity = _interactivity,
|
||||
Cts = _cts
|
||||
|
||||
Cts = cts,
|
||||
ChallongeService = challongeService
|
||||
});
|
||||
dep = d.Build();
|
||||
}
|
||||
@@ -89,7 +86,7 @@ namespace LaDOSE.DiscordBot
|
||||
await e.Guild.GetDefaultChannel().SendMessageAsync($"Bonjour {e.Member.DisplayName}!");
|
||||
};
|
||||
await discord.ConnectAsync();
|
||||
while (!_cts.IsCancellationRequested)
|
||||
while (!cts.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChallongeCSharpDriver;
|
||||
using ChallongeCSharpDriver.Caller;
|
||||
using ChallongeCSharpDriver.Core.Queries;
|
||||
using ChallongeCSharpDriver.Core.Results;
|
||||
using ChallongeCSharpDriver.Main;
|
||||
using ChallongeCSharpDriver.Main.Objects;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
public class ChallongeService
|
||||
{
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
|
||||
public ChallongeService(string apiKey)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
|
||||
}
|
||||
|
||||
public async Task<String> GetLastTournament()
|
||||
{
|
||||
ChallongeConfig config = new ChallongeConfig(this.ApiKey);
|
||||
var caller = new ChallongeHTTPClientAPICaller(config);
|
||||
var tournaments = new Tournaments(caller);
|
||||
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
||||
{
|
||||
state = TournamentState.Ended
|
||||
}
|
||||
.call(caller);
|
||||
List<StartedTournament> tournamentList = new List<StartedTournament>();
|
||||
foreach (TournamentResult result in tournamentResultList)
|
||||
{
|
||||
tournamentList.Add(new TournamentObject(result, caller));
|
||||
}
|
||||
|
||||
var startedTournament = tournamentList.Last();
|
||||
|
||||
return startedTournament.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"Discord": {
|
||||
"Token" : "APITOKEN Here"
|
||||
"Token": "DISCORD TOKEN"
|
||||
},
|
||||
"Challonge": {
|
||||
"Token": "CHALLONGE API TOKEN"
|
||||
}
|
||||
}
|
||||
BIN
LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll
Normal file
BIN
LaDOSE.DiscordBot/Library/ChallongeCSharpDriver.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user