Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.
Draft
Changes from 1 commit
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
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