Add mastodon support
Add very simple mastodon support. Basically send a request with a bearer token. Change-Id: I345dfa5d68a5cbf4035db85be9883592f143dd93
This commit is contained in:
parent
a0760a8025
commit
0263b3abda
@ -52,6 +52,11 @@ consumer_key=consumer_key
|
||||
consumer_secret=consumer_secret
|
||||
access_token_key=access_token_key
|
||||
access_token_secret=access_token_secret
|
||||
|
||||
[mastodon]
|
||||
host=https://example.com
|
||||
token='mastodon_bearer_token'
|
||||
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@ -294,6 +299,48 @@ class Tweet(UpdateInterface):
|
||||
self.update('\u2705\ufe0f Everything back to normal')
|
||||
|
||||
|
||||
class Toot(UpdateInterface):
|
||||
log = logging.getLogger("statusbot.toot")
|
||||
|
||||
def __init__(self, config):
|
||||
self.host = config.get('mastodon', 'host')
|
||||
self.token = config.get('mastodon', 'token')
|
||||
|
||||
def update(self, msg):
|
||||
# NOTE(ianw) Toots are 500 characters, which should be enough.
|
||||
# Figure out chaining some other time
|
||||
url = '%s/api/v1/statuses' % (self.host)
|
||||
data = {'status': msg}
|
||||
|
||||
r = requests.post(url, data=data,
|
||||
headers={
|
||||
'Authorization': 'Bearer %s' % (self.token)})
|
||||
# not sure what to check for...
|
||||
if r.status_code == 200:
|
||||
json_data = r.json()
|
||||
self.log('Tooted id: %s' % json_data['id'])
|
||||
else:
|
||||
self.log('Toot failed: %s' % r.status_code)
|
||||
|
||||
def alert(self, msg=None):
|
||||
# warning sign
|
||||
self.update('\u26A0\ufe0f ' + msg)
|
||||
|
||||
def notice(self, msg=None):
|
||||
# pushpin (notice board)
|
||||
self.update('\U0001f4cc ' + msg)
|
||||
|
||||
def log(self, msg=None):
|
||||
# wood (log)
|
||||
self.update('\U0001fab5 ' + msg)
|
||||
|
||||
def ok(self, msg=None):
|
||||
if msg:
|
||||
self.update('\u2705\ufe0f ' + msg)
|
||||
else:
|
||||
self.update('\u2705\ufe0f Everything back to normal')
|
||||
|
||||
|
||||
class StatusPage(UpdateInterface):
|
||||
alert_re = re.compile(r'{{CI Alert\|(.*?)}}')
|
||||
item_re = re.compile(r'^\* (.*)$')
|
||||
@ -579,6 +626,8 @@ def _main(configpath):
|
||||
thankslog = ThanksPage(config, backend)
|
||||
if config.has_section('twitter'):
|
||||
publishers.append(Tweet(config))
|
||||
if config.has_section('mastodon'):
|
||||
publishers.append(Toot(config))
|
||||
|
||||
if config.has_option('ircbot', 'use_sasl'):
|
||||
use_sasl = config.getboolean('ircbot', 'use_sasl')
|
||||
|
Loading…
x
Reference in New Issue
Block a user