Implement #success command in statusbot
Add simple unprivileged "#praise" command that adds praises snippets to a celebration wiki page. NB: this adds a couple of configuration options, but fails gracefully if they are not present. Change-Id: I995c3189f0f109df35c56b63b3e19427f60f3750
This commit is contained in:
parent
57d6ed9ad7
commit
02fb269d8b
|
@ -31,6 +31,7 @@ password=password
|
|||
url=https://wiki.example.com/w/api.php
|
||||
pageid=1781
|
||||
successpageid=2434
|
||||
praisepageid=4278
|
||||
|
||||
[irclogs]
|
||||
url=http://eavesdrop.example.com/irclogs/%(chan)s/%(chan)s.%(date)s.log.html
|
||||
|
@ -141,6 +142,36 @@ class SuccessPage(WikiPage):
|
|||
self.save(newtext)
|
||||
|
||||
|
||||
class PraisePage(WikiPage):
|
||||
def __init__(self, config):
|
||||
super(PraisePage, self).__init__(config)
|
||||
if config.has_option('wiki', 'praisepageid'):
|
||||
self.pageid = config.get('wiki', 'praisepageid')
|
||||
else:
|
||||
self.pageid = None
|
||||
if config.has_option('irclogs', 'url'):
|
||||
self.irclogs_url = config.get('irclogs', 'url')
|
||||
else:
|
||||
self.irclogs_url = None
|
||||
|
||||
def log(self, channel, nick, msg):
|
||||
if self.pageid:
|
||||
self.login()
|
||||
ts = self.timestamp()
|
||||
if self.irclogs_url:
|
||||
url = self.irclogs_url % {
|
||||
'chan': urllib.quote(channel),
|
||||
'date': ts[0:10]}
|
||||
onchan = "[%s %s]" % (url, channel)
|
||||
else:
|
||||
onchan = channel
|
||||
data = self.load()
|
||||
current = data.split("\n")
|
||||
newtext = "%s\n|-\n| %s || %s (on %s) || %s\n%s" % (
|
||||
current[0], ts, nick, onchan, msg, '\n'.join(current[1:]))
|
||||
self.save(newtext)
|
||||
|
||||
|
||||
class UpdateInterface(object):
|
||||
def alert(self, msg=None):
|
||||
pass
|
||||
|
@ -283,7 +314,7 @@ class AlertFile(UpdateInterface):
|
|||
class StatusBot(irc.bot.SingleServerIRCBot):
|
||||
log = logging.getLogger("statusbot.bot")
|
||||
|
||||
def __init__(self, channels, nicks, publishers, successlog,
|
||||
def __init__(self, channels, nicks, publishers, successlog, praiselog,
|
||||
nickname, password, server, port=6667):
|
||||
if port == 6697:
|
||||
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
||||
|
@ -304,6 +335,7 @@ class StatusBot(irc.bot.SingleServerIRCBot):
|
|||
self.current_topic = None
|
||||
self.publishers = publishers
|
||||
self.successlog = successlog
|
||||
self.praiselog = praiselog
|
||||
|
||||
def on_nicknameinuse(self, c, e):
|
||||
self.log.debug("Nickname in use, releasing")
|
||||
|
@ -366,6 +398,13 @@ class StatusBot(irc.bot.SingleServerIRCBot):
|
|||
self.successlog.log(channel, nick, text)
|
||||
self.send(channel, "%s: Added success to Success page" % (nick,))
|
||||
|
||||
def handle_praise(self, channel, nick, msg):
|
||||
parts = msg.split()
|
||||
text = ' '.join(parts[1:])
|
||||
self.log.info("Processing praise from %s: %s" % (nick, text))
|
||||
self.praiselog.log(channel, nick, text)
|
||||
self.send(channel, "%s: Added praise to Praise page" % (nick,))
|
||||
|
||||
def handle_status_command(self, channel, nick, msg):
|
||||
parts = msg.split()
|
||||
command = parts[1].lower()
|
||||
|
@ -457,10 +496,11 @@ def _main(configpath):
|
|||
publishers = [StatusPage(config),
|
||||
AlertFile(config)]
|
||||
successlog = SuccessPage(config)
|
||||
praiselog = PraisePage(config)
|
||||
if config.has_section('twitter'):
|
||||
publishers.append(Tweet(config))
|
||||
|
||||
bot = StatusBot(channels, nicks, publishers, successlog,
|
||||
bot = StatusBot(channels, nicks, publishers, successlog, praiselog,
|
||||
config.get('ircbot', 'nick'),
|
||||
config.get('ircbot', 'pass'),
|
||||
config.get('ircbot', 'server'),
|
||||
|
|
Loading…
Reference in New Issue