Add Etherpad backend
Change-Id: Ia525ed337ac7569bec54b70bf57a6c010c33f801
This commit is contained in:
parent
0edde4fccc
commit
42e3cc433d
@ -25,6 +25,7 @@ port=6697
|
||||
use_sasl=False
|
||||
channels=foo,bar
|
||||
nicks=alice,bob
|
||||
backend=wiki
|
||||
|
||||
[wiki]
|
||||
username=StatusBot
|
||||
@ -36,6 +37,13 @@ successpageurl=https://wiki.example.com/w/Success
|
||||
thankspageid=37700
|
||||
thankspageurl=https://wiki.example.com/w/Thanks
|
||||
|
||||
# when using etherpad, set the ircbot.backend value to etherpad
|
||||
[etherpad]
|
||||
url=https://etherpad.example.com/p
|
||||
pad=infra-status
|
||||
successpad=success
|
||||
thankspad=thanks
|
||||
|
||||
[irclogs]
|
||||
url=http://eavesdrop.example.com/irclogs/%(chan)s/%(chan)s.%(date)s.log.html
|
||||
|
||||
@ -60,6 +68,7 @@ import time
|
||||
import simplemediawiki
|
||||
import datetime
|
||||
import re
|
||||
import requests
|
||||
import twitter
|
||||
import urllib
|
||||
|
||||
@ -124,6 +133,23 @@ class WikiPage(BackendInterface):
|
||||
token=token))
|
||||
|
||||
|
||||
class EtherPage(BackendInterface):
|
||||
def __init__(self, config):
|
||||
self.url = config.get('etherpad', 'url')
|
||||
self.pad = config.get('etherpad', 'pad')
|
||||
|
||||
@property
|
||||
def pageurl(self):
|
||||
return '/'.join([self.url, self.pad or 'undefined'])
|
||||
|
||||
def load(self):
|
||||
return requests.get('/'.join([self.url, self.pad, 'export/txt'])).text
|
||||
|
||||
def save(self, text):
|
||||
requests.post('/'.join([self.url, self.pad, 'import']),
|
||||
files=dict(file=text))
|
||||
|
||||
|
||||
def timestamp(ts=None):
|
||||
if not ts:
|
||||
ts = datetime.datetime.now()
|
||||
@ -138,6 +164,9 @@ class SuccessPage(object):
|
||||
self.backend.pageid = config.get('wiki', 'successpageid', fallback=None)
|
||||
self.backend.pageurl = config.get('wiki', 'successpageurl', fallback=None)
|
||||
self.ready = self.backend.pageid is not None
|
||||
elif isinstance(self.backend, EtherPage):
|
||||
self.backend.pad = config.get('etherpad', 'successpad', fallback=None)
|
||||
self.ready = self.backend.pad is not None
|
||||
if config.has_option('irclogs', 'url'):
|
||||
self.irclogs_url = config.get('irclogs', 'url')
|
||||
else:
|
||||
@ -168,6 +197,9 @@ class ThanksPage(object):
|
||||
self.backend.pageid = config.get('wiki', 'thankspageid', fallback=None)
|
||||
self.backend.pageurl = config.get('wiki', 'thankspageurl', fallback=None)
|
||||
self.ready = self.backend.pageid is not None
|
||||
elif isinstance(self.backend, EtherPage):
|
||||
self.backend.pad = config.get('etherpad', 'thankspad', fallback=None)
|
||||
self.ready = self.backend.pad is not None
|
||||
if config.has_option('irclogs', 'url'):
|
||||
self.irclogs_url = config.get('irclogs', 'url')
|
||||
else:
|
||||
@ -503,7 +535,10 @@ def _main(configpath):
|
||||
config.read(configpath)
|
||||
setup_logging(config)
|
||||
|
||||
backend = WikiPage
|
||||
if config.get('ircbot', 'backend', fallback=None) == "etherpad":
|
||||
backend = EtherPage
|
||||
else:
|
||||
backend = WikiPage
|
||||
|
||||
channels = ['#' + name.strip() for name in
|
||||
config.get('ircbot', 'channels').split(',')]
|
||||
|
Loading…
Reference in New Issue
Block a user