Skip to content

Commit

Permalink
Include additional detailed embeds for 'show once' notes
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jun 5, 2024
1 parent c2555f7 commit b0711e8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,18 @@ public static async Task MessageHandlerAsync(DiscordClient client, DiscordMessag

// If there are notes, build embed and add to message
if (notesToNotify.Count != 0)
{
memberWarnInfo.AddEmbed(await UserNoteHelpers.GenerateUserNotesEmbedAsync(modmailMember, notesToUse: notesToNotify));

// For any notes set to show once, show the full note content in its own embed because it will not be able to be fetched manually
foreach (var note in notesToNotify)
if (memberWarnInfo.Embeds.Count < 10) // Limit to 10 embeds; this probably won't be an issue because we probably won't have that many 'show once' notes
if (note.Value.ShowOnce)
memberWarnInfo.AddEmbed(await UserNoteHelpers.GenerateUserNoteSimpleEmbedAsync(note.Value, modmailMember));
}

// If message was built (if user is muted OR if user has notes to show on modmail), send it
if (memberWarnInfo.Embeds.Count != 0) // todo: this is probably not the best way to check this?
if (memberWarnInfo.Embeds.Count != 0)
await message.Channel.SendMessageAsync(memberWarnInfo);

// If any notes were shown & set to show only once, delete them now
Expand Down
25 changes: 25 additions & 0 deletions Helpers/UserNoteHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ await LykosAvatarMethods.UserOrMemberAvatarURL(user, Program.homeGuild, "png")

return embed;
}

public static async Task<DiscordEmbed> GenerateUserNoteSimpleEmbedAsync(UserNote note, DiscordUser user)
{
DiscordEmbedBuilder embed = new DiscordEmbedBuilder()
.WithDescription($"**Note**\n{note.NoteText}")
.WithColor(new DiscordColor(0xFEC13D))
.WithTimestamp(DateTime.Now)
.WithFooter(
$"User ID: {user.Id}",
null
)
.WithAuthor(
$"Note for {DiscordHelpers.UniqueUsername(user)}",
null,
await LykosAvatarMethods.UserOrMemberAvatarURL(user, Program.homeGuild, "png")
)
.AddField("Note ID", StringHelpers.Pad(note.NoteId), true)
.AddField("Responsible moderator", $"<@{note.ModUserId}>", true)
.AddField("Time", $"<t:{TimeHelpers.ToUnixTimestamp(note.Timestamp)}:f>", true);

if (note.ShowOnce)
embed.AddField("Showing Once Only", "This note was set to show only once. It has now been deleted!");

return embed;
}

public static async Task<DiscordEmbed> GenerateUserNoteDetailEmbedAsync(UserNote note, DiscordUser user)
{
Expand Down
7 changes: 7 additions & 0 deletions Helpers/WarningHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ public static async Task<UserWarning> GiveWarningAsync(DiscordUser targetUser, D
{
var alertChannel = await Program.discord.GetChannelAsync(Program.cfgjson.InvestigationsChannelId);
var msg = new DiscordMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Muted} {modUser.Mention}, {targetUser.Mention} has notes set to show when they are issued a warning!").AddEmbed(await UserNoteHelpers.GenerateUserNotesEmbedAsync(targetUser, true, notesToNotifyFor)).WithAllowedMentions(Mentions.All);

// For any notes set to show once, show the full note content in its own embed because it will not be able to be fetched manually
foreach (var note in notesToNotifyFor)
if (msg.Embeds.Count < 10) // Limit to 10 embeds; this probably won't be an issue because we probably won't have that many 'show once' notes
if (note.Value.ShowOnce)
msg.AddEmbed(await UserNoteHelpers.GenerateUserNoteSimpleEmbedAsync(note.Value, targetUser));

await alertChannel.SendMessageAsync(msg);
}

Expand Down

0 comments on commit b0711e8

Please sign in to comment.