forked from EllieBotDevs/elliebot
wordfilter, invitefilter and linkfilter will now properly detect forwarded messages, as forwards were used to circumvent filtering.
Fixed .streamremove - now showing proper youtube name when removing instead of channel id
This commit is contained in:
parent
4ec6396c87
commit
91d464b041
2 changed files with 21 additions and 15 deletions
src/EllieBot/Modules
|
@ -52,12 +52,12 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var confs = await uow.GetTable<GuildFilterConfig>()
|
||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
||||
.LoadWith(x => x.FilterInvitesChannelIds)
|
||||
.LoadWith(x => x.FilterWordsChannelIds)
|
||||
.LoadWith(x => x.FilterLinksChannelIds)
|
||||
.LoadWith(x => x.FilteredWords)
|
||||
.ToListAsyncLinqToDB();
|
||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
||||
.LoadWith(x => x.FilterInvitesChannelIds)
|
||||
.LoadWith(x => x.FilterWordsChannelIds)
|
||||
.LoadWith(x => x.FilterLinksChannelIds)
|
||||
.LoadWith(x => x.FilteredWords)
|
||||
.ToListAsyncLinqToDB();
|
||||
|
||||
foreach (var conf in confs)
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
await using var uow = _db.GetDbContext();
|
||||
var fc = uow.FilterConfigForId(guildId,
|
||||
set => set.Include(x => x.FilteredWords)
|
||||
.Include(x => x.FilterWordsChannelIds));
|
||||
.Include(x => x.FilterWordsChannelIds));
|
||||
|
||||
WordFilteringServers.TryRemove(guildId);
|
||||
ServerFilteredWords.TryRemove(guildId, out _);
|
||||
|
@ -140,7 +140,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
var filteredChannelWords =
|
||||
FilteredWordsForChannel(usrMsg.Channel.Id, guild.Id) ?? new ConcurrentHashSet<string>();
|
||||
var filteredServerWords = FilteredWordsForServer(guild.Id) ?? new ConcurrentHashSet<string>();
|
||||
var wordsInMessage = usrMsg.Content.ToLowerInvariant().Split(' ');
|
||||
var wordsInMessage = (usrMsg.Content + " " + usrMsg.ForwardedMessages.FirstOrDefault().Message?.Content)
|
||||
.ToLowerInvariant().Split(' ');
|
||||
if (filteredChannelWords.Count != 0 || filteredServerWords.Count != 0)
|
||||
{
|
||||
foreach (var word in wordsInMessage)
|
||||
|
@ -183,7 +184,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
return false;
|
||||
|
||||
if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id))
|
||||
&& usrMsg.Content.IsDiscordInvite())
|
||||
&& (usrMsg.Content.IsDiscordInvite() ||
|
||||
usrMsg.ForwardedMessages.Any(x => x.Message?.Content.IsDiscordInvite() ?? false)))
|
||||
{
|
||||
Log.Information("User {UserName} [{UserId}] sent a filtered invite to {ChannelId} channel",
|
||||
usrMsg.Author.ToString(),
|
||||
|
@ -219,7 +221,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
return false;
|
||||
|
||||
if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id))
|
||||
&& usrMsg.Content.TryGetUrlPath(out _))
|
||||
&& (usrMsg.Content.TryGetUrlPath(out _) ||
|
||||
usrMsg.ForwardedMessages.Any(x => x.Message?.Content.TryGetUrlPath(out _) ?? false)))
|
||||
{
|
||||
Log.Information("User {UserName} [{UserId}] sent a filtered link to {ChannelId} channel",
|
||||
usrMsg.Author.ToString(),
|
||||
|
@ -246,10 +249,10 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
|
|||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var conf = await uow.GetTable<GuildFilterConfig>()
|
||||
.Where(fi => fi.GuildId == guildId)
|
||||
.LoadWith(x => x.FilterInvitesChannelIds)
|
||||
.LoadWith(x => x.FilterLinksChannelIds)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.Where(fi => fi.GuildId == guildId)
|
||||
.LoadWith(x => x.FilterInvitesChannelIds)
|
||||
.LoadWith(x => x.FilterLinksChannelIds)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
return new()
|
||||
{
|
||||
|
|
|
@ -48,7 +48,10 @@ public partial class Searches
|
|||
return;
|
||||
}
|
||||
|
||||
await Response().Confirm(strs.stream_removed(Format.Bold(fs.Username), fs.Type)).SendAsync();
|
||||
await Response()
|
||||
.Confirm(strs.stream_removed(
|
||||
Format.Bold(string.IsNullOrWhiteSpace(fs.PrettyName) ? fs.Username : fs.PrettyName),
|
||||
fs.Type)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
|
Loading…
Add table
Reference in a new issue