Bot Event
This commit is contained in:
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
Reference in New Issue
Block a user