DeukBot4/DeukBot4/MessageHandlers/JokeHandlers.cs

93 lines
3.1 KiB
C#

using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DeukBot4.APIHandlers;
using DeukBot4.Utilities;
using Discord;
using Discord.WebSocket;
namespace DeukBot4.MessageHandlers
{
public static class JokeHandlers
{
public static async Task DeltaHandler(SocketMessage message)
{
var lowerCasedContent = message.Content.ToLowerInvariant().RemoveSpecialCharacters();
if (lowerCasedContent.Contains("origin"))
return;
var lowerSplit = lowerCasedContent.Split(' ');
if (lowerSplit.Select(s => Lehvenstein.LevenshteinDistance(s, "delta")).Any(diff => diff <= 1))
{
var warning = "uhh excuse me it's called\n Origin and it's an art";
await message.Channel.SendFileAsync(await CatPicHandler.GetCatPicture(warning), "cat_pic.png");
}
}
public static async Task DadJokeHandler(SocketMessage message)
{
if (!(message.Author is IGuildUser guildUser))
return;
string newName;
var content = message.Content;
var lower = content.ToLowerInvariant();
if (lower.StartsWith("hi "))
{
lower = lower.Remove(0, 3);
content = content.Remove(0, 3);
}
else if (lower.StartsWith("hello "))
{
lower = lower.Remove(0, 6);
content = content.Remove(0, 6);
}
if (lower[0] != 'i')
return;
if (lower.StartsWith("i'm "))
{
newName = content.Remove(0, 4);
}
else if (lower.StartsWith("im "))
{
newName = content.Remove(0, 3);
}
else if (lower.StartsWith("i am "))
{
newName = content.Remove(0, 5);
}
else
{
return;
}
if (newName.Length > 15)
return;
await message.Channel.SendMessageAsync($"Hi {newName}, i'm Deukbot");
await guildUser.ModifyAsync(user => user.Nickname = newName);
}
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",
"I gotchu, bb."
};
private static int _pos = 0;
public static async Task ThanksHandler(SocketMessage message)
{
var content = message.Content;
if (ThanksMatcher.IsMatch(content))
{
var response = ThanksResponses[_pos];
_pos = (_pos + 1) % ThanksResponses.Length;
message.Channel.SendMessageAsync(response);
}
}
}
}