REST to a .Net Standard Library

Test REST in discord bot and WPF
Small improvements
This commit is contained in:
2019-03-16 12:22:52 +01:00
parent 081d9ae893
commit 2fe08f938a
22 changed files with 423 additions and 78 deletions

View File

@@ -4,32 +4,50 @@ using DSharpPlus.CommandsNext.Attributes;
namespace LaDOSE.DiscordBot.Command
{
internal class Result
{
Dependencies dep;
internal class Result
public Result(Dependencies d)
{
Dependencies dep;
public Result(Dependencies d)
{
this.dep = d;
}
[RequireRolesAttribute("Staff")]
[Command("update")]
public async Task UpdateAsync(CommandContext ctx)
{
var tournament = await dep.ChallongeService.GetLastTournament();
await ctx.RespondAsync($"Mise à jour effectuée");
}
[Command("last")]
public async Task LastAsync(CommandContext ctx)
{
var lastTournamentMessage = dep.ChallongeService.GetLastTournamentMessage();
await ctx.RespondAsync(lastTournamentMessage);
}
this.dep = d;
}
[RequireRolesAttribute("Staff")]
[Command("update")]
public async Task UpdateAsync(CommandContext ctx)
{
var tournament = await dep.ChallongeService.GetLastTournament();
await ctx.RespondAsync($"Mise à jour effectuée");
}
[Command("last")]
public async Task LastAsync(CommandContext ctx)
{
var lastTournamentMessage = dep.ChallongeService.GetLastTournamentMessage();
await ctx.RespondAsync(lastTournamentMessage);
}
[RequireRolesAttribute("Staff")]
[Command("inscriptions")]
public async Task InscriptionsAsync(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
var inscrits = dep.WebService.GetInscrits();
await ctx.RespondAsync(inscrits);
}
[RequireRolesAttribute("Staff")]
[Command("UpdateDb")]
public async Task UpdateDbAsync(CommandContext ctx)
{
await ctx.RespondAsync("Mise à jour des inscriptions en cours...");
await ctx.TriggerTypingAsync();
var status = dep.WebService.RefreshDb() ? "Ok" : "erreur";
await ctx.RespondAsync($"Status: {status}");
}
}
}

View File

@@ -10,6 +10,6 @@ namespace LaDOSE.DiscordBot
internal CancellationTokenSource Cts { get; set; }
public ChallongeService ChallongeService { get; set; }
public TodoService TodoService { get; set; }
public WebService WebService { get; set; }
}
}

View File

@@ -13,6 +13,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LaDOSE.REST\LaDOSE.REST.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="ChallongeCSharpDriver">
<HintPath>..\..\Library\ChallongeCSharpDriver.dll</HintPath>

View File

@@ -31,7 +31,9 @@ namespace LaDOSE.DiscordBot
var discordToken = builder["Discord:Token"].ToString();
var challongeToken = builder["Challonge:Token"].ToString();
var restUrl = builder["REST:Url"].ToString();
var restUser = builder["REST:User"].ToString();
var restPassword = builder["REST:Password"].ToString();
Console.WriteLine($"LaDOSE.Net Discord Bot");
@@ -42,7 +44,7 @@ namespace LaDOSE.DiscordBot
TokenType = TokenType.Bot
});
var webService = new WebService(new Uri(restUrl),restUser,restPassword);
var challongeService = new ChallongeService(challongeToken);
var todoService = new TodoService();
var cts = new CancellationTokenSource();
@@ -56,6 +58,7 @@ namespace LaDOSE.DiscordBot
Cts = cts,
ChallongeService = challongeService,
TodoService = todoService,
WebService = webService
});
dep = d.Build();
}

View File

@@ -0,0 +1,41 @@
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;
using LaDOSE.DTO;
using LaDOSE.REST;
namespace LaDOSE.DiscordBot.Service
{
public class WebService
{
private RestService restService;
public WebService(Uri uri,string user,string password)
{
restService = new RestService();
restService.Connect(uri,user,password);
}
public String GetInscrits()
{
var wpEventDto = restService.GetNextEvent();
var wpBookingDtos = wpEventDto.WpBookings;
List<String> player= new List<string>();
wpBookingDtos.OrderBy(e=>e.WpUser.Name).ToList().ForEach(e=> player.Add(e.WpUser.Name));
return $"Les Joueurs inscrits pour {wpEventDto.Name} {string.Join(", ", player)}";
}
public bool RefreshDb()
{
return restService.RefreshDb();
}
}
}