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