Add Etherpad backend

Change-Id: Ia525ed337ac7569bec54b70bf57a6c010c33f801
This commit is contained in:
Tristan Cacqueray 2021-09-08 19:20:41 +00:00
parent 0edde4fccc
commit 42e3cc433d

View File

@ -25,6 +25,7 @@ port=6697
use_sasl=False use_sasl=False
channels=foo,bar channels=foo,bar
nicks=alice,bob nicks=alice,bob
backend=wiki
[wiki] [wiki]
username=StatusBot username=StatusBot
@ -36,6 +37,13 @@ successpageurl=https://wiki.example.com/w/Success
thankspageid=37700 thankspageid=37700
thankspageurl=https://wiki.example.com/w/Thanks 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] [irclogs]
url=http://eavesdrop.example.com/irclogs/%(chan)s/%(chan)s.%(date)s.log.html url=http://eavesdrop.example.com/irclogs/%(chan)s/%(chan)s.%(date)s.log.html
@ -60,6 +68,7 @@ import time
import simplemediawiki import simplemediawiki
import datetime import datetime
import re import re
import requests
import twitter import twitter
import urllib import urllib
@ -124,6 +133,23 @@ class WikiPage(BackendInterface):
token=token)) 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): def timestamp(ts=None):
if not ts: if not ts:
ts = datetime.datetime.now() ts = datetime.datetime.now()
@ -138,6 +164,9 @@ class SuccessPage(object):
self.backend.pageid = config.get('wiki', 'successpageid', fallback=None) self.backend.pageid = config.get('wiki', 'successpageid', fallback=None)
self.backend.pageurl = config.get('wiki', 'successpageurl', fallback=None) self.backend.pageurl = config.get('wiki', 'successpageurl', fallback=None)
self.ready = self.backend.pageid is not 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'): if config.has_option('irclogs', 'url'):
self.irclogs_url = config.get('irclogs', 'url') self.irclogs_url = config.get('irclogs', 'url')
else: else:
@ -168,6 +197,9 @@ class ThanksPage(object):
self.backend.pageid = config.get('wiki', 'thankspageid', fallback=None) self.backend.pageid = config.get('wiki', 'thankspageid', fallback=None)
self.backend.pageurl = config.get('wiki', 'thankspageurl', fallback=None) self.backend.pageurl = config.get('wiki', 'thankspageurl', fallback=None)
self.ready = self.backend.pageid is not 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'): if config.has_option('irclogs', 'url'):
self.irclogs_url = config.get('irclogs', 'url') self.irclogs_url = config.get('irclogs', 'url')
else: else:
@ -503,6 +535,9 @@ def _main(configpath):
config.read(configpath) config.read(configpath)
setup_logging(config) setup_logging(config)
if config.get('ircbot', 'backend', fallback=None) == "etherpad":
backend = EtherPage
else:
backend = WikiPage backend = WikiPage
channels = ['#' + name.strip() for name in channels = ['#' + name.strip() for name in