get mention text Examples: >>> msg.mention_text() Returns: str: the message text without mention
(self)
| 466 | return [] |
| 467 | |
| 468 | async def mention_text(self) -> str: |
| 469 | """ |
| 470 | get mention text |
| 471 | |
| 472 | Examples: |
| 473 | >>> msg.mention_text() |
| 474 | Returns: |
| 475 | str: the message text without mention |
| 476 | """ |
| 477 | text = self.text() |
| 478 | room = self.room() |
| 479 | |
| 480 | mention_list = await self.mention_list() |
| 481 | |
| 482 | if room is None or len(mention_list) <= 0: |
| 483 | return text |
| 484 | |
| 485 | async def get_alias_or_name(member: Contact) -> str: |
| 486 | if room is not None: |
| 487 | alias = await room.alias(member) |
| 488 | if alias: |
| 489 | return alias |
| 490 | return member.name |
| 491 | |
| 492 | # TODO -> change to python async best practice |
| 493 | # flake8: disable=F841 |
| 494 | mention_names = [ |
| 495 | await get_alias_or_name(member) |
| 496 | for member in mention_list] |
| 497 | |
| 498 | while len(mention_names) > 0: |
| 499 | escaped_cur = mention_names.pop() |
| 500 | pattern = re.compile(f'@{escaped_cur}(\u2005|\u0020|$)') |
| 501 | text = re.sub(pattern, '', text) |
| 502 | |
| 503 | return text |
| 504 | |
| 505 | async def mention_self(self) -> bool: |
| 506 | """ |
nothing calls this directly
no test coverage detected