From 87a459aa6bc958afe40e5ae5bd75639bdf2e6081 Mon Sep 17 00:00:00 2001 From: skyjoshua Date: Thu, 12 Mar 2026 20:22:41 +0000 Subject: [PATCH] funny react --- Program.cs | 26 ++++++++++++++++++++++++++ utils.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Program.cs b/Program.cs index da31b5e..0e6a9cd 100644 --- a/Program.cs +++ b/Program.cs @@ -66,6 +66,32 @@ client.MessageService.MessageReceived += async (message) => } }; + if (Utils.ContainsAny(content, $"{prefix}react")) + { + if (message.AuthorUserId != ownerId) return; + + string[] args = content.Split(' ', StringSplitOptions.RemoveEmptyEntries); + if (args.Length < 2) return; + string emoji = args[1]; + + var interceptor = new Utils.ReactionInterceptor(Console.Out); + Console.SetOut(interceptor); + + while (true) + { + interceptor.Reset(); + await message.AddReactionAsync(emoji); + if (interceptor.DetectedAlreadyExists) + { + Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }); + Console.WriteLine("Reaction already exists, stopping."); + break; + } + } + + Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }); + } + var echoprefixes = new[] { $"{prefix}echo"}; if (Utils.ContainsAny(content, echoprefixes)) { diff --git a/utils.cs b/utils.cs index 5412a4e..f6d3776 100644 --- a/utils.cs +++ b/utils.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Text.Json; using Valour.Sdk.Models; using Valour.Sdk.Client; +using System.Text; namespace SkyBot { @@ -105,5 +106,33 @@ namespace SkyBot initializedPlanets.Add(planet.Id); } } + + public class ReactionInterceptor : TextWriter + { + private readonly TextWriter _original; + public bool DetectedAlreadyExists { get; private set; } + public override Encoding Encoding => _original.Encoding; + + public ReactionInterceptor(TextWriter original) + { + _original = original; + } + + public void Reset() => DetectedAlreadyExists = false; + + public override void WriteLine(string value) + { + if (value?.Contains("Reaction already exists") == true) + DetectedAlreadyExists = true; + _original.WriteLine(value); + } + + public override void Write(string value) + { + if (value?.Contains("Reaction already exists") == true) + DetectedAlreadyExists = true; + _original.Write(value); + } + } }; }; \ No newline at end of file