From bc4ab57a6713c85fd1d90cef9faa990673212b85 Mon Sep 17 00:00:00 2001
From: Toastie <toastie@toastiet0ast.com>
Date: Mon, 3 Feb 2025 00:19:29 +1300
Subject: [PATCH] .delete will now accept a message link

---
 .../Modules/Administration/Administration.cs  | 19 +++++++++++++++----
 .../data/strings/commands/commands.en-US.yml  | 10 +++++++++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/EllieBot/Modules/Administration/Administration.cs b/src/EllieBot/Modules/Administration/Administration.cs
index b9332be..fac8320 100644
--- a/src/EllieBot/Modules/Administration/Administration.cs
+++ b/src/EllieBot/Modules/Administration/Administration.cs
@@ -97,9 +97,9 @@ public partial class Administration : EllieModule<AdministrationService>
         var (enabled, channels) = _service.GetDelMsgOnCmdData(ctx.Guild.Id);
 
         var embed = CreateEmbed()
-                       .WithOkColor()
-                       .WithTitle(GetText(strs.server_delmsgoncmd))
-                       .WithDescription(enabled ? "✅" : "❌");
+                    .WithOkColor()
+                    .WithTitle(GetText(strs.server_delmsgoncmd))
+                    .WithDescription(enabled ? "✅" : "❌");
 
         var str = string.Join("\n",
             channels.Select(x =>
@@ -301,6 +301,16 @@ public partial class Administration : EllieModule<AdministrationService>
     public Task Delete(ulong messageId, ParsedTimespan timespan = null)
         => Delete((ITextChannel)ctx.Channel, messageId, timespan);
 
+    [Cmd]
+    [RequireContext(ContextType.Guild)]
+    public async Task Delete(MessageLink messageLink, ParsedTimespan timespan = null)
+    {
+        if (messageLink.Channel is not ITextChannel tc)
+            return;
+
+        await Delete(tc, messageLink.Message.Id, timespan);
+    }
+
     [Cmd]
     [RequireContext(ContextType.Guild)]
     public async Task Delete(ITextChannel channel, ulong messageId, ParsedTimespan timespan = null)
@@ -373,7 +383,8 @@ public partial class Administration : EllieModule<AdministrationService>
         if (ctx.Channel is not SocketTextChannel stc)
             return;
 
-        var t = stc.Threads.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase));
+        var t = stc.Threads.FirstOrDefault(
+            x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase));
 
         if (t is null)
         {
diff --git a/src/EllieBot/data/strings/commands/commands.en-US.yml b/src/EllieBot/data/strings/commands/commands.en-US.yml
index 720ea39..75623e5 100644
--- a/src/EllieBot/data/strings/commands/commands.en-US.yml
+++ b/src/EllieBot/data/strings/commands/commands.en-US.yml
@@ -4134,7 +4134,11 @@ edit:
       text:
         desc: "The new text content of the edited message."
 delete:
-  desc: Deletes a single message given the channel and message ID. If channel is ommited, message will be searched for in the current channel. You can also specify time parameter after which the message will be deleted (up to 7 days). This timer won't persist through bot restarts.
+  desc: |-
+    Deletes a single message given the channel and message ID, or a message link.
+    If channel is omitted, message will be searched for in the current channel.
+    You can also specify time parameter after which the message will be deleted (up to 7 days).
+    This timer won't persist through bot restarts.
   ex:
     - '#chat 771562360594628608'
     - 771562360594628608
@@ -4144,6 +4148,10 @@ delete:
         desc: "The id of a specific message within a channel, used to target the deletion operation."
       time:
         desc: "The duration after which the message should be automatically deleted."
+    - messageLink:
+        desc: "The link of the message to delete. It must be on the same server."
+      time:
+        desc: "The duration after which the message should be automatically deleted."
     - channel:
         desc: "The channel where the message is located or should be searched for."
       messageId: