mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
* upgrade deps, remove wrong ppu hashes * upgrade compiler packages will require container pull after build * replace Regex with compiler-generated versions * use new collection initialization syntax * configure global defaults for regex * bump min amd driver version fixes #950 * add macos version check fixes #948 * fix #954 (!sudo log date)
97 lines
3.9 KiB
C#
97 lines
3.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using CompatApiClient.Utils;
|
||
using CompatBot.Commands;
|
||
using CompatBot.Utils;
|
||
using DSharpPlus;
|
||
using DSharpPlus.Entities;
|
||
using DSharpPlus.EventArgs;
|
||
using Microsoft.Extensions.Caching.Memory;
|
||
|
||
namespace CompatBot.EventHandlers;
|
||
|
||
internal static partial class TableFlipMonitor
|
||
{
|
||
[GeneratedRegex(@"(🎲|\s)+")]
|
||
private static partial Regex DiceRoll();
|
||
private static readonly char[] OpenParen = ['(', '(', 'ʕ'];
|
||
|
||
public static async Task OnMessageCreated(DiscordClient _, 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("🎲") && DiceRoll().IsMatch(content))
|
||
{
|
||
var count = 1;
|
||
var idx = content.IndexOf("🎲");
|
||
while (idx < content.Length && (idx = content.IndexOf("🎲", idx + 1)) > 0)
|
||
count++;
|
||
EmpathySimulationHandler.Throttling.Set(args.Channel.Id, new List<DiscordMessage> {args.Message}, EmpathySimulationHandler.ThrottleDuration);
|
||
await Misc.RollImpl(args.Message, $"{count}d6").ConfigureAwait(false);
|
||
return;
|
||
}
|
||
|
||
if (content.Trim() == "🥠")
|
||
{
|
||
EmpathySimulationHandler.Throttling.Set(args.Channel.Id, new List<DiscordMessage> {args.Message}, EmpathySimulationHandler.ThrottleDuration);
|
||
await Fortune.ShowFortune(args.Message, args.Author).ConfigureAwait(false);
|
||
return;
|
||
}
|
||
|
||
if (!(content.Contains("┻━┻") ||
|
||
content.Contains("┻━┻")))
|
||
return;
|
||
|
||
var tableIdx = content.IndexOf("┻━┻", StringComparison.Ordinal);
|
||
if (tableIdx < 0)
|
||
tableIdx = content.IndexOf("┻━┻", StringComparison.Ordinal);
|
||
var faceIdx = content[..tableIdx].LastIndexOfAny(OpenParen);
|
||
var face = content[faceIdx..tableIdx];
|
||
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);
|
||
}
|
||
}
|
||
} |