DeukBot4/DeukBot4/MessageHandlers/JokeHandling/DadJoke.cs

33 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Discord;
namespace DeukBot4.MessageHandlers.JokeHandling
{
internal class DadJoke : IJokeController
{
public string Id => "dad";
public string Name => "Hi I'm dad";
private readonly Regex _regex = new Regex(
@"(\s|^)i(`||'| a)?m (?<word>((?!(i(`||'| a)?m)).){3,15})$",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
public async Task Run(ReceivedMessage message)
{
if (!(message.Message.Author is IGuildUser guildUser))
return;
var content = message.Message.Content;
var match = _regex.Match(content);
if (match.Success)
{
if (message.IsHandled)
return;
message.IsHandled = true;
var newName = match.Groups["word"].Value;
await message.Message.Channel.SendMessageAsync($"Hi {newName}, i'm Deukbot");
await guildUser.ModifyAsync(user => user.Nickname = newName);
}
}
}
}