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.Wordpress;
|
||||
using Result = LaDOSE.Entity.Challonge.Result;
|
||||
using LaDOSE.Entity.BotEvent;
|
||||
|
||||
namespace LaDOSE.Api
|
||||
{
|
||||
@@ -123,6 +124,8 @@ namespace LaDOSE.Api
|
||||
cfg.CreateMap<WPEvent, LaDOSE.DTO.WPEventDTO>();
|
||||
cfg.CreateMap<Result, LaDOSE.DTO.ResultDTO>();
|
||||
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<ChallongeParticipent, LaDOSE.DTO.ParticipentDTO>();
|
||||
@@ -150,6 +153,7 @@ namespace LaDOSE.Api
|
||||
services.AddScoped<IWordPressService, WordPressService>();
|
||||
services.AddScoped<ITodoService, TodoService>();
|
||||
services.AddScoped<IEventService, EventService>();
|
||||
services.AddScoped<IBotEventService, BotEventService>();
|
||||
|
||||
services.AddScoped<IPlayerService, PlayerService>();
|
||||
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")]
|
||||
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("update")]
|
||||
//public async Task UpdateAsync(CommandContext ctx)
|
||||
//[Command("last")]
|
||||
//public async Task LastAsync(CommandContext ctx)
|
||||
//{
|
||||
// //var tournament = await dep.ChallongeService.GetLastTournament();
|
||||
// //await ctx.RespondAsync($"Mise à jour effectuée");
|
||||
// var lastTournamentMessage = dep.WebService.GetLastChallonge();
|
||||
// await ctx.RespondAsync(lastTournamentMessage);
|
||||
//}
|
||||
|
||||
[Command("last")]
|
||||
public async Task LastAsync(CommandContext ctx)
|
||||
{
|
||||
var lastTournamentMessage = dep.WebService.GetLastChallonge();
|
||||
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("inscriptions")]
|
||||
//public async Task InscriptionsAsync(CommandContext ctx)
|
||||
//{
|
||||
// await ctx.TriggerTypingAsync();
|
||||
// var inscrits = dep.WebService.GetInscrits();
|
||||
// await ctx.RespondAsync(inscrits);
|
||||
//}
|
||||
|
||||
[RequireRolesAttribute("Staff")]
|
||||
[Command("UpdateDb")]
|
||||
|
||||
@@ -1,143 +1,143 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Interactivity;
|
||||
using LaDOSE.DTO;
|
||||
//using System;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
//using DSharpPlus.CommandsNext;
|
||||
//using DSharpPlus.CommandsNext.Attributes;
|
||||
//using DSharpPlus.Interactivity;
|
||||
//using LaDOSE.DTO;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
public class Todo
|
||||
{
|
||||
private readonly Dependencies dep;
|
||||
//namespace LaDOSE.DiscordBot.Command
|
||||
//{
|
||||
// public class Todo
|
||||
// {
|
||||
// private readonly Dependencies dep;
|
||||
|
||||
public Todo(Dependencies d)
|
||||
{
|
||||
dep = d;
|
||||
}
|
||||
// public Todo(Dependencies d)
|
||||
// {
|
||||
// dep = d;
|
||||
// }
|
||||
|
||||
[Command("todo"),Description("Todo List")]
|
||||
// [Command("todo"),Description("Todo List")]
|
||||
|
||||
public async Task TodoAsync(CommandContext ctx, string command,params string[] todo)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
string args = string.Join(" ",todo);
|
||||
switch (command.ToUpperInvariant())
|
||||
{
|
||||
case "ADD":
|
||||
// public async Task TodoAsync(CommandContext ctx, string command,params string[] todo)
|
||||
// {
|
||||
// await ctx.TriggerTypingAsync();
|
||||
// string args = string.Join(" ",todo);
|
||||
// switch (command.ToUpperInvariant())
|
||||
// {
|
||||
// case "ADD":
|
||||
|
||||
var todoDto = new TodoDTO
|
||||
{
|
||||
Created = DateTime.Now,
|
||||
Done = false,
|
||||
Deleted = null,
|
||||
Task = args,
|
||||
User = ctx.User.Username,
|
||||
};
|
||||
dep.WebService.RestService.UpdateTodo(todoDto);
|
||||
//dep.WebService.RestService.UpdateGame();
|
||||
break;
|
||||
case "LIST":
|
||||
var todoDtos = dep.WebService.RestService.GetTodos();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Todos: ");
|
||||
if (todoDtos!=null && todoDtos.Count>0)
|
||||
{
|
||||
foreach (var task in todoDtos)
|
||||
{
|
||||
string taskStatus = task.Done ? ":white_check_mark:" : ":negative_squared_cross_mark:";
|
||||
sb.AppendLine($"{task.Id} | {taskStatus} | {task.User} | {task.Task}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine("None.");
|
||||
}
|
||||
await ctx.RespondAsync(sb.ToString());
|
||||
break;
|
||||
case "DEL":
|
||||
try
|
||||
{
|
||||
int id = int.Parse(todo[0]);
|
||||
await ctx.RespondAsync(dep.WebService.RestService.DeleteTodo(id) ? $"Deleted" : $"Error");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ctx.RespondAsync($"Error {e.Message}");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "V":
|
||||
try
|
||||
{
|
||||
int id = int.Parse(todo[0]);
|
||||
var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||
todoById.Done = true;
|
||||
dep.WebService.RestService.UpdateTodo(todoById);
|
||||
await ctx.RespondAsync($"Done : {todoById.Id} - {todoById.Task}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ctx.RespondAsync($"Error {e.Message}");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "X":
|
||||
try
|
||||
{
|
||||
int id = int.Parse(todo[0]);
|
||||
var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||
todoById.Done = false;
|
||||
dep.WebService.RestService.UpdateTodo(todoById);
|
||||
await ctx.RespondAsync($"Undone : {todoById.Id} - {todoById.Task}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ctx.RespondAsync($"Erreur {e.Message}");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "TRUNC":
|
||||
try
|
||||
{
|
||||
// var todoDto = new TodoDTO
|
||||
// {
|
||||
// Created = DateTime.Now,
|
||||
// Done = false,
|
||||
// Deleted = null,
|
||||
// Task = args,
|
||||
// User = ctx.User.Username,
|
||||
// };
|
||||
// dep.WebService.RestService.UpdateTodo(todoDto);
|
||||
// //dep.WebService.RestService.UpdateGame();
|
||||
// break;
|
||||
// case "LIST":
|
||||
// var todoDtos = dep.WebService.RestService.GetTodos();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.AppendLine("Todos: ");
|
||||
// if (todoDtos!=null && todoDtos.Count>0)
|
||||
// {
|
||||
// foreach (var task in todoDtos)
|
||||
// {
|
||||
// string taskStatus = task.Done ? ":white_check_mark:" : ":negative_squared_cross_mark:";
|
||||
// sb.AppendLine($"{task.Id} | {taskStatus} | {task.User} | {task.Task}");
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sb.AppendLine("None.");
|
||||
// }
|
||||
// await ctx.RespondAsync(sb.ToString());
|
||||
// break;
|
||||
// case "DEL":
|
||||
// try
|
||||
// {
|
||||
// int id = int.Parse(todo[0]);
|
||||
// await ctx.RespondAsync(dep.WebService.RestService.DeleteTodo(id) ? $"Deleted" : $"Error");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// await ctx.RespondAsync($"Error {e.Message}");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
// case "V":
|
||||
// try
|
||||
// {
|
||||
// int id = int.Parse(todo[0]);
|
||||
// var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||
// todoById.Done = true;
|
||||
// dep.WebService.RestService.UpdateTodo(todoById);
|
||||
// await ctx.RespondAsync($"Done : {todoById.Id} - {todoById.Task}");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// await ctx.RespondAsync($"Error {e.Message}");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
// case "X":
|
||||
// try
|
||||
// {
|
||||
// int id = int.Parse(todo[0]);
|
||||
// var todoById = dep.WebService.RestService.GetTodoById(id);
|
||||
// todoById.Done = false;
|
||||
// dep.WebService.RestService.UpdateTodo(todoById);
|
||||
// await ctx.RespondAsync($"Undone : {todoById.Id} - {todoById.Task}");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// await ctx.RespondAsync($"Erreur {e.Message}");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
// case "TRUNC":
|
||||
// try
|
||||
// {
|
||||
|
||||
var todos = dep.WebService.RestService.GetTodos();
|
||||
await ctx.RespondAsync($"Sure ? (Y/N)");
|
||||
var interactivity = ctx.Client.GetInteractivityModule();
|
||||
var waitForMessageAsync = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains("Y")||xm.Content.Contains("N"), TimeSpan.FromSeconds(10));
|
||||
if (waitForMessageAsync!= null)
|
||||
{
|
||||
if (waitForMessageAsync.Message.Content == "Y")
|
||||
{
|
||||
foreach (var task in todos)
|
||||
{
|
||||
dep.WebService.RestService.DeleteTodo(task.Id);
|
||||
await ctx.RespondAsync($"Deleted - {task.Id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ctx.RespondAsync($"Erreur {e.Message}");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "HELP":
|
||||
// var todos = dep.WebService.RestService.GetTodos();
|
||||
// await ctx.RespondAsync($"Sure ? (Y/N)");
|
||||
// var interactivity = ctx.Client.GetInteractivityModule();
|
||||
// var waitForMessageAsync = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains("Y")||xm.Content.Contains("N"), TimeSpan.FromSeconds(10));
|
||||
// if (waitForMessageAsync!= null)
|
||||
// {
|
||||
// if (waitForMessageAsync.Message.Content == "Y")
|
||||
// {
|
||||
// foreach (var task in todos)
|
||||
// {
|
||||
// dep.WebService.RestService.DeleteTodo(task.Id);
|
||||
// await ctx.RespondAsync($"Deleted - {task.Id}");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// await ctx.RespondAsync($"Erreur {e.Message}");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
// case "HELP":
|
||||
|
||||
|
||||
await ctx.RespondAsync($"Todo:\n" +
|
||||
$"-Add : Add todo\n" +
|
||||
$"-Del : Delete todo\n" +
|
||||
$"-V : check todo\n" +
|
||||
$"-X : uncheck todo\n");
|
||||
break;
|
||||
default:
|
||||
await ctx.RespondAsync($"Need some help ? !todo help");
|
||||
break;
|
||||
}
|
||||
//await ctx.RespondAsync($"command : {command}, todo: {todo} ");
|
||||
}
|
||||
}
|
||||
}
|
||||
// await ctx.RespondAsync($"Todo:\n" +
|
||||
// $"-Add : Add todo\n" +
|
||||
// $"-Del : Delete todo\n" +
|
||||
// $"-V : check todo\n" +
|
||||
// $"-X : uncheck todo\n");
|
||||
// break;
|
||||
// default:
|
||||
// await ctx.RespondAsync($"Need some help ? !todo help");
|
||||
// break;
|
||||
// }
|
||||
// //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>
|
||||
<None Update="Quotes.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="settings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -84,10 +84,11 @@ namespace LaDOSE.DiscordBot
|
||||
});
|
||||
|
||||
_cnext.RegisterCommands<Result>();
|
||||
_cnext.RegisterCommands<Twitch>();
|
||||
_cnext.RegisterCommands<Public>();
|
||||
_cnext.RegisterCommands<Shutdown>();
|
||||
_cnext.RegisterCommands<Todo>();
|
||||
//_cnext.RegisterCommands<Todo>();
|
||||
_cnext.RegisterCommands<Hokuto>();
|
||||
_cnext.RegisterCommands<BotEvent>();
|
||||
|
||||
|
||||
//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.Wordpress;
|
||||
using LaDOSE.Entity.BotEvent;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LaDOSE.Entity.Context
|
||||
@@ -32,6 +32,10 @@ namespace LaDOSE.Entity.Context
|
||||
public DbSet<ChallongeParticipent> ChallongeParticipent { 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)
|
||||
{
|
||||
}
|
||||
@@ -70,6 +74,11 @@ namespace LaDOSE.Entity.Context
|
||||
.WithMany(e => e.Results)
|
||||
.HasForeignKey(pt => pt.TournamentId);
|
||||
|
||||
modelBuilder.Entity<BotEventResult>()
|
||||
.HasOne(e => e.BotEvent)
|
||||
.WithMany(e => e.Results)
|
||||
.HasForeignKey(pt => pt.BotEventId);
|
||||
|
||||
|
||||
|
||||
//modelBuilder.Entity<Set>()
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace LaDOSE.REST
|
||||
return Post<List<int>, bool>("Api/Tournament/ParseChallonge", ids);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Tournamenet Event / Player
|
||||
public List<EventDTO> GetAllEvents()
|
||||
{
|
||||
CheckToken();
|
||||
@@ -313,5 +313,33 @@ namespace LaDOSE.REST
|
||||
var restResponse = Client.Get<List<string>>(restRequest);
|
||||
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