aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-04-19 12:13:54 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2020-04-19 23:08:35 +0200
commitbe5d8906ed994b58416a330d7ccb987673d38674 (patch)
tree7f5b32267952f71e89c68e8de280b16eea89b390 /wee_slack.py
parentd618193419563f31b7c845cc92d9b6a77055cb8d (diff)
downloadwee-slack-be5d8906ed994b58416a330d7ccb987673d38674.tar.gz
Fix completion for /slack status
Previously, the emoji completion only returned emojis if you tried to complete after typing a :. This prevented it to be used in commands without typing : first.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 345706d..6eeb01a 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -341,6 +341,9 @@ def handle_socket_error(exception, team, caller_name):
team.set_disconnected()
+MESSAGE_ID_REGEX_STRING = r'(?P<msg_id>\d+|\$[0-9a-fA-F]{3,})'
+REACTION_PREFIX_REGEX_STRING = r'{}?(?P<reaction_change>\+|-)'.format(MESSAGE_ID_REGEX_STRING)
+
EMOJI_CHAR_REGEX_STRING = '(?P<emoji_char>[\U00000080-\U0010ffff]+)'
EMOJI_NAME_REGEX_STRING = ':(?P<emoji_name>[a-z0-9_+-]+):'
EMOJI_CHAR_OR_NAME_REGEX_STRING = '({}|{})'.format(EMOJI_CHAR_REGEX_STRING, EMOJI_NAME_REGEX_STRING)
@@ -832,17 +835,16 @@ def buffer_input_callback(signal, buffer_ptr, data):
else:
return int(message_id)
- message_id_regex = r"(\d*|\$[0-9a-fA-F]{3,})"
- reaction = re.match(r"^{}(\+|-){}\s*$".format(message_id_regex, EMOJI_CHAR_OR_NAME_REGEX_STRING), data)
- substitute = re.match("^{}s/".format(message_id_regex), data)
+ reaction = re.match(r"{}{}\s*$".format(REACTION_PREFIX_REGEX_STRING, EMOJI_CHAR_OR_NAME_REGEX_STRING), data)
+ substitute = re.match("{}s/".format(MESSAGE_ID_REGEX_STRING), data)
if reaction:
emoji = reaction.group("emoji_char") or reaction.group("emoji_name")
- if reaction.group(2) == "+":
- channel.send_add_reaction(get_id(reaction.group(1)), emoji)
- elif reaction.group(2) == "-":
- channel.send_remove_reaction(get_id(reaction.group(1)), emoji)
+ if reaction.group("reaction_change") == "+":
+ channel.send_add_reaction(get_id(reaction.group("msg_id")), emoji)
+ elif reaction.group("reaction_change") == "-":
+ channel.send_remove_reaction(get_id(reaction.group("msg_id")), emoji)
elif substitute:
- msg_id = get_id(substitute.group(1))
+ msg_id = get_id(substitute.group("msg_id"))
try:
old, new, flags = re.split(r'(?<!\\)/', data)[1:]
except ValueError:
@@ -1074,9 +1076,8 @@ def emoji_completion_cb(data, completion_item, current_buffer, completion):
return w.WEECHAT_RC_OK
base_word = w.hook_completion_get_string(completion, "base_word")
- if ":" not in base_word:
- return w.WEECHAT_RC_OK
- prefix = base_word.split(":")[0] + ":"
+ reaction = re.match(REACTION_PREFIX_REGEX_STRING + ":", base_word)
+ prefix = reaction.group(0) if reaction else ":"
for emoji in current_channel.team.emoji_completions:
w.hook_completion_list_add(completion, prefix + emoji + ":", 0, w.WEECHAT_LIST_POS_SORT)