StdoutCapture: add @pastebin.

master
Valentin Lorentz 2013-05-21 18:27:12 +02:00
parent 9f1e086e63
commit 2f48afcd9b
2 changed files with 24 additions and 1 deletions

View File

@ -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:

View File

@ -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):
"""<number> [<pastebin url>]
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