discord-bot/CompatBot/EventHandlers/TableFlipMonitor.cs

74 lines
2.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
using System.Threading.Tasks;
using CompatApiClient.Utils;
using CompatBot.Utils;
using DSharpPlus.Entities;
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))
return;
/*
* (╯°□°)╯︵ ┻━┻
* ( ゜Д゜) ︵ ┻━┻
* (ノಠ益ಠ)ノ彡┻━┻
* (ノಥ益ಥ)ノ ┻━┻
* (ノಥДಥ)ノ︵┻━┻・/
* (^_^)ノ┻━┻
* (/¯◡ ‿ ◡)/¯ ~ ┻━┻
*
* this might look the same, but only because of the font choice
*
* ┻━┻
* ┻━┻
*/
try
{
var content = args.Message.Content;
if (!(content.Contains("┻━┻") ||
content.Contains("┻━┻")))
return;
var tableIdx = content.IndexOf("┻━┻");
if (tableIdx < 0)
tableIdx = content.IndexOf("┻━┻");
var faceIdx = content[..tableIdx].LastIndexOfAny(OpenParen);
var face = content.Substring(faceIdx, tableIdx - faceIdx);
if (face.Length > 30)
return;
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;
var faceLength = reverseFace.Length;
if (faceLength > 5 + 4)
reverseFace = $"{reverseFace[..2]}ಠ益ಠ{reverseFace[^2..]}";
await args.Channel.SendMessageAsync("┬─┬ " + reverseFace.Sanitize()).ConfigureAwait(false);
}
catch (Exception e)
{
Config.Log.Warn(e);
}
}
}
}