Better handling of opinion method, made responding to a message a bit easier

This commit is contained in:
Deukhoofd 2018-03-30 16:45:40 +02:00
parent b4a8923f9e
commit 865f8a5083
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
6 changed files with 86 additions and 61 deletions

2
DeukBot4.sln.DotSettings Normal file
View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TTS/@EntryIndexedValue">TTS</s:String></wpf:ResourceDictionary>

View File

@ -29,14 +29,14 @@ namespace DeukBot4.MessageHandlers.CommandHandler
embed.AddField("Software", "Deukbot 4.0", true); embed.AddField("Software", "Deukbot 4.0", true);
embed.AddField("Creator", "Deukhoofd#7361", 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)] [Command("ping", PermissionLevel.Everyone)]
[CommandHelp("Simple Ping Pong Response", "Generates a simple Pong response when triggered")] [CommandHelp("Simple Ping Pong Response", "Generates a simple Pong response when triggered")]
public async Task Ping(CommandRequest request) public async Task Ping(CommandRequest request)
{ {
await request.OriginalMessage.Channel.SendMessageAsync("Pong"); await request.SendMessageAsync("Pong");
} }
[Command("help", PermissionLevel.Everyone)] [Command("help", PermissionLevel.Everyone)]
@ -51,13 +51,12 @@ usage:
{ {
if (request.Parameters.Length == 0) if (request.Parameters.Length == 0)
{ {
await request.OriginalMessage.Channel.SendMessageAsync( await request.SendMessageAsync(HelpCommandGenerator.GenerateFullHelp(request.RequestPermissions));
HelpCommandGenerator.GenerateFullHelp(request.RequestPermissions));
} }
else else
{ {
await request.OriginalMessage.Channel.SendMessageAsync("", embed: await request.SendMessageAsync("",
HelpCommandGenerator.GenerateSpecificHelp(request.Parameters[0].AsString(), embed: HelpCommandGenerator.GenerateSpecificHelp(request.Parameters[0].AsString(),
request.RequestPermissions)); request.RequestPermissions));
} }
} }
@ -67,56 +66,7 @@ usage:
[CommandParameters(ParameterMatcher.ParameterType.Remainder)] [CommandParameters(ParameterMatcher.ParameterType.Remainder)]
public async Task BotOpinion(CommandRequest request) public async Task BotOpinion(CommandRequest request)
{ {
var random = new Random(); await request.SendMessageAsync(await BotOpinions.GetOpinion(request));
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));
}
}
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."
};
}
} }

View File

@ -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 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) 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; return;
} }
@ -46,6 +46,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
// and kick // and kick
await user.KickAsync(reason); await user.KickAsync(reason);
await request.SendMessageAsync($"User was kicked: {user.Username}");
} }
[Command("ban", PermissionLevel.Moderator)] [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 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) 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; return;
} }
@ -77,6 +78,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
// and ban // and ban
await channel.Guild.AddBanAsync(user, 0, reason); await channel.Guild.AddBanAsync(user, 0, reason);
await request.SendMessageAsync($"User was banned: {user.Username}");
} }
} }
} }

View File

@ -67,14 +67,14 @@ namespace DeukBot4.MessageHandlers.CommandHandler
if (request.Parameters.Length == 0) 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"); $"You did not give a valid role ID. Use ``!roles`` to list all current server roles, along with their ids");
return; return;
} }
if (!ulong.TryParse(request.Parameters[0].AsString(), out var roleId)) 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"); $"You did not give a valid role ID. Use ``!roles`` to list all current server roles, along with their ids");
return; return;
} }
@ -82,7 +82,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
var role = serverChannel.Guild.GetRole(roleId); var role = serverChannel.Guild.GetRole(roleId);
if (role == null) 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; return;
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using DeukBot4.MessageHandlers.Permissions; using DeukBot4.MessageHandlers.Permissions;
using Discord;
using Discord.WebSocket; using Discord.WebSocket;
namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
@ -31,6 +32,11 @@ namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
OK, UnknownCommand, Invalid, Forbidden, InvalidParameters 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) public static async Task<(CommandRequest, RequestCode, object)> Create(SocketMessage message)
{ {
var originalMessage = message; var originalMessage = message;

View File

@ -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<string> 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."
};
}
}