From 6097515b5b9eb1cb3b4b684b5b818e44914948d3 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 12 Aug 2018 13:43:14 +0200 Subject: [PATCH] Add sarcastic responses when someone says thanks or thank you --- DeukBot4/MessageHandlers/JokeHandlers.cs | 20 ++++++++++++++++++++ DeukBot4/MessageHandlers/MainHandler.cs | 1 + 2 files changed, 21 insertions(+) diff --git a/DeukBot4/MessageHandlers/JokeHandlers.cs b/DeukBot4/MessageHandlers/JokeHandlers.cs index 4359044..63da5b6 100644 --- a/DeukBot4/MessageHandlers/JokeHandlers.cs +++ b/DeukBot4/MessageHandlers/JokeHandlers.cs @@ -1,4 +1,6 @@ +using System; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using DeukBot4.APIHandlers; using DeukBot4.Utilities; @@ -67,5 +69,23 @@ namespace DeukBot4.MessageHandlers } + private static readonly Regex ThanksMatcher = new Regex(@"(?i)((\b)thanks*(\W|$)+)"); + private static readonly string[] ThanksResponses = { + "You're welcome!", "No problem", + "It was the least I could do, I always do the least I can do!", + "Yes, well, we'd be absolutely nowhere without me.", + "Yeah no problem, I'm the only one who does work around here anyway", + }; + private static readonly Random Rand = new Random(); + public static async Task ThanksHandler(SocketMessage message) + { + var content = message.Content; + if (ThanksMatcher.IsMatch(content)) + { + var response = ThanksResponses[Rand.Next(0, ThanksResponses.Length)]; + message.Channel.SendMessageAsync(response); + } + } + } } \ No newline at end of file diff --git a/DeukBot4/MessageHandlers/MainHandler.cs b/DeukBot4/MessageHandlers/MainHandler.cs index 63c2fa1..410a174 100644 --- a/DeukBot4/MessageHandlers/MainHandler.cs +++ b/DeukBot4/MessageHandlers/MainHandler.cs @@ -25,6 +25,7 @@ namespace DeukBot4.MessageHandlers ImageBackupHandler.Backup(message); JokeHandlers.DeltaHandler(message); JokeHandlers.DadJokeHandler(message); + JokeHandlers.ThanksHandler(message); #pragma warning restore 4014 } catch (Exception e)