aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2018-11-06 23:16:59 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2019-01-26 12:51:07 +0100
commita921bb4fd7380aaab918a816046c5903a6ea8f69 (patch)
treefe5f25ff2655241446c6521fe62ab96566920ade /wee_slack.py
parent46f62c5410e4cce3dd261b0d1cb49ace4bed5f27 (diff)
downloadwee-slack-a921bb4fd7380aaab918a816046c5903a6ea8f69.tar.gz
Merge linkarchive and openweb commands
linkarchive now supports being run without arguments, and if so it will output a link to either the team or the channel, depending on where it's run. openweb has been removed.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/wee_slack.py b/wee_slack.py
index e463e16..05223ab 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -3663,29 +3663,30 @@ def command_mute(data, current_buffer, args):
@slack_buffer_required
-def command_openweb(data, current_buffer, args):
- # if done from server buffer, open slack for reals
- channel = EVENTROUTER.weechat_controller.buffers[current_buffer]
- if isinstance(channel, SlackTeam):
- url = "https://{}".format(channel.team.domain)
- else:
- now = SlackTS()
- url = "https://{}/archives/{}/p{}000000".format(channel.team.domain, channel.slack_name, now.majorstr())
- w.prnt_date_tags(channel.team.channel_buffer, SlackTS().major, "openweb,logger_backlog_end,notify_none", url)
-
-@slack_buffer_required
+@utf8_decode
def command_linkarchive(data, current_buffer, args):
channel = EVENTROUTER.weechat_controller.buffers[current_buffer]
- message_id = args.split(' ', 1)[1]
- if message_id[0] == "$":
- message_id = message_id[1:]
- if isinstance(channel, SlackChannelCommon) and message_id in channel.hashed_messages:
- message = channel.hashed_messages[message_id]
- ts = message.ts
- url = "https://{}/archives/{}/p{}{:0>6}".format(channel.team.domain, channel.identifier, ts.majorstr(), ts.minorstr())
- if isinstance(message, SlackThreadMessage):
- url += "?thread_ts={}&cid={}".format(message.parent_message.ts, channel.identifier)
- w.command(current_buffer, "/input insert {}".format(url))
+ split_args = args.split()
+ message_id = split_args[1] if len(split_args) > 1 else None
+ url = 'https://{}/'.format(channel.team.domain)
+
+ if isinstance(channel, SlackChannelCommon):
+ url += 'archives/{}/'.format(channel.identifier)
+ if message_id:
+ if message_id[0] == '$':
+ message_id = message_id[1:]
+ message = channel.hashed_messages.get(message_id)
+ if message:
+ url += '{}{:0>6}'.format(message.ts.majorstr(), message.ts.minorstr())
+ if isinstance(message, SlackThreadMessage):
+ url += "?thread_ts={}&cid={}".format(message.parent_message.ts, channel.identifier)
+ else:
+ w.prnt('', 'ERROR: Invalid id given, must be an existing id')
+ return w.WEECHAT_RC_OK_EAT
+
+ w.command(current_buffer, "/input insert {}".format(url))
+ return w.WEECHAT_RC_OK
+
def command_nodistractions(data, current_buffer, args):
global hide_distractions