diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-12 00:53:33 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-08-25 19:45:18 +0200 |
commit | a2b4d08ba6b9cbe190ff6b46db4cf429e83e8f80 (patch) | |
tree | e859223ed41a10ccb0ebb8dcf41efef1647e607f /wee_slack.py | |
parent | 4b142ddbd37adee2a4eef5b4a0c372dd7d8fe38c (diff) | |
download | wee-slack-a2b4d08ba6b9cbe190ff6b46db4cf429e83e8f80.tar.gz |
Linkify users in /slack slash command
If we don't linkify users, only usernames (which are not shown anymore)
are accepted by the chat.command endpoint, not display names. It does
accept user links, so we can use that. However, it doesn't seem to
accept channel links (at least the invite command, which is what I
tested), so we only linkify users.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py index 35854c1..032965e 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3195,7 +3195,7 @@ def render_formatting(text): return text -def linkify_text(message, team): +def linkify_text(message, team, only_users=False): # The get_username_map function is a bit heavy, but this whole # function is only called on message send.. usernames = team.get_username_map() @@ -3223,7 +3223,7 @@ def linkify_text(message, team): return "<@{}>".format(usernames[name]) elif word in usergroups.keys(): return "<!subteam^{}|{}>".format(usergroups[word], word) - elif prefix == "#": + elif prefix == "#" and not only_users: if word in channels: return "<#{}|{}>".format(channels[word], name) return word @@ -4037,9 +4037,10 @@ def command_slash(data, current_buffer, args): split_args = args.split(' ', 1) command = split_args[0] text = split_args[1] if len(split_args) > 1 else "" + text_linkified = linkify_text(text, team, only_users=True) s = SlackRequest(team.token, "chat.command", - {"command": command, "text": text, 'channel': channel.identifier}, + {"command": command, "text": text_linkified, 'channel': channel.identifier}, team_hash=team.team_hash, channel_identifier=channel.identifier, command=command, command_args=text) EVENTROUTER.receive(s) |