diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-09-19 19:04:26 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2022-10-02 22:08:01 +0200 |
commit | 676a2fd668b288aedc42ea175e403ad17416552f (patch) | |
tree | fca8028b16e73a4e3d53c5000329235fff1cbee0 /wee_slack.py | |
parent | d638e457878a68bb1c8e8d5325c758efec95654a (diff) | |
download | wee-slack-676a2fd668b288aedc42ea175e403ad17416552f.tar.gz |
Update usage of deprecated WeeChat API methods
The script will use the new methods if the WeeChat version is new
enough, and the old deprecated methods if it's too old for the new ones.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/wee_slack.py b/wee_slack.py index 18569ce..d54da7f 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1237,7 +1237,7 @@ def channel_completion_cb(data, completion_item, current_buffer, completion): for team in other_teams: for channel in team.channels.values(): if should_include_channel(channel): - w.hook_completion_list_add( + completion_list_add( completion, channel.name, 0, w.WEECHAT_LIST_POS_SORT ) @@ -1248,12 +1248,12 @@ def channel_completion_cb(data, completion_item, current_buffer, completion): reverse=True, ): if should_include_channel(channel): - w.hook_completion_list_add( + completion_list_add( completion, channel.name, 0, w.WEECHAT_LIST_POS_BEGINNING ) if should_include_channel(current_channel): - w.hook_completion_list_add( + completion_list_add( completion, current_channel.name, 0, w.WEECHAT_LIST_POS_BEGINNING ) return w.WEECHAT_RC_OK @@ -1267,7 +1267,7 @@ def dm_completion_cb(data, completion_item, current_buffer, completion): for team in EVENTROUTER.teams.values(): for channel in team.channels.values(): if channel.active and channel.type in ["im", "mpim"]: - w.hook_completion_list_add( + completion_list_add( completion, channel.name, 0, w.WEECHAT_LIST_POS_SORT ) return w.WEECHAT_RC_OK @@ -1282,7 +1282,7 @@ def nick_completion_cb(data, completion_item, current_buffer, completion): if current_channel is None or current_channel.members is None: return w.WEECHAT_RC_OK - base_command = w.hook_completion_get_string(completion, "base_command") + base_command = completion_get_string(completion, "base_command") if base_command in ["invite", "msg", "query", "whois"]: members = current_channel.team.members else: @@ -1291,12 +1291,8 @@ def nick_completion_cb(data, completion_item, current_buffer, completion): for member in members: user = current_channel.team.users.get(member) if user and not user.deleted: - w.hook_completion_list_add( - completion, user.name, 1, w.WEECHAT_LIST_POS_SORT - ) - w.hook_completion_list_add( - completion, "@" + user.name, 1, w.WEECHAT_LIST_POS_SORT - ) + completion_list_add(completion, user.name, 1, w.WEECHAT_LIST_POS_SORT) + completion_list_add(completion, "@" + user.name, 1, w.WEECHAT_LIST_POS_SORT) return w.WEECHAT_RC_OK @@ -1309,12 +1305,12 @@ def emoji_completion_cb(data, completion_item, current_buffer, completion): if current_channel is None: return w.WEECHAT_RC_OK - base_word = w.hook_completion_get_string(completion, "base_word") + base_word = completion_get_string(completion, "base_word") 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_list_add( completion, prefix + emoji + ":", 0, w.WEECHAT_LIST_POS_SORT ) return w.WEECHAT_RC_OK @@ -1335,7 +1331,7 @@ def thread_completion_cb(data, completion_item, current_buffer, completion): for thread_id, message_ts in sorted(threads, key=lambda item: item[1]): message = current_channel.messages.get(message_ts) if message and message.number_of_replies(): - w.hook_completion_list_add( + completion_list_add( completion, "$" + thread_id, 0, w.WEECHAT_LIST_POS_BEGINNING ) return w.WEECHAT_RC_OK @@ -1355,7 +1351,7 @@ def topic_completion_cb(data, completion_item, current_buffer, completion): if topic.split(" ", 1)[0] in channel_names: topic = "{} {}".format(current_channel.name, topic) - w.hook_completion_list_add(completion, topic, 0, w.WEECHAT_LIST_POS_SORT) + completion_list_add(completion, topic, 0, w.WEECHAT_LIST_POS_SORT) return w.WEECHAT_RC_OK @@ -1372,7 +1368,7 @@ def usergroups_completion_cb(data, completion_item, current_buffer, completion): subteam.handle for subteam in current_channel.team.subteams.values() ] for group in subteam_handles + ["@channel", "@everyone", "@here"]: - w.hook_completion_list_add(completion, group, 1, w.WEECHAT_LIST_POS_SORT) + completion_list_add(completion, group, 1, w.WEECHAT_LIST_POS_SORT) return w.WEECHAT_RC_OK @@ -7083,6 +7079,18 @@ if __name__ == "__main__": weechat_version = int(w.info_get("version_number", "") or 0) weechat_upgrading = w.info_get("weechat_upgrading", "") + completion_get_string = ( + w.hook_completion_get_string + if weechat_version < 0x2090000 + else w.completion_get_string + ) + + completion_list_add = ( + w.hook_completion_list_add + if weechat_version < 0x2090000 + else w.completion_list_add + ) + if weechat_version < 0x1030000: w.prnt( "", |