Test Connection
Add Todo Bot use Webservice now TBD : Rework Event
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
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
|
||||
{
|
||||
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<Boolean> GetLastTournament()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
||||
{
|
||||
state = TournamentState.Ended
|
||||
}
|
||||
.call(this.ApiCaller);
|
||||
|
||||
|
||||
var lastDate = tournamentResultList.Max(e => e.completed_at);
|
||||
if (lastDate.HasValue)
|
||||
{
|
||||
var lastRankingDate = new DateTime(lastDate.Value.Year, lastDate.Value.Month, lastDate.Value.Day);
|
||||
|
||||
var lastTournament = tournamentResultList.Where(e => e.completed_at > lastRankingDate).ToList();
|
||||
string returnValue = "Les derniers tournois : \n";
|
||||
foreach (var tournamentResult in lastTournament)
|
||||
{
|
||||
returnValue += $"{tournamentResult.name} : <https://challonge.com/{tournamentResult.url}> \n";
|
||||
}
|
||||
|
||||
DernierTournois = returnValue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public string GetLastTournamentMessage()
|
||||
{
|
||||
return DernierTournois;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
public class TodoService
|
||||
{
|
||||
private const string db = "todo.txt";
|
||||
|
||||
public TodoService()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Add(string text)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(text)) {
|
||||
using (var textWriter =File.AppendText(db))
|
||||
{
|
||||
textWriter.WriteLine(text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
public bool Delete(int id)
|
||||
{
|
||||
string returnText = "";
|
||||
var text = File.ReadAllText(db);
|
||||
var i = 0;
|
||||
foreach (var line in text.Split('\n'))
|
||||
{
|
||||
++i;
|
||||
if (i != id)
|
||||
{
|
||||
returnText += $"{line}\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File.WriteAllText(db,returnText);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public string List()
|
||||
{
|
||||
string returnText = "";
|
||||
var text = File.ReadAllText(db);
|
||||
var i = 0;
|
||||
foreach (var line in text.Split())
|
||||
{
|
||||
if(!string.IsNullOrEmpty(line))
|
||||
returnText += $"{++i}. {line}";
|
||||
}
|
||||
|
||||
return returnText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using ChallongeCSharpDriver.Main;
|
||||
using ChallongeCSharpDriver.Main.Objects;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.REST;
|
||||
using RestSharp.Authenticators;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
@@ -17,12 +18,20 @@ namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
private RestService restService;
|
||||
|
||||
public RestService RestService => restService;
|
||||
|
||||
public WebService(Uri uri,string user,string password)
|
||||
{
|
||||
restService = new RestService();
|
||||
restService.Connect(uri,user,password);
|
||||
}
|
||||
|
||||
private void CheckToken()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String GetInscrits()
|
||||
@@ -37,5 +46,10 @@ namespace LaDOSE.DiscordBot.Service
|
||||
{
|
||||
return restService.RefreshDb();
|
||||
}
|
||||
|
||||
public string GetLastChallonge()
|
||||
{
|
||||
return restService.GetLastChallonge();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user