From eead3717c616e424f90de21243e86fbf59996c2e Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 26 Sep 2016 00:07:22 -0400 Subject: [PATCH] Add a host property to the SlackService --- rtmbot.py | 6 +++++- service.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rtmbot.py b/rtmbot.py index 163d39b..4e68f70 100755 --- a/rtmbot.py +++ b/rtmbot.py @@ -24,7 +24,11 @@ args = parse_args() config = None with open(args.config or 'rtmbot.conf', 'r') as f: config = yaml.load(f) -service.slack = service.SlackService(config.get('SLACK_TOKEN')) + +token = config.get('SLACK_TOKEN') +host = config.get('HOST') +service.slack = service.SlackService(token, host) + bot = client.init(config) try: bot.start() diff --git a/service.py b/service.py index b96629e..cc7548b 100644 --- a/service.py +++ b/service.py @@ -10,8 +10,22 @@ class SlackService(object): _API_BASE = 'https://slack.com/api' - def __init__(self, token): + def __init__(self, token, host): self.token = token + self.host = host + + def permalink(self, channel, message): + ''' + Generate a permalink to the given message object in the given channel. + Channel should be the name of the channel, without the leading '#'. + `message` should have a `ts` field. + ''' + try: + ts = message['ts'] + except KeyError: + return + ts = ts.replace('.', '') + return 'https://{}/archives/{}/p{}'.format(self.host, channel, ts) # # Endpoints