Skip to content

Commit

Permalink
feat: add support for silent macros
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Nov 4, 2023
1 parent fe9187e commit e5aed17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
18 changes: 15 additions & 3 deletions Marco/Commands/MacroCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DSharpPlus.SlashCommands;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
using Marco.AutocompleteProviders;
using Marco.Data;
Expand All @@ -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))
{
Expand All @@ -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);
}
}
13 changes: 12 additions & 1 deletion Marco/Services/MacroListeningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5aed17

Please sign in to comment.