From fe9187eeb442132cf7bf216f31ec4ca1751ecf8f Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 4 Nov 2023 14:30:22 +0000 Subject: [PATCH 1/2] chore: bump to 2.1.1 --- Marco/Marco.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marco/Marco.csproj b/Marco/Marco.csproj index 372cc43..d185758 100644 --- a/Marco/Marco.csproj +++ b/Marco/Marco.csproj @@ -6,7 +6,7 @@ enable enable Linux - 2.1.0 + 2.1.1 From e5aed17cf6eb5bf117c89206bd025272f5628599 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 4 Nov 2023 14:30:37 +0000 Subject: [PATCH 2/2] feat: add support for silent macros --- Marco/Commands/MacroCommand.cs | 18 +++++++++++++++--- Marco/Services/MacroListeningService.cs | 13 ++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Marco/Commands/MacroCommand.cs b/Marco/Commands/MacroCommand.cs index 01d2551..02db2fa 100644 --- a/Marco/Commands/MacroCommand.cs +++ b/Marco/Commands/MacroCommand.cs @@ -1,4 +1,5 @@ -using DSharpPlus.SlashCommands; +using DSharpPlus.Entities; +using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; using Marco.AutocompleteProviders; using Marco.Data; @@ -22,7 +23,8 @@ public MacroCommand(MacroService macroService) [SlashCommand("macro", "Executes a macro.")] [SlashRequireGuild] public async Task MacroAsync(InteractionContext context, - [Option("macro", "The name of the macro.", true)] [Autocomplete(typeof(MacroAutocompleteProvider))] string macroName) + [Option("macro", "The name of the macro.", true)] [Autocomplete(typeof(MacroAutocompleteProvider))] + string macroName) { if (!_macroService.TryGetMacro(context.Guild, macroName, out Macro? macro)) { @@ -36,6 +38,16 @@ public async Task MacroAsync(InteractionContext context, return; } - await context.CreateResponseAsync(macro.Response).ConfigureAwait(false); + var builder = new DiscordInteractionResponseBuilder(); + string response = macro.Response; + + if (response.StartsWith("@silent ")) + { + response = response[8..]; + builder.SuppressNotifications(); + } + + builder.WithContent(response); + await context.CreateResponseAsync(builder).ConfigureAwait(false); } } diff --git a/Marco/Services/MacroListeningService.cs b/Marco/Services/MacroListeningService.cs index 974dbee..f37f6bb 100644 --- a/Marco/Services/MacroListeningService.cs +++ b/Marco/Services/MacroListeningService.cs @@ -124,7 +124,18 @@ private async Task OnMessageCreated(DiscordClient sender, MessageCreateEventArgs guild, user = (DiscordMember) e.Message.Author });*/ - await channel.SendMessageAsync(macro.Response).ConfigureAwait(false); + + var builder = new DiscordMessageBuilder(); + string response = macro.Response; + + if (response.StartsWith("@silent ")) + { + response = response[8..]; + builder.SuppressNotifications(); + } + + builder.WithContent(response); + await channel.SendMessageAsync(builder).ConfigureAwait(false); } } else