Skip to content
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
11 changes: 8 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ def is_bot_mentioned(message_text: str) -> bool:
bool: True if the bot is mentioned, False otherwise.
"""
bot_trigger_words = ["ботяра", "bot_health"]
# Remove all non-letter characters
cleaned_text = ''.join(char for char in message_text.lower() if char.isalpha() or char.isspace())
return any(word in cleaned_text for word in bot_trigger_words)
# Remove leading/trailing whitespace and convert to lowercase
cleaned_text = message_text.strip().lower()
for word in bot_trigger_words:
if cleaned_text.startswith(word):
# Check if it's followed by space, punctuation, or is the whole message
if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalpha():
return True
return False
Comment on lines +109 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Consider stricter word boundary checking to avoid false positives.

The current boundary check uses isalpha(), which means messages like "ботяра123" or "bot_health_check" would trigger the bot since digits and underscores are not alphabetic. This could lead to unintended activations.

If you want strict word boundaries, consider checking for whitespace or end-of-string instead:

     bot_trigger_words = ["ботяра", "bot_health"]
     # Remove leading/trailing whitespace and convert to lowercase
     cleaned_text = message_text.strip().lower()
     for word in bot_trigger_words:
         if cleaned_text.startswith(word):
-            # Check if it's followed by space, punctuation, or is the whole message
-            if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalpha():
+            # Check if it's the whole message or followed by whitespace
+            if len(cleaned_text) == len(word) or cleaned_text[len(word)].isspace():
                 return True
     return False

Alternatively, if you want to allow punctuation but not alphanumeric characters:

     bot_trigger_words = ["ботяра", "bot_health"]
     # Remove leading/trailing whitespace and convert to lowercase
     cleaned_text = message_text.strip().lower()
     for word in bot_trigger_words:
         if cleaned_text.startswith(word):
-            # Check if it's followed by space, punctuation, or is the whole message
-            if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalpha():
+            # Check if it's the whole message or followed by non-alphanumeric character
+            if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalnum():
                 return True
     return False
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Remove leading/trailing whitespace and convert to lowercase
cleaned_text = message_text.strip().lower()
for word in bot_trigger_words:
if cleaned_text.startswith(word):
# Check if it's followed by space, punctuation, or is the whole message
if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalpha():
return True
return False
# Remove leading/trailing whitespace and convert to lowercase
cleaned_text = message_text.strip().lower()
for word in bot_trigger_words:
if cleaned_text.startswith(word):
# Check if it's the whole message or followed by whitespace
if len(cleaned_text) == len(word) or cleaned_text[len(word)].isspace():
return True
return False
Suggested change
# Remove leading/trailing whitespace and convert to lowercase
cleaned_text = message_text.strip().lower()
for word in bot_trigger_words:
if cleaned_text.startswith(word):
# Check if it's followed by space, punctuation, or is the whole message
if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalpha():
return True
return False
# Remove leading/trailing whitespace and convert to lowercase
cleaned_text = message_text.strip().lower()
for word in bot_trigger_words:
if cleaned_text.startswith(word):
# Check if it's the whole message or followed by non-alphanumeric character
if len(cleaned_text) == len(word) or not cleaned_text[len(word)].isalnum():
return True
return False
🤖 Prompt for AI Agents
In src/main.py around lines 109 to 116, the trigger-word boundary check using
cleaned_text[len(word)].isalpha() allows digits/underscores to pass and causes
false positives (e.g., "bot123" or "bot_health"); replace that check with a
stricter condition: treat the trigger as valid only if it's at end-of-string or
the following character is whitespace or a punctuation character (use
string.punctuation), e.g., check for len(cleaned_text)==len(word) or
cleaned_text[len(word)].isspace() or cleaned_text[len(word)] in
string.punctuation; ensure to import string at the top of the file.



def clean_url(message_text: str) -> str:
Expand Down