Limit rule update to small channels
This commit is contained in:
parent
8ad625fb4e
commit
a527346ae6
@ -49,6 +49,10 @@ from .aimod_config import (
|
||||
)
|
||||
|
||||
|
||||
# Avoid loading an excessive number of messages when updating rules
|
||||
MAX_RULE_MESSAGES = 25
|
||||
|
||||
|
||||
class AIModerationCog(commands.Cog):
|
||||
"""
|
||||
A Discord Cog that uses Google Vertex AI to moderate messages based on server rules.
|
||||
@ -753,9 +757,18 @@ class AIModerationCog(commands.Cog):
|
||||
) -> None:
|
||||
"""Pull the server rules from a channel and update the global config."""
|
||||
messages = []
|
||||
async for msg in channel.history(limit=None, oldest_first=True):
|
||||
async for msg in channel.history(
|
||||
limit=MAX_RULE_MESSAGES + 1, oldest_first=True
|
||||
):
|
||||
if msg.content:
|
||||
messages.append(msg.content)
|
||||
if len(messages) > MAX_RULE_MESSAGES:
|
||||
await interaction.response.send_message(
|
||||
f"Channel has more than {MAX_RULE_MESSAGES} messages."
|
||||
" Please consolidate your rules into fewer messages.",
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
|
||||
if not messages:
|
||||
await interaction.response.send_message(
|
||||
|
Loading…
x
Reference in New Issue
Block a user