Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
39419831
by Philipp Hörist at 2022-12-26T09:56:07+01:00
3 changed files:
Changes:
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | from gajim.common.helpers import Observable, is_role_change_allowed
|
| 30 | 30 | from gajim.common.helpers import is_affiliation_change_allowed
|
| 31 | 31 | from gajim.common.modules.contacts import GroupchatContact
|
| 32 | +from gajim.common import regex
|
|
| 32 | 33 | |
| 33 | 34 | |
| 34 | 35 | def split_argument_string(string: str) -> list[str]:
|
| ... | ... | @@ -133,7 +134,13 @@ def add_command(self, |
| 133 | 134 | usage = get_usage_from_command(cmd, command_name)
|
| 134 | 135 | self._commands[command_name] = (used_in, usage)
|
| 135 | 136 | |
| 136 | - def parse(self, type_: str, arg_string: str) -> None:
|
|
| 137 | + def parse(self, type_: str, arg_string: str) -> bool:
|
|
| 138 | + if arg_string.startswith('/me '):
|
|
| 139 | + return False
|
|
| 140 | + |
|
| 141 | + if regex.COMMAND_REGEX.match(arg_string) is None:
|
|
| 142 | + return False
|
|
| 143 | + |
|
| 137 | 144 | arg_list = split_argument_string(arg_string[1:])
|
| 138 | 145 | |
| 139 | 146 | command_name = arg_list[0]
|
| ... | ... | @@ -161,6 +168,7 @@ def parse(self, type_: str, arg_string: str) -> None: |
| 161 | 168 | result = _('Command executed successfully')
|
| 162 | 169 | |
| 163 | 170 | self.notify('command-result', result)
|
| 171 | + return True
|
|
| 164 | 172 | |
| 165 | 173 | def _create_commands(self) -> None:
|
| 166 | 174 | parser = self.make_parser('help', self._help_command)
|
| ... | ... | @@ -16,6 +16,8 @@ |
| 16 | 16 | from typing import Any
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | +COMMAND_REGEX = re.compile(r'^/[a-z]+')
|
|
| 20 | + |
|
| 19 | 21 | INVALID_XML_CHARS_REGEX = re.compile(
|
| 20 | 22 | '[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x1f]|[\ud800-\udfff]|[\ufffe-\uffff]')
|
| 21 | 23 |
| ... | ... | @@ -507,16 +507,14 @@ def _on_msg_textview_key_press_event(self, |
| 507 | 507 | assert self._contact is not None
|
| 508 | 508 | |
| 509 | 509 | message = self.msg_textview.get_text()
|
| 510 | - if (message.startswith('/') and
|
|
| 511 | - not message.startswith('//') and
|
|
| 512 | - not message.startswith('/me ') and
|
|
| 513 | - len(message) > 1):
|
|
| 514 | - try:
|
|
| 515 | - app.commands.parse(self._contact.type_string, message)
|
|
| 516 | - except CommandFailed:
|
|
| 517 | - pass
|
|
| 518 | - else:
|
|
| 519 | - self.msg_textview.clear()
|
|
| 510 | + |
|
| 511 | + try:
|
|
| 512 | + handled = app.commands.parse(self._contact.type_string, message)
|
|
| 513 | + except CommandFailed:
|
|
| 514 | + return True
|
|
| 515 | + |
|
| 516 | + if handled:
|
|
| 517 | + self.msg_textview.clear()
|
|
| 520 | 518 | return True
|
| 521 | 519 | |
| 522 | 520 | if not app.account_is_available(self._contact.account):
|