Add a host property to the SlackService
This commit is contained in:
parent
2c53416cc6
commit
eead3717c6
2 changed files with 20 additions and 2 deletions
|
@ -24,7 +24,11 @@ args = parse_args()
|
||||||
config = None
|
config = None
|
||||||
with open(args.config or 'rtmbot.conf', 'r') as f:
|
with open(args.config or 'rtmbot.conf', 'r') as f:
|
||||||
config = yaml.load(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)
|
bot = client.init(config)
|
||||||
try:
|
try:
|
||||||
bot.start()
|
bot.start()
|
||||||
|
|
16
service.py
16
service.py
|
@ -10,8 +10,22 @@ class SlackService(object):
|
||||||
|
|
||||||
_API_BASE = 'https://slack.com/api'
|
_API_BASE = 'https://slack.com/api'
|
||||||
|
|
||||||
def __init__(self, token):
|
def __init__(self, token, host):
|
||||||
self.token = token
|
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
|
# Endpoints
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue