From 865f8a508364b6ec658e6ae3a76f38c882ea8708 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 30 Mar 2018 16:45:40 +0200 Subject: [PATCH] Better handling of opinion method, made responding to a message a bit easier --- DeukBot4.sln.DotSettings | 2 + .../Commands/GeneralCommands.cs | 62 ++---------------- .../Commands/ModeratorCommands.cs | 6 +- .../Commands/RolePermissionCommands.cs | 6 +- .../RequestStructure/CommandRequest.cs | 6 ++ DeukBot4/Utilities/BotOpinions.cs | 65 +++++++++++++++++++ 6 files changed, 86 insertions(+), 61 deletions(-) create mode 100644 DeukBot4.sln.DotSettings create mode 100644 DeukBot4/Utilities/BotOpinions.cs diff --git a/DeukBot4.sln.DotSettings b/DeukBot4.sln.DotSettings new file mode 100644 index 0000000..ca11ccf --- /dev/null +++ b/DeukBot4.sln.DotSettings @@ -0,0 +1,2 @@ + + TTS \ No newline at end of file diff --git a/DeukBot4/MessageHandlers/CommandHandler/Commands/GeneralCommands.cs b/DeukBot4/MessageHandlers/CommandHandler/Commands/GeneralCommands.cs index 523b364..5570dbe 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/Commands/GeneralCommands.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/Commands/GeneralCommands.cs @@ -29,14 +29,14 @@ namespace DeukBot4.MessageHandlers.CommandHandler embed.AddField("Software", "Deukbot 4.0", true); embed.AddField("Creator", "Deukhoofd#7361", true); - await request.OriginalMessage.Channel.SendMessageAsync("", embed: embed.Build()); + await request.SendMessageAsync("", embed: embed.Build()); } [Command("ping", PermissionLevel.Everyone)] [CommandHelp("Simple Ping Pong Response", "Generates a simple Pong response when triggered")] public async Task Ping(CommandRequest request) { - await request.OriginalMessage.Channel.SendMessageAsync("Pong"); + await request.SendMessageAsync("Pong"); } [Command("help", PermissionLevel.Everyone)] @@ -51,13 +51,12 @@ usage: { if (request.Parameters.Length == 0) { - await request.OriginalMessage.Channel.SendMessageAsync( - HelpCommandGenerator.GenerateFullHelp(request.RequestPermissions)); + await request.SendMessageAsync(HelpCommandGenerator.GenerateFullHelp(request.RequestPermissions)); } else { - await request.OriginalMessage.Channel.SendMessageAsync("", embed: - HelpCommandGenerator.GenerateSpecificHelp(request.Parameters[0].AsString(), + await request.SendMessageAsync("", + embed: HelpCommandGenerator.GenerateSpecificHelp(request.Parameters[0].AsString(), request.RequestPermissions)); } } @@ -67,56 +66,7 @@ usage: [CommandParameters(ParameterMatcher.ParameterType.Remainder)] public async Task BotOpinion(CommandRequest request) { - var random = new Random(); - var positive = random.Next(-20, 80) < (int) request.RequestPermissions; - - var extend = request.Parameters[0].AsString().ToLowerInvariant(); - if (extend.Contains("kill") || extend.Contains("suicide")) - { - await request.OriginalMessage.Channel.SendMessageAsync("That sounds like a bad idea to me"); - return; - } - if (extend.Contains("ban")) - { - if (extend.Contains("deuk")) - { - positive = false; - } - else - { - await request.OriginalMessage.Channel.SendMessageAsync("Absolutely, ban the fucker!"); - return; - } - } - - if (positive) - { - await request.OriginalMessage.Channel.SendMessageAsync(PositiveOpinions.Choice(random)); - } - else - { - await request.OriginalMessage.Channel.SendMessageAsync(NegativeOpinions.Choice(random)); - } + await request.SendMessageAsync(await BotOpinions.GetOpinion(request)); } - - private static readonly string[] PositiveOpinions = new[] - { - "I think you should go for it!", - "You can do it!", - "That sounds like a good idea to me!", - "Sure do it", - "Always remember there are people who love you", - "love u bb" - }; - private static readonly string[] NegativeOpinions = new[] - { - "I do not care for your pathetic worries humanoid. Leave me alone.", - "Absolutely not, who do you even think you are?", - "Ask me another time. Maybe I'll care then.", - "Too hungover atm, don't feel like answering questions.", - "Confirmation Received. Installing Cryptominers on your PC.", - "Fuck off please thanks.", - "If you don't get a brain within 15 minutes I'm legally allowed to ban you." - }; } } \ No newline at end of file diff --git a/DeukBot4/MessageHandlers/CommandHandler/Commands/ModeratorCommands.cs b/DeukBot4/MessageHandlers/CommandHandler/Commands/ModeratorCommands.cs index d858da4..a02bc12 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/Commands/ModeratorCommands.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/Commands/ModeratorCommands.cs @@ -33,7 +33,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler // if the user has sufficient permissions, or is deukbot, warn the user that he's not allowed to do that, and stop if (userPermissions >= PermissionLevel.Helper || user.Id == Program.Client.CurrentUser.Id) { - await request.OriginalMessage.Channel.SendMessageAsync("You are not allowed to kick that user"); + await request.SendMessageAsync("You are not allowed to kick that user"); return; } @@ -46,6 +46,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler // and kick await user.KickAsync(reason); + await request.SendMessageAsync($"User was kicked: {user.Username}"); } [Command("ban", PermissionLevel.Moderator)] @@ -64,7 +65,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler // if the user has sufficient permissions, or is deukbot, warn the user that he's not allowed to do that, and stop if (userPermissions >= PermissionLevel.Helper || user.Id == Program.Client.CurrentUser.Id) { - await request.OriginalMessage.Channel.SendMessageAsync("You are not allowed to ban that user"); + await request.SendMessageAsync("You are not allowed to ban that user"); return; } @@ -77,6 +78,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler // and ban await channel.Guild.AddBanAsync(user, 0, reason); + await request.SendMessageAsync($"User was banned: {user.Username}"); } } } \ No newline at end of file diff --git a/DeukBot4/MessageHandlers/CommandHandler/Commands/RolePermissionCommands.cs b/DeukBot4/MessageHandlers/CommandHandler/Commands/RolePermissionCommands.cs index cddfed9..8d4043f 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/Commands/RolePermissionCommands.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/Commands/RolePermissionCommands.cs @@ -67,14 +67,14 @@ namespace DeukBot4.MessageHandlers.CommandHandler if (request.Parameters.Length == 0) { - await request.OriginalMessage.Channel.SendMessageAsync( + await request.SendMessageAsync( $"You did not give a valid role ID. Use ``!roles`` to list all current server roles, along with their ids"); return; } if (!ulong.TryParse(request.Parameters[0].AsString(), out var roleId)) { - await request.OriginalMessage.Channel.SendMessageAsync( + await request.SendMessageAsync( $"You did not give a valid role ID. Use ``!roles`` to list all current server roles, along with their ids"); return; } @@ -82,7 +82,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler var role = serverChannel.Guild.GetRole(roleId); if (role == null) { - await request.OriginalMessage.Channel.SendMessageAsync("No role with that id exists on this server"); + await request.SendMessageAsync("No role with that id exists on this server"); return; } diff --git a/DeukBot4/MessageHandlers/CommandHandler/RequestStructure/CommandRequest.cs b/DeukBot4/MessageHandlers/CommandHandler/RequestStructure/CommandRequest.cs index ff6147c..9660cf7 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/RequestStructure/CommandRequest.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/RequestStructure/CommandRequest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading.Tasks; using DeukBot4.MessageHandlers.Permissions; +using Discord; using Discord.WebSocket; namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure @@ -31,6 +32,11 @@ namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure OK, UnknownCommand, Invalid, Forbidden, InvalidParameters } + public async Task SendMessageAsync(string text, bool isTTS = false, Embed embed = null) + { + await OriginalMessage.Channel.SendMessageAsync(text, isTTS, embed); + } + public static async Task<(CommandRequest, RequestCode, object)> Create(SocketMessage message) { var originalMessage = message; diff --git a/DeukBot4/Utilities/BotOpinions.cs b/DeukBot4/Utilities/BotOpinions.cs new file mode 100644 index 0000000..40ecedf --- /dev/null +++ b/DeukBot4/Utilities/BotOpinions.cs @@ -0,0 +1,65 @@ +using System; +using System.Threading.Tasks; +using DeukBot4.MessageHandlers.CommandHandler.RequestStructure; + +namespace DeukBot4.Utilities +{ + public static class BotOpinions + { + public static async Task GetOpinion(CommandRequest request) + { + var random = new Random(); + var positive = random.Next(-20, 80) < (int) request.RequestPermissions; + + var extend = request.Parameters[0].AsString().ToLowerInvariant(); + if (extend.Contains("kill") || extend.Contains("suicide")) + { + return "That sounds like a bad idea to me"; + } + if (extend.Contains("ban")) + { + if (extend.Contains("deuk")) + { + positive = false; + } + else + { + return "Absolutely, ban the fucker!"; + } + } + + return positive ?PositiveOpinions.Choice(random) : NegativeOpinions.Choice(random); + + } + + + private static readonly string[] PositiveOpinions = new[] + { + "I think you should go for it!", + "You can do it!", + "That sounds like a good idea to me!", + "Sure do it", + "Always remember there are people who love you", + "love u bb" + }; + private static readonly string[] NegativeOpinions = new[] + { + "I do not care for your pathetic worries humanoid. Leave me alone.", + "Absolutely not, who do you even think you are?", + "Ask me another time. Maybe I'll care then.", + "Too hungover atm, don't feel like answering questions.", + "Confirmation Received. Installing Cryptominers on your PC.", + "Fuck off please thanks.", + "If you don't get a brain within 15 minutes I'm legally allowed to ban you." + }; + + private static readonly string[] BanOpinions = new[] + { + "Absolutely, ban the fucker", + "Yeah do it, never cared for him anyway", + "Yeah he's probably 13 year old anyway", + "Fuck yeah get him out of here.", + "Yeah he's been getting on my nerves." + }; + } +} \ No newline at end of file