Directories

This commit is contained in:
2018-10-04 21:18:18 +02:00
parent 3b88ea1d48
commit b5ca26c7cb
16 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace LaDOSE.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ConfigController : ControllerBase
{
// GET api/Config
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/Config/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace LaDOSE.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace LaDOSE.Api
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
namespace LaDOSE.DiscordBot.Command
{
public partial class Twitch
{
internal class Result
{
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);
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
namespace LaDOSE.DiscordBot.Command
{
[RequireRolesAttribute("SuperAdmin")]
internal class Shutdown
{
private readonly Dependencies dep;
public Shutdown(Dependencies d)
{
dep = d;
}
[Command("shutdown")]
public async Task ShutDownAsync(CommandContext ctx)
{
await ctx.RespondAsync("Hasta la vista, baby");
dep.Cts.Cancel();
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
namespace LaDOSE.DiscordBot.Command
{
public class Result
{
internal class Twitch
{
Dependencies dep;
public Twitch(Dependencies d)
{
this.dep = d;
}
[Command("twitch")]
public async Task TwitchAsync(CommandContext ctx)
{
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
}
}
}
}

View File

@@ -0,0 +1,13 @@
using System.Threading;
using DSharpPlus.Interactivity;
using LaDOSE.DiscordBot.Service;
namespace LaDOSE.DiscordBot
{
internal class Dependencies
{
internal InteractivityModule Interactivity { get; set; }
internal CancellationTokenSource Cts { get; set; }
public ChallongeService ChallongeService { get; set; }
}
}

View File

@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="3.2.3" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="3.2.3" />
<PackageReference Include="DSharpPlus.Interactivity" Version="3.2.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<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>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Interactivity;
using DSharpPlus.CommandsNext;
using DSharpPlus.EventArgs;
using LaDOSE.DiscordBot.Command;
using LaDOSE.DiscordBot.Service;
using Microsoft.Extensions.Configuration;
namespace LaDOSE.DiscordBot
{
class Program
{
static DiscordClient discord;
static void Main(string[] args)
{
MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
}
static async Task MainAsync(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.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");
discord = new DiscordClient(new DiscordConfiguration
{
Token = discordToken,
TokenType = TokenType.Bot
});
var challongeService = new ChallongeService(challongeToken);
var cts = new CancellationTokenSource();
DependencyCollection dep = null;
using (var d = new DependencyCollectionBuilder())
{
d.AddInstance(new Dependencies()
{
Cts = cts,
ChallongeService = challongeService
});
dep = d.Build();
}
var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration()
{
CaseSensitive = false,
EnableDefaultHelp = true,
EnableDms = false,
EnableMentionPrefix = true,
StringPrefix = "!",
IgnoreExtraArguments = true,
Dependencies = dep
});
_cnext.RegisterCommands<Result>();
_cnext.RegisterCommands<Twitch>();
_cnext.RegisterCommands<Shutdown>();
//discord.MessageCreated += async e =>
//{
// if (e.Message.Content.ToLower().Equals("!result"))
// await e.Message.RespondAsync("Les Résultats du dernier Ranking : XXXX");
// if (e.Message.Content.ToLower().Equals("!twitch"))
// await e.Message.RespondAsync("https://www.twitch.tv/LaDOSETV");
//};
discord.GuildMemberAdded += async e =>
{
await e.Guild.GetDefaultChannel().SendMessageAsync($"Bonjour {e.Member.DisplayName}!");
};
await discord.ConnectAsync();
while (!cts.IsCancellationRequested)
{
await Task.Delay(200);
}
}
}
}

View File

@@ -0,0 +1,68 @@
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);
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)
{
returnValue += $"{tournamentResult.name} : <https://challonge.com/{tournamentResult.url}> \n";
}
DernierTournois = returnValue;
return true;
}
catch
{
return false;
}
}
public string GetLastTournamentMessage()
{
return DernierTournois;
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Discord": {
"Token": "DISCORD TOKEN"
},
"Challonge": {
"Token": "CHALLONGE API TOKEN"
}
}

31
LaDOSE.Src/LaDOSE.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2041
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.DiscordBot", "LaDOSE.DiscordBot\LaDOSE.DiscordBot.csproj", "{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1E8FAF6-3A75-44AC-938D-CA56A5322D1C}.Release|Any CPU.Build.0 = Release|Any CPU
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D47DEDD0-C906-439D-81E4-D86BBE723B8C}
EndGlobalSection
EndGlobal