Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spam-detection): Limit user's messages checked #85

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
TENOR_API_KEY = os.environ["TENOR_API_KEY"]
GEMINI_API_KEY = os.environ["GEMINI_API_KEY"]
SPAM_CHECK_MIN_MSG = 3
MESSAGE_HISTORY_LIMIT = 1000

# Load the permissions the bot has been granted in the previous configuration
intents = Intents.default()
Expand Down Expand Up @@ -190,9 +191,12 @@ async def on_message(message: Message):

# Count user's messages in channel
count = 0
async for msg in message.channel.history(limit=None):
async for msg in message.channel.history(limit=MESSAGE_HISTORY_LIMIT):
if msg.author.id == message.author.id:
count += 1
# Exit early if count exceeds SPAM_CHECK_MIN_MSG
if count >= SPAM_CHECK_MIN_MSG:
break

# If the user has sent less than SPAM_CHECK_MIN_MSG messages in the channel, check for spam
if count < SPAM_CHECK_MIN_MSG:
Expand Down