diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs index 2543c7f..858cda1 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Command/EventStaff.cs @@ -1,58 +1,55 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; using LaDOSE.DiscordBot.Service; using LaDOSE.DTO; namespace LaDOSE.DiscordBot.Command { - public class BotEvent : BaseCommandModule - { - private WebService dep; - public BotEvent(WebService d) - { - dep = d; - } - - [RequireRolesAttribute(RoleCheckMode.Any, "Staff")] - [Command("newevent")] - public async Task NewEventAsync(CommandContext ctx, string command) - { - - await ctx.RespondAsync(dep.RestService.CreateBotEvent(command).ToString()); - } - [RequireRolesAttribute(RoleCheckMode.Any,"Staff")] - [Command("staffs")] - public async Task StaffAsync(CommandContext ctx) - { - BotEventDTO currentEvent = dep.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(RoleCheckMode.Any, "Staff")] - [Command("present")] - public async Task PresentAsync(CommandContext ctx) - { - await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = true }).ToString()); - - - } - [RequireRolesAttribute(RoleCheckMode.Any, "Staff")] - [Command("absent")] - public async Task AbsentAsync(CommandContext ctx) - { - await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = false }).ToString()); - } - } + // public class BotEvent : BaseCommandModule + // { + // private WebService dep; + // public BotEvent(WebService d) + // { + // dep = d; + // } + // + // [Command("newevent")] + // public async Task NewEventAsync(CommandContext ctx, string command) + // { + // + // await ctx.RespondAsync(dep.RestService.CreateBotEvent(command).ToString()); + // } + // [RequireRolesAttribute(RoleCheckMode.Any,"Staff")] + // [Command("staffs")] + // public async Task StaffAsync(CommandContext ctx) + // { + // BotEventDTO currentEvent = dep.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(RoleCheckMode.Any, "Staff")] + // [Command("present")] + // public async Task PresentAsync(CommandContext ctx) + // { + // await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = true }).ToString()); + // + // + // } + // [RequireRolesAttribute(RoleCheckMode.Any, "Staff")] + // [Command("absent")] + // public async Task AbsentAsync(CommandContext ctx) + // { + // await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = false }).ToString()); + // } + // } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Hokuto.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Hokuto.cs index 63c0c2e..272750a 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Hokuto.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Hokuto.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; +using DSharpPlus.Commands; +using DSharpPlus.Commands.ArgumentModifiers; +using DSharpPlus.Commands.Processors.TextCommands; using DSharpPlus.Entities; namespace LaDOSE.DiscordBot.Command { - public class Hokuto : BaseCommandModule + public class Hokuto { private static List Games = new List { "2X", "3.3", "Karnov" }; @@ -21,14 +22,21 @@ namespace LaDOSE.DiscordBot.Command [Command("hokuto")] - public async Task HokutoUserAsync(CommandContext ctx, params DiscordMember[] user) + public async ValueTask HokutoUserAsync(TextCommandContext ctx) { var i = r.Next(0, 3); - if (user!=null && user.Length>0) + if (ctx.Message.MentionedUsers is { Count: 1 } ) { - await ctx.RespondAsync(ctx.User?.Mention + " vs " + user[0].Mention + " : " + Games[i].ToString()); + foreach (var arg in ctx.Message.MentionedUsers) + { + if (arg is DiscordUser member) + { + await ctx.RespondAsync(ctx.User?.Mention + " vs " + member.Mention + " : " + Games[i].ToString()); + return; + } + } } else { diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs index 8e6a180..992e718 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs @@ -4,12 +4,11 @@ using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; +using DSharpPlus.Commands; namespace LaDOSE.DiscordBot.Command { - public class Public : BaseCommandModule + public class Public { private static List Quotes { get; set; } diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj index df9db20..ebcfbfd 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj +++ b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj @@ -7,11 +7,12 @@ - - - + + + + diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs index bcad7b0..30e2e31 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs @@ -4,8 +4,12 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using DSharpPlus; +using DSharpPlus.Commands; +using DSharpPlus.Commands.Processors.SlashCommands; +using DSharpPlus.Commands.Processors.TextCommands; +using DSharpPlus.Commands.Processors.TextCommands.Parsing; +using DSharpPlus.Entities; using DSharpPlus.Interactivity; -using DSharpPlus.CommandsNext; using DSharpPlus.EventArgs; using DSharpPlus.Interactivity.Extensions; //using DSharpPlus.SlashCommands; @@ -20,7 +24,6 @@ namespace LaDOSE.DiscordBot { class Program { - static DiscordClient discord; //static InteractivityModule Interactivity { get; set; } static void Main(string[] args) @@ -42,107 +45,36 @@ namespace LaDOSE.DiscordBot var restUrl = builder["REST:Url"].ToString(); var restUser = builder["REST:User"].ToString(); var restPassword = builder["REST:Password"].ToString(); - - var service = new ServiceCollection() - .AddSingleton(typeof(WebService), new WebService(new Uri(restUrl), restUser, restPassword)) - .BuildServiceProvider(); - - + Console.WriteLine($"LaDOSE.Net Discord Bot"); - - discord = new DiscordClient(new DiscordConfiguration - { - Token = discordToken, - TokenType = TokenType.Bot, - //AutoReconnect = true, - //MinimumLogLevel = LogLevel.Debug, - //MessageCacheSize = 0, - }); - - discord.UseInteractivity(new InteractivityConfiguration - { - - // default pagination behaviour to just ignore the reactions - //PaginationBehaviour = TimeoutBehaviour.Ignore, - - // default pagination timeout to 5 minutes - //PaginationTimeout = TimeSpan.FromMinutes(5), - - // default timeout for other actions to 2 minutes - Timeout = TimeSpan.FromMinutes(2) - }); - + DiscordClientBuilder builder2 = DiscordClientBuilder.CreateDefault(discordToken, TextCommandProcessor.RequiredIntents | SlashCommandProcessor.RequiredIntents); var cts = new CancellationTokenSource(); - var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration() + // Setup the commands extension + builder2.UseCommands((IServiceProvider serviceProvider, CommandsExtension extension) => { - //CaseSensitive = false, - //EnableDefaultHelp = true, - //EnableDms = false, - //EnableMentionPrefix = true, - StringPrefixes = new List() { "/", "!" }, - //IgnoreExtraArguments = true, - Services = service + extension.AddCommands([typeof(Hokuto), typeof(Public)]); + TextCommandProcessor textCommandProcessor = new(); + extension.AddProcessor(textCommandProcessor); + }, new CommandsConfiguration() + { + // The default value is true, however it's shown here for clarity + RegisterDefaultCommandProcessors = true, + UseDefaultCommandErrorHandler = false + // DebugGuildId = Environment.GetEnvironmentVariable("DEBUG_GUILD_ID") ?? 0, }); + DiscordClient client = builder2.Build(); - //var slashCommands = discord.UseSlashCommands(new SlashCommandsConfiguration() {Services = service}); - //slashCommands.RegisterCommands(guildId:null); - - - //_cnext.RegisterCommands(); - _cnext.RegisterCommands(); - //_cnext.RegisterCommands(); - //_cnext.RegisterCommands(); - _cnext.RegisterCommands(); - _cnext.RegisterCommands(); - - foreach (var registeredCommandsKey in discord.GetCommandsNext().RegisteredCommands.Keys) - { - Console.WriteLine(registeredCommandsKey); - } - - - discord.Ready += (sender, eventArgs) => - { - Console.WriteLine($"Bot READY."); - return Task.CompletedTask; - }; - discord.GuildAvailable += (sender, eventArgs) => - { - - Console.WriteLine($"Joined Guild " + eventArgs.Guild.Name); - return Task.CompletedTask; - }; - - await discord.ConnectAsync(); + // We can specify a status for our bot. Let's set it to "playing" and set the activity to "with fire". + DiscordActivity status = new("Street Fighter", DiscordActivityType.Playing); + await client.ConnectAsync(status,DiscordUserStatus.Online); await Task.Delay(Timeout.Infinite); - //while (!cts.IsCancellationRequested) - //{ - // await Task.Delay(200); - // //if(discord.GetConnectionsAsync().Result.Count) - //} - } - - } - - //internal class SlashCommand : ApplicationCommandModule - //{ - // [SlashCommand("test", "A slash command made to test the DSharpPlusSlashCommands library!")] - - // public async Task TestCommand(InteractionContext ctx) - // { - - // await ctx.CreateResponseAsync("Lol"); - - // } - //} - } \ No newline at end of file