Bot Event
This commit is contained in:
48
LaDOSE.Src/LaDOSE.Api/Controllers/BotEventController.cs
Normal file
48
LaDOSE.Src/LaDOSE.Api/Controllers/BotEventController.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
|
using LaDOSE.Business.Interface;
|
||||||
|
using LaDOSE.DTO;
|
||||||
|
using LaDOSE.Entity;
|
||||||
|
using LaDOSE.Entity.BotEvent;
|
||||||
|
using LaDOSE.Entity.Wordpress;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LaDOSE.Api.Controllers
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
//[Authorize]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class BotEventController : GenericControllerDTO<IBotEventService, BotEvent, BotEventDTO>
|
||||||
|
{
|
||||||
|
|
||||||
|
public BotEventController(IMapper mapper,IBotEventService service) : base(mapper,service)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("CreateBotEvent/{eventName}")]
|
||||||
|
public bool CreateBotEvent(String eventName)
|
||||||
|
{
|
||||||
|
return this._service.CreateEvent(eventName);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
[Route("ResultBotEvent/")]
|
||||||
|
public bool ResultBotEvent([FromBody] BotEventSendDTO result)
|
||||||
|
{
|
||||||
|
return this._service.SetResult(result.DiscordId,result.DiscordName,result.Present);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("GetLastBotEvent/")]
|
||||||
|
public BotEventDTO GetLastBotEvent()
|
||||||
|
{
|
||||||
|
return this._mapper.Map<BotEventDTO>(this._service.GetLastEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ using LaDOSE.Business.Provider.SmashProvider;
|
|||||||
using LaDOSE.Entity.Challonge;
|
using LaDOSE.Entity.Challonge;
|
||||||
using LaDOSE.Entity.Wordpress;
|
using LaDOSE.Entity.Wordpress;
|
||||||
using Result = LaDOSE.Entity.Challonge.Result;
|
using Result = LaDOSE.Entity.Challonge.Result;
|
||||||
|
using LaDOSE.Entity.BotEvent;
|
||||||
|
|
||||||
namespace LaDOSE.Api
|
namespace LaDOSE.Api
|
||||||
{
|
{
|
||||||
@@ -123,6 +124,8 @@ namespace LaDOSE.Api
|
|||||||
cfg.CreateMap<WPEvent, LaDOSE.DTO.WPEventDTO>();
|
cfg.CreateMap<WPEvent, LaDOSE.DTO.WPEventDTO>();
|
||||||
cfg.CreateMap<Result, LaDOSE.DTO.ResultDTO>();
|
cfg.CreateMap<Result, LaDOSE.DTO.ResultDTO>();
|
||||||
cfg.CreateMap<Event, LaDOSE.DTO.EventDTO>();
|
cfg.CreateMap<Event, LaDOSE.DTO.EventDTO>();
|
||||||
|
cfg.CreateMap<BotEventResult, LaDOSE.DTO.BotEventResultDTO>();
|
||||||
|
cfg.CreateMap<BotEvent, LaDOSE.DTO.BotEventDTO>();
|
||||||
|
|
||||||
cfg.CreateMap<TournamentsResult, LaDOSE.DTO.TournamentsResultDTO>();
|
cfg.CreateMap<TournamentsResult, LaDOSE.DTO.TournamentsResultDTO>();
|
||||||
cfg.CreateMap<ChallongeParticipent, LaDOSE.DTO.ParticipentDTO>();
|
cfg.CreateMap<ChallongeParticipent, LaDOSE.DTO.ParticipentDTO>();
|
||||||
@@ -150,6 +153,7 @@ namespace LaDOSE.Api
|
|||||||
services.AddScoped<IWordPressService, WordPressService>();
|
services.AddScoped<IWordPressService, WordPressService>();
|
||||||
services.AddScoped<ITodoService, TodoService>();
|
services.AddScoped<ITodoService, TodoService>();
|
||||||
services.AddScoped<IEventService, EventService>();
|
services.AddScoped<IEventService, EventService>();
|
||||||
|
services.AddScoped<IBotEventService, BotEventService>();
|
||||||
|
|
||||||
services.AddScoped<IPlayerService, PlayerService>();
|
services.AddScoped<IPlayerService, PlayerService>();
|
||||||
services.AddTransient<IChallongeProvider>(p => new ChallongeProvider( p.GetRequiredService<IGameService>(),
|
services.AddTransient<IChallongeProvider>(p => new ChallongeProvider( p.GetRequiredService<IGameService>(),
|
||||||
|
|||||||
21
LaDOSE.Src/LaDOSE.DTO/BotEventDTO.cs
Normal file
21
LaDOSE.Src/LaDOSE.DTO/BotEventDTO.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace LaDOSE.DTO
|
||||||
|
{
|
||||||
|
public class BotEventSendDTO
|
||||||
|
{
|
||||||
|
public string DiscordId { get; set; }
|
||||||
|
public string DiscordName { get; set; }
|
||||||
|
public bool Present { get; set; }
|
||||||
|
}
|
||||||
|
public class BotEventDTO
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public List<BotEventResultDTO> Results { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
10
LaDOSE.Src/LaDOSE.DTO/BotEventResultDTO.cs
Normal file
10
LaDOSE.Src/LaDOSE.DTO/BotEventResultDTO.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace LaDOSE.DTO
|
||||||
|
{
|
||||||
|
public class BotEventResultDTO
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string DiscordId { get; set; }
|
||||||
|
public bool Result { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
58
LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs
Normal file
58
LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.CommandsNext;
|
||||||
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
|
using LaDOSE.DTO;
|
||||||
|
|
||||||
|
namespace LaDOSE.DiscordBot.Command
|
||||||
|
{
|
||||||
|
public class BotEvent
|
||||||
|
{
|
||||||
|
private readonly Dependencies dep;
|
||||||
|
|
||||||
|
public BotEvent(Dependencies d)
|
||||||
|
{
|
||||||
|
dep = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequireRolesAttribute("Staff")]
|
||||||
|
[Command("newevent")]
|
||||||
|
public async Task NewEventAsync(CommandContext ctx, string command)
|
||||||
|
{
|
||||||
|
|
||||||
|
await ctx.RespondAsync(dep.WebService.RestService.CreateBotEvent(command).ToString());
|
||||||
|
}
|
||||||
|
[RequireRolesAttribute("Staff")]
|
||||||
|
[Command("staffs")]
|
||||||
|
public async Task StaffAsync(CommandContext ctx)
|
||||||
|
{
|
||||||
|
BotEventDTO currentEvent = dep.WebService.RestService.GetLastBotEvent();
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
var present = currentEvent.Results.Where(x => x.Result).ToList();
|
||||||
|
var absent = currentEvent.Results.Where(x => !x.Result).ToList();
|
||||||
|
|
||||||
|
stringBuilder.AppendLine($"Pour {currentEvent.Name} : ");
|
||||||
|
present.ForEach(x => stringBuilder.AppendLine($":white_check_mark: {x.Name}"));
|
||||||
|
absent.ForEach(x => stringBuilder.AppendLine($":x: {x.Name}"));
|
||||||
|
|
||||||
|
await ctx.RespondAsync(stringBuilder.ToString());
|
||||||
|
|
||||||
|
}
|
||||||
|
[RequireRolesAttribute("Staff")]
|
||||||
|
[Command("present")]
|
||||||
|
public async Task PresentAsync(CommandContext ctx)
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync(dep.WebService.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = true }).ToString());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
[RequireRolesAttribute("Staff")]
|
||||||
|
[Command("absent")]
|
||||||
|
public async Task AbsentAsync(CommandContext ctx)
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync(dep.WebService.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = false }).ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,14 +20,6 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//[Command("hokuto")]
|
|
||||||
//public async Task HokutoAsync(CommandContext ctx)
|
|
||||||
//{
|
|
||||||
|
|
||||||
// var i = r.Next(0, 3);
|
|
||||||
// await ctx.RespondAsync(ctx.User?.Mention + " : " + Games[i].ToString());
|
|
||||||
//}
|
|
||||||
|
|
||||||
[Command("hokuto")]
|
[Command("hokuto")]
|
||||||
public async Task HokutoUserAsync(CommandContext ctx, params DiscordMember[] user)
|
public async Task HokutoUserAsync(CommandContext ctx, params DiscordMember[] user)
|
||||||
{
|
{
|
||||||
|
|||||||
55
LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs
Normal file
55
LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.CommandsNext;
|
||||||
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
|
|
||||||
|
namespace LaDOSE.DiscordBot.Command
|
||||||
|
{
|
||||||
|
public class Public
|
||||||
|
{
|
||||||
|
private readonly Dependencies dep;
|
||||||
|
private List<string> Quotes { get; set; }
|
||||||
|
private Random rnd { get; set; }
|
||||||
|
public Public(Dependencies d)
|
||||||
|
{
|
||||||
|
dep = d;
|
||||||
|
rnd = new Random(DateTime.Now.Millisecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("twitch")]
|
||||||
|
public async Task TwitchAsync(CommandContext ctx)
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("Quote")]
|
||||||
|
public async Task QuotesAsync(CommandContext ctx)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Quotes == null)
|
||||||
|
LoadQuote();
|
||||||
|
|
||||||
|
await ctx.RespondAsync("```"+ Quotes[rnd.Next(Quotes.Count-1)] + "```");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadQuote()
|
||||||
|
{
|
||||||
|
Quotes = new List<string>();
|
||||||
|
string[] fileQuotes = File.ReadAllLines("quotes.txt");
|
||||||
|
string currentQuote = string.Empty;
|
||||||
|
for(int i = 0; i < fileQuotes.Length; i++)
|
||||||
|
{
|
||||||
|
if(String.IsNullOrEmpty(fileQuotes[i]))
|
||||||
|
{
|
||||||
|
Quotes.Add(currentQuote);
|
||||||
|
currentQuote = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentQuote += fileQuotes[i] + (!String.IsNullOrEmpty(currentQuote) ? "\r\n" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,29 +14,21 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//[RequireRolesAttribute("Staff")]
|
//[Command("last")]
|
||||||
//[Command("update")]
|
//public async Task LastAsync(CommandContext ctx)
|
||||||
//public async Task UpdateAsync(CommandContext ctx)
|
|
||||||
//{
|
//{
|
||||||
// //var tournament = await dep.ChallongeService.GetLastTournament();
|
// var lastTournamentMessage = dep.WebService.GetLastChallonge();
|
||||||
// //await ctx.RespondAsync($"Mise à jour effectuée");
|
// await ctx.RespondAsync(lastTournamentMessage);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[Command("last")]
|
//[RequireRolesAttribute("Staff")]
|
||||||
public async Task LastAsync(CommandContext ctx)
|
//[Command("inscriptions")]
|
||||||
{
|
//public async Task InscriptionsAsync(CommandContext ctx)
|
||||||
var lastTournamentMessage = dep.WebService.GetLastChallonge();
|
//{
|
||||||
await ctx.RespondAsync(lastTournamentMessage);
|
// await ctx.TriggerTypingAsync();
|
||||||
}
|
// var inscrits = dep.WebService.GetInscrits();
|
||||||
|
// await ctx.RespondAsync(inscrits);
|
||||||
[RequireRolesAttribute("Staff")]
|
//}
|
||||||
[Command("inscriptions")]
|
|
||||||
public async Task InscriptionsAsync(CommandContext ctx)
|
|
||||||
{
|
|
||||||
await ctx.TriggerTypingAsync();
|
|
||||||
var inscrits = dep.WebService.GetInscrits();
|
|
||||||
await ctx.RespondAsync(inscrits);
|
|
||||||
}
|
|
||||||
|
|
||||||
[RequireRolesAttribute("Staff")]
|
[RequireRolesAttribute("Staff")]
|
||||||
[Command("UpdateDb")]
|
[Command("UpdateDb")]
|
||||||
|
|||||||
@@ -1,143 +1,143 @@
|
|||||||
using System;
|
//using System;
|
||||||
using System.Text;
|
//using System.Text;
|
||||||
using System.Threading.Tasks;
|
//using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
//using DSharpPlus.CommandsNext;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
//using DSharpPlus.CommandsNext.Attributes;
|
||||||
using DSharpPlus.Interactivity;
|
//using DSharpPlus.Interactivity;
|
||||||
using LaDOSE.DTO;
|
//using LaDOSE.DTO;
|
||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
//namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
//{
|
||||||
public class Todo
|
// public class Todo
|
||||||
{
|
// {
|
||||||
private readonly Dependencies dep;
|
// private readonly Dependencies dep;
|
||||||
|
|
||||||
public Todo(Dependencies d)
|
// public Todo(Dependencies d)
|
||||||
{
|
// {
|
||||||
dep = d;
|
// dep = d;
|
||||||
}
|
// }
|
||||||
|
|
||||||
[Command("todo"),Description("Todo List")]
|
// [Command("todo"),Description("Todo List")]
|
||||||
|
|
||||||
public async Task TodoAsync(CommandContext ctx, string command,params string[] todo)
|
// public async Task TodoAsync(CommandContext ctx, string command,params string[] todo)
|
||||||
{
|
// {
|
||||||
await ctx.TriggerTypingAsync();
|
// await ctx.TriggerTypingAsync();
|
||||||
string args = string.Join(" ",todo);
|
// string args = string.Join(" ",todo);
|
||||||
switch (command.ToUpperInvariant())
|
// switch (command.ToUpperInvariant())
|
||||||
{
|
// {
|
||||||
case "ADD":
|
// case "ADD":
|
||||||
|
|
||||||
var todoDto = new TodoDTO
|
// var todoDto = new TodoDTO
|
||||||
{
|
// {
|
||||||
Created = DateTime.Now,
|
// Created = DateTime.Now,
|
||||||
Done = false,
|
// Done = false,
|
||||||
Deleted = null,
|
// Deleted = null,
|
||||||
Task = args,
|
// Task = args,
|
||||||
User = ctx.User.Username,
|
// User = ctx.User.Username,
|
||||||
};
|
// };
|
||||||
dep.WebService.RestService.UpdateTodo(todoDto);
|
// dep.WebService.RestService.UpdateTodo(todoDto);
|
||||||
//dep.WebService.RestService.UpdateGame();
|
// //dep.WebService.RestService.UpdateGame();
|
||||||
break;
|
// break;
|
||||||
case "LIST":
|
// case "LIST":
|
||||||
var todoDtos = dep.WebService.RestService.GetTodos();
|
// var todoDtos = dep.WebService.RestService.GetTodos();
|
||||||
StringBuilder sb = new StringBuilder();
|
// StringBuilder sb = new StringBuilder();
|
||||||
sb.AppendLine("Todos: ");
|
// sb.AppendLine("Todos: ");
|
||||||
if (todoDtos!=null && todoDtos.Count>0)
|
// if (todoDtos!=null && todoDtos.Count>0)
|
||||||
{
|
// {
|
||||||
foreach (var task in todoDtos)
|
// foreach (var task in todoDtos)
|
||||||
{
|
// {
|
||||||
string taskStatus = task.Done ? ":white_check_mark:" : ":negative_squared_cross_mark:";
|
// string taskStatus = task.Done ? ":white_check_mark:" : ":negative_squared_cross_mark:";
|
||||||
sb.AppendLine($"{task.Id} | {taskStatus} | {task.User} | {task.Task}");
|
// sb.AppendLine($"{task.Id} | {taskStatus} | {task.User} | {task.Task}");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
sb.AppendLine("None.");
|
// sb.AppendLine("None.");
|
||||||
}
|
// }
|
||||||
await ctx.RespondAsync(sb.ToString());
|
// await ctx.RespondAsync(sb.ToString());
|
||||||
break;
|
// break;
|
||||||
case "DEL":
|
// case "DEL":
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
int id = int.Parse(todo[0]);
|
// int id = int.Parse(todo[0]);
|
||||||
await ctx.RespondAsync(dep.WebService.RestService.DeleteTodo(id) ? $"Deleted" : $"Error");
|
// await ctx.RespondAsync(dep.WebService.RestService.DeleteTodo(id) ? $"Deleted" : $"Error");
|
||||||
}
|
// }
|
||||||
catch (Exception e)
|
// catch (Exception e)
|
||||||
{
|
// {
|
||||||
await ctx.RespondAsync($"Error {e.Message}");
|
// await ctx.RespondAsync($"Error {e.Message}");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case "V":
|
// case "V":
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
int id = int.Parse(todo[0]);
|
// int id = int.Parse(todo[0]);
|
||||||
var todoById = dep.WebService.RestService.GetTodoById(id);
|
// var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||||
todoById.Done = true;
|
// todoById.Done = true;
|
||||||
dep.WebService.RestService.UpdateTodo(todoById);
|
// dep.WebService.RestService.UpdateTodo(todoById);
|
||||||
await ctx.RespondAsync($"Done : {todoById.Id} - {todoById.Task}");
|
// await ctx.RespondAsync($"Done : {todoById.Id} - {todoById.Task}");
|
||||||
}
|
// }
|
||||||
catch (Exception e)
|
// catch (Exception e)
|
||||||
{
|
// {
|
||||||
await ctx.RespondAsync($"Error {e.Message}");
|
// await ctx.RespondAsync($"Error {e.Message}");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case "X":
|
// case "X":
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
int id = int.Parse(todo[0]);
|
// int id = int.Parse(todo[0]);
|
||||||
var todoById = dep.WebService.RestService.GetTodoById(id);
|
// var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||||
todoById.Done = false;
|
// todoById.Done = false;
|
||||||
dep.WebService.RestService.UpdateTodo(todoById);
|
// dep.WebService.RestService.UpdateTodo(todoById);
|
||||||
await ctx.RespondAsync($"Undone : {todoById.Id} - {todoById.Task}");
|
// await ctx.RespondAsync($"Undone : {todoById.Id} - {todoById.Task}");
|
||||||
}
|
// }
|
||||||
catch (Exception e)
|
// catch (Exception e)
|
||||||
{
|
// {
|
||||||
await ctx.RespondAsync($"Erreur {e.Message}");
|
// await ctx.RespondAsync($"Erreur {e.Message}");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case "TRUNC":
|
// case "TRUNC":
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
|
|
||||||
var todos = dep.WebService.RestService.GetTodos();
|
// var todos = dep.WebService.RestService.GetTodos();
|
||||||
await ctx.RespondAsync($"Sure ? (Y/N)");
|
// await ctx.RespondAsync($"Sure ? (Y/N)");
|
||||||
var interactivity = ctx.Client.GetInteractivityModule();
|
// var interactivity = ctx.Client.GetInteractivityModule();
|
||||||
var waitForMessageAsync = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains("Y")||xm.Content.Contains("N"), TimeSpan.FromSeconds(10));
|
// var waitForMessageAsync = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains("Y")||xm.Content.Contains("N"), TimeSpan.FromSeconds(10));
|
||||||
if (waitForMessageAsync!= null)
|
// if (waitForMessageAsync!= null)
|
||||||
{
|
// {
|
||||||
if (waitForMessageAsync.Message.Content == "Y")
|
// if (waitForMessageAsync.Message.Content == "Y")
|
||||||
{
|
// {
|
||||||
foreach (var task in todos)
|
// foreach (var task in todos)
|
||||||
{
|
// {
|
||||||
dep.WebService.RestService.DeleteTodo(task.Id);
|
// dep.WebService.RestService.DeleteTodo(task.Id);
|
||||||
await ctx.RespondAsync($"Deleted - {task.Id}");
|
// await ctx.RespondAsync($"Deleted - {task.Id}");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Exception e)
|
// catch (Exception e)
|
||||||
{
|
// {
|
||||||
await ctx.RespondAsync($"Erreur {e.Message}");
|
// await ctx.RespondAsync($"Erreur {e.Message}");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case "HELP":
|
// case "HELP":
|
||||||
|
|
||||||
|
|
||||||
await ctx.RespondAsync($"Todo:\n" +
|
// await ctx.RespondAsync($"Todo:\n" +
|
||||||
$"-Add : Add todo\n" +
|
// $"-Add : Add todo\n" +
|
||||||
$"-Del : Delete todo\n" +
|
// $"-Del : Delete todo\n" +
|
||||||
$"-V : check todo\n" +
|
// $"-V : check todo\n" +
|
||||||
$"-X : uncheck todo\n");
|
// $"-X : uncheck todo\n");
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
await ctx.RespondAsync($"Need some help ? !todo help");
|
// await ctx.RespondAsync($"Need some help ? !todo help");
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
//await ctx.RespondAsync($"command : {command}, todo: {todo} ");
|
// //await ctx.RespondAsync($"command : {command}, todo: {todo} ");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
|
||||||
{
|
|
||||||
public class Twitch
|
|
||||||
{
|
|
||||||
private readonly Dependencies dep;
|
|
||||||
|
|
||||||
public Twitch(Dependencies d)
|
|
||||||
{
|
|
||||||
dep = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("twitch")]
|
|
||||||
public async Task TwitchAsync(CommandContext ctx)
|
|
||||||
{
|
|
||||||
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,6 +25,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="Quotes.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="settings.json">
|
<None Update="settings.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
@@ -84,10 +84,11 @@ namespace LaDOSE.DiscordBot
|
|||||||
});
|
});
|
||||||
|
|
||||||
_cnext.RegisterCommands<Result>();
|
_cnext.RegisterCommands<Result>();
|
||||||
_cnext.RegisterCommands<Twitch>();
|
_cnext.RegisterCommands<Public>();
|
||||||
_cnext.RegisterCommands<Shutdown>();
|
_cnext.RegisterCommands<Shutdown>();
|
||||||
_cnext.RegisterCommands<Todo>();
|
//_cnext.RegisterCommands<Todo>();
|
||||||
_cnext.RegisterCommands<Hokuto>();
|
_cnext.RegisterCommands<Hokuto>();
|
||||||
|
_cnext.RegisterCommands<BotEvent>();
|
||||||
|
|
||||||
|
|
||||||
//discord.MessageCreated += async e =>
|
//discord.MessageCreated += async e =>
|
||||||
|
|||||||
2405
LaDOSE.Src/LaDOSE.DiscordBot/Quotes.txt
Normal file
2405
LaDOSE.Src/LaDOSE.DiscordBot/Quotes.txt
Normal file
File diff suppressed because it is too large
Load Diff
23
LaDOSE.Src/LaDOSE.Entity/BotEvent/BotEvent.cs
Normal file
23
LaDOSE.Src/LaDOSE.Entity/BotEvent/BotEvent.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace LaDOSE.Entity.BotEvent
|
||||||
|
{
|
||||||
|
public class BotEvent : Context.Entity
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public virtual ICollection<BotEventResult> Results { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
public class BotEventResult : Context.Entity
|
||||||
|
{
|
||||||
|
public int BotEventId { get; set; }
|
||||||
|
public BotEvent BotEvent { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string DiscordId { get; set; }
|
||||||
|
public bool Result { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using LaDOSE.Entity.Challonge;
|
using LaDOSE.Entity.Challonge;
|
||||||
|
|
||||||
using LaDOSE.Entity.Wordpress;
|
using LaDOSE.Entity.Wordpress;
|
||||||
|
using LaDOSE.Entity.BotEvent;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace LaDOSE.Entity.Context
|
namespace LaDOSE.Entity.Context
|
||||||
@@ -32,6 +32,10 @@ namespace LaDOSE.Entity.Context
|
|||||||
public DbSet<ChallongeParticipent> ChallongeParticipent { get; set; }
|
public DbSet<ChallongeParticipent> ChallongeParticipent { get; set; }
|
||||||
public DbSet<ChallongeTournament> ChallongeTournament { get; set; }
|
public DbSet<ChallongeTournament> ChallongeTournament { get; set; }
|
||||||
|
|
||||||
|
#region BotEvents
|
||||||
|
public DbSet<BotEvent.BotEvent> BotEvent { get; set; }
|
||||||
|
public DbSet<BotEventResult> BotEventResult { get; set; }
|
||||||
|
#endregion
|
||||||
public LaDOSEDbContext(DbContextOptions options) : base(options)
|
public LaDOSEDbContext(DbContextOptions options) : base(options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -69,7 +73,12 @@ namespace LaDOSE.Entity.Context
|
|||||||
.HasOne(e => e.Tournament)
|
.HasOne(e => e.Tournament)
|
||||||
.WithMany(e => e.Results)
|
.WithMany(e => e.Results)
|
||||||
.HasForeignKey(pt => pt.TournamentId);
|
.HasForeignKey(pt => pt.TournamentId);
|
||||||
|
|
||||||
|
modelBuilder.Entity<BotEventResult>()
|
||||||
|
.HasOne(e => e.BotEvent)
|
||||||
|
.WithMany(e => e.Results)
|
||||||
|
.HasForeignKey(pt => pt.BotEventId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//modelBuilder.Entity<Set>()
|
//modelBuilder.Entity<Set>()
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ namespace LaDOSE.REST
|
|||||||
return Post<List<int>, bool>("Api/Tournament/ParseChallonge", ids);
|
return Post<List<int>, bool>("Api/Tournament/ParseChallonge", ids);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
#region Tournamenet Event / Player
|
||||||
public List<EventDTO> GetAllEvents()
|
public List<EventDTO> GetAllEvents()
|
||||||
{
|
{
|
||||||
CheckToken();
|
CheckToken();
|
||||||
@@ -313,5 +313,33 @@ namespace LaDOSE.REST
|
|||||||
var restResponse = Client.Get<List<string>>(restRequest);
|
var restResponse = Client.Get<List<string>>(restRequest);
|
||||||
return restResponse.Data;
|
return restResponse.Data;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Bot Command
|
||||||
|
|
||||||
|
public bool CreateBotEvent(string eventName)
|
||||||
|
{
|
||||||
|
CheckToken();
|
||||||
|
var restRequest = new RestRequest($"/api/BotEvent/CreateBotEvent/{eventName}", Method.GET);
|
||||||
|
var restResponse = Client.Get<bool>(restRequest);
|
||||||
|
return restResponse.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BotEventDTO GetLastBotEvent()
|
||||||
|
{
|
||||||
|
CheckToken();
|
||||||
|
var restRequest = new RestRequest($"/api/BotEvent/GetLastBotEvent/", Method.GET);
|
||||||
|
var restResponse = Client.Post<BotEventDTO>(restRequest);
|
||||||
|
return restResponse.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ResultBotEvent(BotEventSendDTO result)
|
||||||
|
{
|
||||||
|
CheckToken();
|
||||||
|
return Post<BotEventSendDTO,bool>("/api/BotEvent/ResultBotEvent", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12
LaDOSE.Src/LaDOSE.Service/Interface/IBotEventService.cs
Normal file
12
LaDOSE.Src/LaDOSE.Service/Interface/IBotEventService.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using LaDOSE.Entity.BotEvent;
|
||||||
|
|
||||||
|
namespace LaDOSE.Business.Interface
|
||||||
|
{
|
||||||
|
public interface IBotEventService : IBaseService<BotEvent>
|
||||||
|
{
|
||||||
|
BotEvent GetLastEvent();
|
||||||
|
|
||||||
|
bool CreateEvent(string EventName);
|
||||||
|
bool SetResult(string discordId, string name, bool present);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
LaDOSE.Src/LaDOSE.Service/Service/BotEventService.cs
Normal file
55
LaDOSE.Src/LaDOSE.Service/Service/BotEventService.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using LaDOSE.Business.Interface;
|
||||||
|
using LaDOSE.Entity;
|
||||||
|
using LaDOSE.Entity.BotEvent;
|
||||||
|
using LaDOSE.Entity.Context;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LaDOSE.Business.Service
|
||||||
|
{
|
||||||
|
public class BotEventService : BaseService<BotEvent>, IBotEventService
|
||||||
|
{
|
||||||
|
public BotEventService(LaDOSEDbContext context) : base(context)
|
||||||
|
{
|
||||||
|
this._context = context;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateEvent(string EventName)
|
||||||
|
{
|
||||||
|
this._context.BotEvent.Add(new BotEvent { Name = EventName, Date = DateTime.Now });
|
||||||
|
return this._context.SaveChanges()!=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BotEvent GetLastEvent()
|
||||||
|
{
|
||||||
|
return this._context.BotEvent.Include(e=>e.Results).FirstOrDefault(e => e.Date == this._context.BotEvent.Max(e => e.Date));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SetResult(string discordId, string name, bool present)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(discordId))
|
||||||
|
throw new Exception("DiscordId invalid.");
|
||||||
|
|
||||||
|
BotEvent currentEvent = this.GetLastEvent();
|
||||||
|
|
||||||
|
if(currentEvent == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Oups");
|
||||||
|
}
|
||||||
|
BotEventResult res = currentEvent.Results.FirstOrDefault(e => e.DiscordId == discordId);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.Result = present;
|
||||||
|
_context.BotEventResult.Update(res);
|
||||||
|
_context.SaveChanges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.BotEventResult.Add(new BotEventResult() { BotEventId = currentEvent.Id, DiscordId = discordId, Result = present, Name = name });
|
||||||
|
return _context.SaveChanges()!=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user