From 556142c5ce96d098d30b13f5836b0a11d5e81b87 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 2 Feb 2025 07:56:21 +0000 Subject: [PATCH] .delete will now accept a message link --- .../Modules/Administration/Administration.cs | 38 ++++++++++++------- .../data/strings/commands/commands.en-US.yml | 10 ++++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 37c5a3df0..29701dc83 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -54,7 +54,7 @@ public partial class Administration : NadekoModule else await Response().Pending(strs.imageonly_disable).SendAsync(); } - + [Cmd] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.Administrator)] @@ -97,9 +97,9 @@ public partial class Administration : NadekoModule 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 => @@ -221,7 +221,7 @@ public partial class Administration : NadekoModule [BotPerm(GuildPerm.ManageChannels)] public async Task CreaTxtChanl([Leftover] string channelName) { - var txtCh = await ctx.Guild.CreateTextChannelAsync(channelName); + var txtCh = await ctx.Guild.CreateTextChannelAsync(channelName); await Response().Confirm(strs.createtextchan(Format.Bold(txtCh.Name))).SendAsync(); } @@ -301,6 +301,16 @@ public partial class Administration : NadekoModule 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) @@ -360,11 +370,11 @@ public partial class Administration : NadekoModule { if (ctx.Channel is not SocketTextChannel stc) return; - + await stc.CreateThreadAsync(name, message: ctx.Message.ReferencedMessage); await ctx.OkAsync(); } - + [Cmd] [BotPerm(ChannelPermission.ManageThreads)] [UserPerm(ChannelPermission.ManageThreads)] @@ -373,14 +383,15 @@ public partial class Administration : NadekoModule 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) { await Response().Error(strs.not_found).SendAsync(); return; } - + await t.DeleteAsync(); await ctx.OkAsync(); } @@ -406,7 +417,7 @@ public partial class Administration : NadekoModule await Response().Confirm(strs.autopublish_disable).SendAsync(); } } - + [Cmd] [UserPerm(GuildPerm.ManageNicknames)] [BotPerm(GuildPerm.ChangeNickname)] @@ -450,8 +461,9 @@ public partial class Administration : NadekoModule public async Task SetServerBanner([Leftover] string img = null) { // Tier2 or higher is required to set a banner. - if (ctx.Guild.PremiumTier is PremiumTier.Tier1 or PremiumTier.None) return; - + if (ctx.Guild.PremiumTier is PremiumTier.Tier1 or PremiumTier.None) + return; + var result = await _service.SetServerBannerAsync(ctx.Guild, img); switch (result) @@ -472,7 +484,7 @@ public partial class Administration : NadekoModule throw new ArgumentOutOfRangeException(); } } - + [Cmd] [RequireContext(ContextType.Guild)] [UserPerm(GuildPermission.ManageGuild)] diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 9ab9a26d6..be755d1b2 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/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: