discord-bot/CompatBot/EventHandlers/TableFlipMonitor.cs

74 lines
2.9 KiB
C#
Raw Normal View History

2018-11-12 23:37:13 +00:00
using System;
using System.Threading.Tasks;
2019-04-28 14:06:27 +00:00
using CompatApiClient.Utils;
using CompatBot.Utils;
2019-04-28 14:06:27 +00:00
using DSharpPlus.Entities;
2018-11-12 23:37:13 +00:00
using DSharpPlus.EventArgs;
namespace CompatBot.EventHandlers
{
internal static class TableFlipMonitor
{
private static readonly char[] OpenParen = {'(', '', 'ʕ'};
public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
if (DefaultHandlerFilter.IsFluff(args.Message))
2018-11-12 23:37:13 +00:00
return;
/*
* (°°
* ( Д)
* ()
* (
* (Д)/
* (^_^)
* (/¯ )/¯ ~
*
2018-11-16 14:27:20 +00:00
* this might look the same, but only because of the font choice
*
2018-11-12 23:37:13 +00:00
*
*
*/
try
{
var content = args.Message.Content;
2018-11-12 23:37:13 +00:00
if (!(content.Contains("┻━┻") ||
content.Contains("┻━┻")))
return;
var tableIdx = content.IndexOf("┻━┻");
if (tableIdx < 0)
tableIdx = content.IndexOf("┻━┻");
var faceIdx = content[..tableIdx].LastIndexOfAny(OpenParen);
2018-11-12 23:37:13 +00:00
var face = content.Substring(faceIdx, tableIdx - faceIdx);
2019-04-28 14:11:45 +00:00
if (face.Length > 30)
2019-04-28 14:06:27 +00:00
return;
2018-11-12 23:37:13 +00:00
var reverseFace = face
.Replace("(╯", "╯(").Replace("(ノ", "ノ(").Replace("(", "(").Replace("(/¯", @"\_/(")
.Replace(")╯", "╯)").Replace(")ノ", "ノ)").Replace(")", ")").Replace(")/¯", @"\_/)")
.Replace("(╯", "╯(").Replace("(ノ", "ノ(").Replace("", "").Replace("/¯", @"\_/")
.Replace(")╯", "╯)").Replace(")ノ", "ノ)").Replace("", "").Replace("/¯", @"\_/")
.Replace("ʕ╯", "╯ʕ").Replace("ʕノ", "ノʕ").Replace("ʕノ", "ノʕ").Replace("ʕ/¯", @"\_/ʕ")
.Replace("ʔ╯", "╯ʔ").Replace("ʔノ", "ノʔ").Replace("ʔ", "ʔ").Replace("ʔ/¯", @"\_/ʔ")
.TrimEnd('︵', '彡', ' ', ' ', '~', '');
if (reverseFace == face)
return;
2019-04-28 14:06:27 +00:00
var faceLength = reverseFace.Length;
if (faceLength > 5 + 4)
reverseFace = $"{reverseFace[..2]}ಠ益ಠ{reverseFace[^2..]}";
2019-04-28 14:06:27 +00:00
await args.Channel.SendMessageAsync("┬─┬ " + reverseFace.Sanitize()).ConfigureAwait(false);
2018-11-12 23:37:13 +00:00
}
catch (Exception e)
{
Config.Log.Warn(e);
}
}
}
}