From 97fe14cf5a9c7c3d4ca220db4d26a2c79d02de23 Mon Sep 17 00:00:00 2001
From: Toastie <toastie@toastiet0ast.com>
Date: Wed, 26 Mar 2025 12:17:53 +1300
Subject: [PATCH] added owner-only .massping for emergencies

---
 src/EllieBot/Modules/Owner/OwnerCommands.cs   | 38 +++++++++++++++++++
 src/EllieBot/strings/aliases.yml              |  4 +-
 .../strings/commands/commands.en-US.yml       |  8 ++++
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/EllieBot/Modules/Owner/OwnerCommands.cs b/src/EllieBot/Modules/Owner/OwnerCommands.cs
index a2f676d..09d68f8 100644
--- a/src/EllieBot/Modules/Owner/OwnerCommands.cs
+++ b/src/EllieBot/Modules/Owner/OwnerCommands.cs
@@ -11,4 +11,42 @@ public class Owner(VoteRewardService vrs) : EllieModule
         vrs.SetVoiceChannel(ctx.Channel);
         await ctx.OkAsync();
     }
+
+    private static CancellationTokenSource _cts = null;
+
+    [Cmd]
+    public async Task MassPing()
+    {
+        if (_cts is { } t)
+        {
+            await t.CancelAsync();
+        }
+
+        try
+        {
+            var users = await ctx.Guild.GetUsersAsync().Fmap(u => u.Where(x => !x.IsBot).ToArray());
+
+            var currentIndex = 0;
+            while (!_cts.IsCancellationRequested)
+            {
+                try
+                {
+                    var batch = users[currentIndex..(currentIndex += 50)];
+
+                    var mentions = batch.Select(x => x.Mention).Join(" ");
+                    await ctx.Channel.SendMessageAsync(mentions, allowedMentions: AllowedMentions.All);
+                }
+                catch
+                {
+                    // ignored
+                }
+
+                await Task.Delay(2500);
+            }
+        }
+        finally
+        {
+            _cts = null;
+        }
+    }
 }
\ No newline at end of file
diff --git a/src/EllieBot/strings/aliases.yml b/src/EllieBot/strings/aliases.yml
index 8da0b87..e09edb7 100644
--- a/src/EllieBot/strings/aliases.yml
+++ b/src/EllieBot/strings/aliases.yml
@@ -1656,4 +1656,6 @@ linkfixlist:
 votefeed:
   - votefeed
 vote:
-  - vote
\ No newline at end of file
+  - vote
+massping:
+  - massping
\ No newline at end of file
diff --git a/src/EllieBot/strings/commands/commands.en-US.yml b/src/EllieBot/strings/commands/commands.en-US.yml
index cb1677b..4fd19f1 100644
--- a/src/EllieBot/strings/commands/commands.en-US.yml
+++ b/src/EllieBot/strings/commands/commands.en-US.yml
@@ -5198,5 +5198,13 @@ vote:
     Will redirect user to timely if voting is not enabled.
   ex:
     - ''
+  params:
+    - { }
+massping:
+  desc: |-
+    Mass pings all users in the server.
+    Run again to cancel.
+  ex:
+    - ''
   params:
     - { }
\ No newline at end of file