mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Made commands.wrap stop doing decorators, exposed thread and urlSnarfer, and changed plugins accordingly.
This commit is contained in:
parent
6389256dc2
commit
c943ab77bb
@ -267,7 +267,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
|
||||
report['product'] = str(summary['product'])
|
||||
s = '%(product)s bug #%(id)s: %(title)s %(summary)s' % report
|
||||
irc.reply(s, prefixName=False)
|
||||
bzSnarfer = wrap(bzSnarfer, decorators=['urlSnarfer'])
|
||||
bzSnarfer = urlSnarfer(bzSnarfer)
|
||||
|
||||
def urlquery2bugslist(self, url, query):
|
||||
"""Given a URL and query list for a CSV bug list, it'll return
|
||||
|
@ -127,7 +127,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp):
|
||||
irc.reply(self._getResponse(url), prefixName=False)
|
||||
except EbayError, e:
|
||||
self.log.info('ebaySnarfer exception at %s: %s', url, str(e))
|
||||
ebaySnarfer = wrap(ebaySnarfer, decorators=['urlSnarfer'])
|
||||
ebaySnarfer = urlSnarfer(ebaySnarfer)
|
||||
|
||||
def _getResponse(self, url):
|
||||
try:
|
||||
|
@ -223,7 +223,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
||||
irc.errorPossibleBug(s)
|
||||
except Exception, e:
|
||||
irc.error(utils.exnToString(e))
|
||||
gameknotSnarfer = wrap(gameknotSnarfer, decorators=['urlSnarfer'])
|
||||
gameknotSnarfer = urlSnarfer(gameknotSnarfer)
|
||||
|
||||
def gameknotStatsSnarfer(self, irc, msg, match):
|
||||
r"http://gameknot\.com/stats\.pl\?([^&]+)"
|
||||
@ -232,7 +232,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
||||
name = match.group(1)
|
||||
s = self.getStats(name)
|
||||
irc.reply(s, prefixName=False)
|
||||
gameknotStatsSnarfer = wrap(gameknotStatsSnarfer,decorators=['urlSnarfer'])
|
||||
gameknotStatsSnarfer = urlSnarfer(gameknotStatsSnarfer)
|
||||
|
||||
Class = Gameknot
|
||||
|
||||
|
@ -58,7 +58,6 @@ import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.webutils as webutils
|
||||
import supybot.privmsgs as privmsgs
|
||||
import supybot.registry as registry
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
@ -158,7 +157,7 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp):
|
||||
site = match.groupdict()['site']
|
||||
self.log.info('Snarfing geekquote %s from %s.' % (id, site))
|
||||
self._gkBackend(irc, msg, site, id)
|
||||
geekSnarfer = wrap(geekSnarfer, decorators=['urlSnarfer'])
|
||||
geekSnarfer = urlSnarfer(geekSnarfer)
|
||||
|
||||
def geekquote(self, irc, msg, args, id):
|
||||
"""[<id>]
|
||||
@ -168,7 +167,7 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp):
|
||||
"""
|
||||
site = 'bash.org'
|
||||
self._gkBackend(irc, msg, site, id)
|
||||
geekquote = wrap(geekquote, [optional(('id', 'geekquote'))])
|
||||
geekquote = wrap(geekquote, [additional(('id', 'geekquote'))])
|
||||
|
||||
def qdb(self, irc, msg, args, id):
|
||||
"""[<id>]
|
||||
@ -176,10 +175,9 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp):
|
||||
Returns a random geek quote from qdb.us; the optional argument
|
||||
<id> specifies which quote to retrieve.
|
||||
"""
|
||||
id = privmsgs.getArgs(args, required=0, optional=1)
|
||||
site = 'qdb.us'
|
||||
self._gkBackend(irc, msg, site, id)
|
||||
qdb = wrap(qdb, [optional(('id', 'qdb'))])
|
||||
qdb = wrap(qdb, [additional(('id', 'qdb'))])
|
||||
|
||||
Class = Geekquote
|
||||
|
||||
|
@ -427,7 +427,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
if data.results:
|
||||
url = data.results[0].URL
|
||||
irc.reply(url, prefixName=False)
|
||||
googleSnarfer = wrap(googleSnarfer, decorators=['urlSnarfer'])
|
||||
googleSnarfer = urlSnarfer(googleSnarfer)
|
||||
|
||||
_ggThread = re.compile(r'<br>Subject: ([^<]+)<br>', re.I)
|
||||
_ggGroup = re.compile(r'Newsgroups: (?:<a[^>]+>)?([^<]+)(?:</a>)?', re.I)
|
||||
@ -460,7 +460,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
else:
|
||||
irc.errorPossibleBug('That doesn\'t appear to be a proper '
|
||||
'Google Groups page.')
|
||||
googleGroups = wrap(googleGroups, decorators=['urlSnarfer'])
|
||||
googleGroups = urlSnarfer(googleGroups)
|
||||
|
||||
_calcRe = re.compile(r'<td nowrap><font size=\+1><b>(.*?)</b>', re.I)
|
||||
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)
|
||||
|
@ -193,7 +193,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp):
|
||||
resp.append('%s: %s' % self._bold(m.groups()))
|
||||
if resp:
|
||||
irc.reply('; '.join(resp), prefixName = False)
|
||||
aspnRecipes = wrap(aspnRecipes, decorators=['urlSnarfer'])
|
||||
aspnRecipes = urlSnarfer(aspnRecipes)
|
||||
|
||||
|
||||
Class = Python
|
||||
|
@ -189,7 +189,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
||||
if m is None:
|
||||
print irc, irc.__class__
|
||||
m.tag('shrunken')
|
||||
shrinkSnarfer = wrap(shrinkSnarfer, decorators=['urlSnarfer'])
|
||||
shrinkSnarfer = urlSnarfer(shrinkSnarfer)
|
||||
|
||||
def _getLnUrl(self, url):
|
||||
try:
|
||||
@ -219,7 +219,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
||||
m.tag('shrunken')
|
||||
else:
|
||||
irc.error(error)
|
||||
ln = wrap(ln, ['url'], decorators=['thread'])
|
||||
ln = thread(wrap(ln, ['url']))
|
||||
|
||||
_tinyRe = re.compile(r'<blockquote><b>(http://tinyurl\.com/\w+)</b>')
|
||||
def _getTinyUrl(self, url):
|
||||
@ -250,7 +250,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
||||
else:
|
||||
s = 'Could not parse the TinyURL.com results page.'
|
||||
irc.errorPossibleBug(s)
|
||||
tiny = wrap(tiny, ['url'], decorators=['thread'])
|
||||
tiny = thread(wrap(tiny, ['url']))
|
||||
|
||||
|
||||
Class = ShrinkUrl
|
||||
|
@ -510,7 +510,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
|
||||
irc.reply(resp, prefixName=False)
|
||||
except TrackerError, e:
|
||||
self.log.warning(str(e))
|
||||
sfSnarfer = wrap(sfSnarfer, decorators=['urlSnarfer'])
|
||||
sfSnarfer = urlSnarfer(sfSnarfer)
|
||||
|
||||
Class = Sourceforge
|
||||
|
||||
|
@ -139,7 +139,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp):
|
||||
title = utils.htmlToText(m.group(1).strip())
|
||||
s = 'Title: %s (at %s)' % (title, domain)
|
||||
irc.reply(s, prefixName=False)
|
||||
titleSnarfer = wrap(titleSnarfer, decorators=['urlSnarfer'])
|
||||
titleSnarfer = urlSnarfer(titleSnarfer)
|
||||
|
||||
def stats(self, irc, msg, args, channel):
|
||||
"""[<channel>]
|
||||
@ -152,7 +152,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp):
|
||||
irc.reply('I have %s in my database.' % utils.nItems('URL', count))
|
||||
stats = wrap(stats, ['channeldb'])
|
||||
|
||||
def last(self, irc, msg, args, optlist, channel):
|
||||
def last(self, irc, msg, args, channel, optlist):
|
||||
"""[<channel>] [--{from,with,without,near,proto}=<value>] --nolimit
|
||||
|
||||
Gives the last URL matching the given criteria. --from is from whom
|
||||
|
@ -279,7 +279,7 @@ class Misc(callbacks.Privmsg):
|
||||
s = 'The current (running) version of this Supybot is %s. %s' % \
|
||||
(conf.version, newest)
|
||||
irc.reply(s)
|
||||
version = wrap(version, decorators=['thread'])
|
||||
version = wrap(thread(version))
|
||||
|
||||
# XXX This should be converted to use commands.wrap, but since it's not
|
||||
# using privmsgs.*, I'm saving it for later.
|
||||
|
@ -501,6 +501,8 @@ class RichReplyMethods(object):
|
||||
return self._error(self.__makeReply(v, s), **kwargs)
|
||||
|
||||
def errorNoUser(self, s='', name='that user', **kwargs):
|
||||
if 'Raise' not in kwargs:
|
||||
kwargs['Raise'] = True
|
||||
v = self._getConfig(conf.supybot.replies.noUser)
|
||||
try:
|
||||
v = v % name
|
||||
|
@ -79,6 +79,12 @@ class UrlSnarfThread(world.SupyThread):
|
||||
super(UrlSnarfThread, self).__init__(*args, **kwargs)
|
||||
self.setDaemon(True)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
super(UrlSnarfThread, self).run()
|
||||
except webutils.WebError, e:
|
||||
log.debug('Exception in urlSnarfer: %s' % utils.exnToString(e))
|
||||
|
||||
class SnarfQueue(ircutils.FloodQueue):
|
||||
timeout = conf.supybot.snarfThrottle
|
||||
def key(self, channel):
|
||||
@ -134,11 +140,6 @@ def urlSnarfer(f):
|
||||
newf = utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||
return newf
|
||||
|
||||
decorators = ircutils.IrcDict({
|
||||
'thread': thread,
|
||||
'urlSnarfer': urlSnarfer,
|
||||
})
|
||||
|
||||
|
||||
###
|
||||
# Converters, which take irc, msg, args, and a state object, and build up the
|
||||
@ -756,26 +757,16 @@ class Spec(object):
|
||||
|
||||
# This is used below, but we need to rename it so its name isn't
|
||||
# shadowed by our locals.
|
||||
_decorators = decorators
|
||||
def wrap(f, specList=[], decorators=None, **kw):
|
||||
def wrap(f, specList=[], **kw):
|
||||
spec = Spec(specList, **kw)
|
||||
# XXX This is a hack, but it's just a workaround until I know the right way
|
||||
# to fix this problem.
|
||||
if decorators is not None and 'urlSnarfer' in decorators:
|
||||
kw['allowExtra'] = True
|
||||
def newf(self, irc, msg, args, **kwargs):
|
||||
state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log})
|
||||
f(self, irc, msg, args, *state.args, **state.kwargs)
|
||||
newf = utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||
if decorators is not None:
|
||||
decorators = map(_decorators.__getitem__, decorators)
|
||||
for decorator in decorators:
|
||||
newf = decorator(newf)
|
||||
return newf
|
||||
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||
|
||||
|
||||
__all__ = ['wrap', 'context', 'additional', 'optional', 'any', 'compose',
|
||||
'Spec', 'first',
|
||||
'Spec', 'first', 'urlSnarfer', 'thread',
|
||||
'many', 'getopts', 'getConverter', 'addConverter', 'callConverter']
|
||||
|
||||
if world.testing:
|
||||
|
Loading…
Reference in New Issue
Block a user