Skip to content

Commit

Permalink
Added Regular Expression Checking #37 (#40)
Browse files Browse the repository at this point in the history
Changes to how messages are checked. Uses regex instead of literal string matching to add more expressive config

Co-authored-by: David <[email protected]>
  • Loading branch information
Sam2004-2 and coillteoir authored Nov 17, 2023
1 parent 8ecddea commit c0da5f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
4. Write a concise title
5. Write a good description
6. Sit back and wait for review
7. Accept constructive feedback and comments
7. Build upon constructive feedback and comments
8. Get it merged :)

## General PR Guidelines
Expand Down
32 changes: 17 additions & 15 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,29 @@ async def on_message(message):
await message.add_reaction(BAD_MORNING_EMOJI)
return

if any(element in contents for element in GOOD_MORNING_PHRASES):
print(f'gm detected > "{message.content}" by {message.author}')
if FIRST_GM is False:
FIRST_GM_USER = message.author
FIRST_GM = True
# Use regular expressions to check for good morning phrases small changes
for pattern in GOOD_MORNING_PHRASES:
if re.search(rf'\b{re.escape(pattern)}\b', contents):
print(f'gm detected > "{message.content}" by {message.author}')
if FIRST_GM is False:
FIRST_GM_USER = message.author
FIRST_GM = True

await message.add_reaction(EARLY_EMOJI)
server_leaders.add_point(message.author)
return

await message.add_reaction(EARLY_EMOJI)
server_leaders.add_point(message.author)
return
await message.add_reaction(MORNING_EMOJI)

server_leaders.add_point(message.author)
await message.add_reaction(MORNING_EMOJI)
return

#Performing regular expression checking on easter egg phrases
for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items():
if re.search(rf'\b{re.escape(egg_phrase)}\b', contents):
await message.add_reaction(reaction)
return

for egg_phrase in configuration_data["easter_egg_phrases"].keys():
if egg_phrase in contents:
await message.add_reaction(
configuration_data["easter_egg_phrases"][egg_phrase]
)

if DEBUG_MODE:
if re.match(PATTERN, contents.lower()): # debug block >1
extracted_number = re.match(PATTERN, contents.lower()).group(1)
Expand Down

0 comments on commit c0da5f2

Please sign in to comment.