diff --git a/StdoutCapture/config.py b/StdoutCapture/config.py index bdf3bba..0b3352c 100644 --- a/StdoutCapture/config.py +++ b/StdoutCapture/config.py @@ -51,6 +51,9 @@ StdoutCapture = conf.registerPlugin('StdoutCapture') # This is where your configuration variables (if any) should go. For example: # conf.registerGlobalValue(StdoutCapture, 'someConfigVariableName', # registry.Boolean(False, _("""Help for someConfigVariableName."""))) +conf.registerChannelValue(StdoutCapture, 'pastebin', + registry.String('http://paste.progval.net/', _("""Default pastebin. + The pastebin has to support the LodgeIt API."""))) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/StdoutCapture/plugin.py b/StdoutCapture/plugin.py index 29688d6..4dc8be7 100644 --- a/StdoutCapture/plugin.py +++ b/StdoutCapture/plugin.py @@ -29,6 +29,7 @@ ### import sys +import json import logging import supybot.utils as utils @@ -90,7 +91,26 @@ class StdoutCapture(callbacks.Plugin): Return the last lines displayed in the console.""" irc.replies(StdoutBuffer._buffer[-number:]) - history = wrap(history, ['positiveInt']) + history = wrap(history, ['positiveInt', 'owner']) + + def pastebin(self, irc, msg, args, number, url=None): + """ [] + + Paste the last lines displayed in the console on a pastebin and + returns the URL. + The pastebin has to support the LodgeIt API.""" + base = url or self.registryValue('pastebin', msg.args[0]) + if base.endswith('/'): + base = base[0:-1] + fd = utils.web.getUrlFd(base+'/json/?method=pastes.newPaste', + data=json.dumps({ + 'language': 'text', + 'code': ''.join(StdoutBuffer._buffer[-number:]), + }), + headers={'Content-Type': 'application/json'}) + irc.reply('%s/show/%s' % (base, json.load(fd)['data'])) + + pastebin = wrap(pastebin, ['owner', 'positiveInt', optional('text')]) Class = StdoutCapture