From 177f55fb0628bedc39fc817fc40c3d0346b28c6e Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:01:08 -0300 Subject: [PATCH] fix(bot): :bug: Fix censorship. --- payphone/bot.py | 8 +++++++- payphone/core/censorship.py | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/payphone/bot.py b/payphone/bot.py index c407c53..1c4f7c4 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -243,6 +243,9 @@ class Payphone(commands.AutoShardedBot): if message is not None and message.guild is None: return ["p.", "P."] + if message is not None and message.content is None: + return "p." + server_id = server_id if server_id is not None else message.guild.id key = constants.PREFIX_TEMPLATE % server_id @@ -259,7 +262,7 @@ class Payphone(commands.AutoShardedBot): prefix = server.prefix - if message.content.lower().startswith(prefix.lower()): + if message is not None and message.content.lower().startswith(prefix.lower()): return message.content[: len(prefix)] return prefix @@ -375,6 +378,9 @@ async def is_channel_enabled(ctx: commands.Context) -> Literal[True]: if ctx.guild is None: return True + + if ctx.command.qualified_name in ["config enable", "config disable"]: + return True server_id = ctx.guild.id channel_id = ctx.channel.id diff --git a/payphone/core/censorship.py b/payphone/core/censorship.py index 2dc28c4..ecb6f88 100644 --- a/payphone/core/censorship.py +++ b/payphone/core/censorship.py @@ -243,19 +243,19 @@ def moderate(message: str) -> str: str | None: The blocked pattern found as it was found. """ - match = PATTERN.match(message) + match = next(PATTERN.finditer(message), None) if match is not None: - return match.string + return message[match.start():match.end()] - match = URL_PATTERN.match(message) + match = next(URL_PATTERN.finditer(message), None) if match is not None: - return match.string + return message[match.start():match.end()] - match = INVITES_PATTERN.match(message) + match = next(INVITES_PATTERN.finditer(message), None) if match is not None: - return message[match.start] + return message[match.start():match.end()] return None