Skip to content

Commit

Permalink
Refactor code to handle message events more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Jul 23, 2024
1 parent 16eb7ce commit 468605f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions events/on_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ async def _global_chat_handler(self, message: discord.Message) -> None:
if self.is_banned(message.author):
return

if TYPE_CHECKING:
assert message.guild is not None

if message.guild.id not in self.__global_chat_cache:
# LRU?
data = await self.bot.guild_configurations.find_one(
Expand Down Expand Up @@ -584,6 +587,10 @@ async def _scam_detection(self, message: discord.Message, *, to_send: bool = Tru
if message.author.id == self.bot.user.id:
return False

flags = message.author.public_flags
if any((flags.staff, flags.system, flags.verified_bot)):
return False

if not message.channel.permissions_for(message.guild.me).send_messages:
return

Expand Down Expand Up @@ -621,6 +628,9 @@ async def _scam_detection(self, message: discord.Message, *, to_send: bool = Tru
aiohttp.ServerDisconnectedError,
aiohttp.ClientResponseError,
):
if self.bot.http_session.closed: # RuntimeError: Session is closed
return

response = await self.bot.http_session.post(
API,
json={"message": message.content},
Expand Down

0 comments on commit 468605f

Please sign in to comment.