Skip to content

Commit

Permalink
Ignore silently words in commands that stop when filter triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimShadyIAm committed May 19, 2024
1 parent 9d8ed39 commit 2915da1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cogs/commands/misc/canister.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from utils import GIRContext, canister_search_package, cfg, transform_context
from utils.fetchers import canister_fetch_repos
from utils.framework import gatekeeper, whisper_in_general, find_triggered_filters, find_triggered_raid_phrases
from utils.framework.filter import ignorable_words
from utils.views import TweakDropdown, default_repos, repo_autocomplete


Expand All @@ -22,7 +23,6 @@ async def on_message(self, message):
author = message.guild.get_member(message.author.id)
if author is None:
return

if not gatekeeper.has(message.guild, author, 5) and message.channel.id == cfg.channels.general:
return

Expand All @@ -31,8 +31,10 @@ async def on_message(self, message):
if not pattern.match(message.content):
return

if await find_triggered_filters(message.content, message.author) or await find_triggered_raid_phrases(message.content, message.author):
return
if filter_words := await find_triggered_filters(message.content, message.author) or await find_triggered_raid_phrases(message.content, message.author):
# if any of the triggered filtered words are not silently filtered, don't show results
if not ignorable_words(filter_words):
return

matches = pattern.findall(message.content)
if not matches:
Expand Down
6 changes: 4 additions & 2 deletions cogs/commands/misc/memes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
find_triggered_filters,
find_triggered_raid_phrases, gatekeeper,
memed_and_up, mempro_and_up, mod_and_up, whisper)
from utils.framework.filter import ignorable_words
from utils.views import GenericDescriptionModal, Menu, memes_autocomplete


Expand Down Expand Up @@ -463,8 +464,9 @@ async def aitext(self, ctx: GIRContext, prompt: str):
data = await resp.json()
text = data.get("choices")[0].get("text")
text = discord.utils.escape_markdown(text)
if await find_triggered_filters(text, ctx.author) or await find_triggered_raid_phrases(text, ctx.author):
text = "A filter was triggered by this response. Please try a different prompt."
if filter_words := await find_triggered_filters(text, ctx.author) or await find_triggered_raid_phrases(text, ctx.author):
if not ignorable_words(filter_words):
text = "A filter was triggered by this response. Please try a different prompt."

embed = discord.Embed(color=discord.Color.random())
prompt_formatted = discord.utils.escape_markdown(prompt)
Expand Down
3 changes: 2 additions & 1 deletion cogs/monitors/misc/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from utils import cfg
from utils.framework import find_triggered_filters, gatekeeper
from utils.framework.filter import ignorable_words
from utils.logging import logger
from datetime import timezone

Expand Down Expand Up @@ -111,7 +112,7 @@ async def generate_view(self, message: discord.Message, link: str):
triggered_words = await find_triggered_filters(
title, message.author)

if triggered_words:
if triggered_words and not ignorable_words(triggered_words):
title = "<:fr:959135064657109012>"

view = discord.ui.View()
Expand Down
3 changes: 3 additions & 0 deletions cogs/monitors/mod/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ async def nick_filter(self, member):
if not triggered_words:
return

if ignorable_words(triggered_words):
return

await member.edit(nick="change name pls")
embed = discord.Embed(title="Nickname changed",
color=discord.Color.orange())
Expand Down
7 changes: 7 additions & 0 deletions utils/framework/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ async def find_triggered_filters(input, member: discord.Member) -> List[FilterWo
words_found.append(word)
return words_found

def ignorable_words(triggered_filter_words: List[FilterWord]):
"""
We don't want to trigger the filter if the words are silently filtered
return True if all triggered filtered words are silently filtered
"""
return all(filter_word.silent_filter for filter_word in triggered_filter_words)


async def find_triggered_raid_phrases(input, member):
symbols = (u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",
Expand Down

0 comments on commit 2915da1

Please sign in to comment.