Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Refactor messagematch.command
Browse files Browse the repository at this point in the history
  • Loading branch information
krazykirby99999 committed Nov 25, 2021
1 parent e73f24b commit 2d63cbe
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions simplematrixbotlib/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,26 @@ def command(self, command=None):
elif self.mention():
# the order is important here!
# note: we assume that body and formatted_body, if present, match as a workaraound of cleaning html
if self.event.body.startswith(self._disambiguated_name):
self._body_without_prefix = self.event.body[len(self._disambiguated_name):]
elif self.event.body.startswith(self._display_name):
self._body_without_prefix = self.event.body[len(self._display_name):]
elif self.event.body.startswith(self.room.own_user_id):
self._body_without_prefix = self.event.body[len(self.room.own_user_id):]
elif self.event.formatted_body.startswith(self._pill):
name = self.event.formatted_body[len(self._pill):self.event.formatted_body.index('</a>')]
id_matched = False
for id in (self._disambiguated_name, self._display_name, self.room.own_user_id):
if self.event.body.startswith(id) and not id_matched:
self._body_without_prefix = self.event.body[len(id):]
id_matched = True

if self.event.formatted_body.startswith(self._pill) and not id_matched:
name = self.event.formatted_body[len():self.event.formatted_body.index('</a>')]
self._body_without_prefix = self.event.body[len(name):]

# mentioning may include a : (colon) as inserted by Element when clicking on a user
if self._body_without_prefix.startswith(':'):
self._body_without_prefix = self._body_without_prefix[1:]

# trim leading whitespace after the mention
self._body_without_prefix = self._body_without_prefix.strip()

else:
self._body_without_prefix = self.event.body

if not self._body_without_prefix:
return []

if command:
return self._body_without_prefix.split()[0] == command
else:
Expand Down

0 comments on commit 2d63cbe

Please sign in to comment.