2018-10-08 17:51:19 +00:00
|
|
|
|
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";
|
|
|
|
|
|
2018-10-15 15:17:52 +00:00
|
|
|
|
private readonly Regex _regex = new Regex(@"(\s|^)i(`|’|'| a)?m (?<word>.{3,15})$",
|
2018-10-08 17:51:19 +00:00
|
|
|
|
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
|
|
|
|
|
2019-01-29 22:28:52 +00:00
|
|
|
|
public async Task Run(ReceivedMessage message)
|
2018-10-08 17:51:19 +00:00
|
|
|
|
{
|
2019-01-29 22:28:52 +00:00
|
|
|
|
if (!(message.Message.Author is IGuildUser guildUser))
|
2018-10-08 17:51:19 +00:00
|
|
|
|
return;
|
2019-01-29 22:28:52 +00:00
|
|
|
|
var content = message.Message.Content;
|
2018-10-08 17:51:19 +00:00
|
|
|
|
var match = _regex.Match(content);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
2019-01-29 22:28:52 +00:00
|
|
|
|
if (message.IsHandled)
|
|
|
|
|
return;
|
|
|
|
|
message.IsHandled = true;
|
2018-10-09 21:29:31 +00:00
|
|
|
|
var newName = match.Groups["word"].Value;
|
2019-01-29 22:28:52 +00:00
|
|
|
|
await message.Message.Channel.SendMessageAsync($"Hi {newName}, i'm Deukbot");
|
2018-10-08 17:51:19 +00:00
|
|
|
|
await guildUser.ModifyAsync(user => user.Nickname = newName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|