Philipp Hörist pushed to branch master at gajim / gajim
Commits:
39419831 by Philipp Hörist at 2022-12-26T09:56:07+01:00
cfix: Improve command detection
- - - - -
3 changed files:
- gajim/common/commands.py
- gajim/common/regex.py
- gajim/gtk/message_actions_box.py
Changes:
=====================================
gajim/common/commands.py
=====================================
@@ -29,6 +29,7 @@
from gajim.common.helpers import Observable, is_role_change_allowed
from gajim.common.helpers import is_affiliation_change_allowed
from gajim.common.modules.contacts import GroupchatContact
+from gajim.common import regex
def split_argument_string(string: str) -> list[str]:
@@ -133,7 +134,13 @@ def add_command(self,
usage = get_usage_from_command(cmd, command_name)
self._commands[command_name] = (used_in, usage)
- def parse(self, type_: str, arg_string: str) -> None:
+ def parse(self, type_: str, arg_string: str) -> bool:
+ if arg_string.startswith('/me '):
+ return False
+
+ if regex.COMMAND_REGEX.match(arg_string) is None:
+ return False
+
arg_list = split_argument_string(arg_string[1:])
command_name = arg_list[0]
@@ -161,6 +168,7 @@ def parse(self, type_: str, arg_string: str) -> None:
result = _('Command executed successfully')
self.notify('command-result', result)
+ return True
def _create_commands(self) -> None:
parser = self.make_parser('help', self._help_command)
=====================================
gajim/common/regex.py
=====================================
@@ -16,6 +16,8 @@
from typing import Any
+COMMAND_REGEX = re.compile(r'^/[a-z]+')
+
INVALID_XML_CHARS_REGEX = re.compile(
'[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x1f]|[\ud800-\udfff]|[\ufffe-\uffff]')
=====================================
gajim/gtk/message_actions_box.py
=====================================
@@ -507,16 +507,14 @@ def _on_msg_textview_key_press_event(self,
assert self._contact is not None
message = self.msg_textview.get_text()
- if (message.startswith('/') and
- not message.startswith('//') and
- not message.startswith('/me ') and
- len(message) > 1):
- try:
- app.commands.parse(self._contact.type_string, message)
- except CommandFailed:
- pass
- else:
- self.msg_textview.clear()
+
+ try:
+ handled = app.commands.parse(self._contact.type_string,
message)
+ except CommandFailed:
+ return True
+
+ if handled:
+ self.msg_textview.clear()
return True
if not app.account_is_available(self._contact.account):
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/394198312fc1ed7fabe12169a5f14b708963d5f7
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/394198312fc1ed7fabe12169a5f14b708963d5f7
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits