Skip to content

Commit

Permalink
Keyword tracking: Add missing case check, handle GetMemberAsync 404
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Oct 6, 2024
1 parent 3e62a0d commit 2d214bd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Helpers/KeywordTrackingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async Task KeywordCheck(DiscordMessage message, bool isEdit = fals

// It does*. For any matched keywords, is the target user in the guild?
// *this is a broad check, we check again more specifically later (respecting other keyword properties)
foreach (var matchedKeyword in keywordsList.Where(x => message.Content.Contains(x.Keyword)))
foreach (var matchedKeyword in keywordsList.Where(x => message.Content.Contains(x.Keyword, StringComparison.OrdinalIgnoreCase)))
{
try
{
Expand Down Expand Up @@ -120,8 +120,18 @@ public static async Task KeywordCheck(DiscordMessage message, bool isEdit = fals

// Don't DM the user if their keyword was mentioned in a channel they do not have permissions to view.
// If we don't do this we may leak private channels, which - even if the user might want to - I don't want to be doing.
var member = await message.Channel.Guild.GetMemberAsync(fieldValue.UserId); // need to fetch member to check permissions
if (!message.Channel.PermissionsFor(member).HasPermission(Permissions.AccessChannels))
DiscordMember member = default;
try
{
member = await message.Channel.Guild.GetMemberAsync(fieldValue.UserId); // need to fetch member to check permissions
}
catch (NotFoundException)
{
// Member is not in server. We cannot check permissions, and it would be silly to continue anyway. Stop here.
return;
}

if (!message.Channel.PermissionsFor(member).HasPermission(Permissions.AccessChannels) || !message.Channel.PermissionsFor(member).HasPermission(Permissions.ReadMessageHistory))
break;

if (fieldValue.MatchWholeWord)
Expand Down

0 comments on commit 2d214bd

Please sign in to comment.