Skip to content

Commit

Permalink
feat: @silent support
Browse files Browse the repository at this point in the history
Discord [relatively] recently added support for supressing notifications by typing @silent before the message content. This applies 1 << 12 to the message flags, and does not emit a notification, but still shows the highlight/mention in the channel you've been mentioned in.

Up until now, this bot did not support this functionality, neither in the sense of utilizing the feature or respecting messages attributed with 1 << 12.

This commit is the main purpose of the subsequent PR this will be in, allowing for users to quietly mention users in a channel, effectively bringing the bot in parity with the original message in that sense as well.
  • Loading branch information
VelvetToroyashi authored and Instellate committed Sep 25, 2023
1 parent d5f80b2 commit 3c0f32b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Events/MessageCreatedEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed partial class MessageCreatedEventHandler

public static async Task ExecuteAsync(DiscordClient _, MessageCreateEventArgs eventArgs)
{
bool shouldSilence = eventArgs.Message.Flags is { } flags && flags.HasFlag(MessageFlags.SupressNotifications);
DiscordMessage message = eventArgs.Message;
// Explicitly cast to nullable to prevent erroneous compiler warning about it
// not being nullable.
Expand All @@ -32,6 +33,7 @@ public static async Task ExecuteAsync(DiscordClient _, MessageCreateEventArgs ev
{
mentionedUsers = mentionedUsers.Prepend(eventArgs.Message.ReferencedMessage.Author);
}


// Only mention the users that the message intended to mention.
foreach (DiscordUser user in mentionedUsers)
Expand Down Expand Up @@ -69,7 +71,15 @@ public static async Task ExecuteAsync(DiscordClient _, MessageCreateEventArgs ev

try
{
await member.SendMessageAsync($"You were pinged in {eventArgs.Channel.Mention} by {message.Author.Mention}: {message.JumpLink}");
var builder = new DiscordMessageBuilder()
.WithContent($"You were pinged by {message.Author.Mention} in {eventArgs.Channel.Mention}. [Jump! \u2197]({message.JumpLink})");

if (shouldSilence)
{
builder.SuppressNotifications();
}

await member.SendMessageAsync(builder);
}
catch (DiscordException error)
{
Expand Down

0 comments on commit 3c0f32b

Please sign in to comment.