Removed privmsgs.urlSnarfer, now it exists only in commands.

This commit is contained in:
Jeremy Fincher 2004-09-30 10:04:22 +00:00
parent 1a6f9325dd
commit 9c2a9096d3
9 changed files with 19 additions and 75 deletions

View File

@ -48,6 +48,7 @@ from htmlentitydefs import entitydefs as entities
import supybot.conf as conf
import supybot.utils as utils
import supybot.plugins as plugins
from supybot.commands import wrap
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
@ -266,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 = privmsgs.urlSnarfer(bzSnarfer)
bzSnarfer = wrap(bzSnarfer, decorators=['urlSnarfer'])
def urlquery2bugslist(self, url, query):
"""Given a URL and query list for a CSV bug list, it'll return

View File

@ -43,6 +43,7 @@ import getopt
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
@ -129,7 +130,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 = privmsgs.urlSnarfer(ebaySnarfer)
ebaySnarfer = wrap(ebaySnarfer, decorators=['urlSnarfer'])
def _getResponse(self, url):
try:

View File

@ -42,6 +42,7 @@ import supybot.registry as registry
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.webutils as webutils
@ -222,7 +223,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
irc.errorPossibleBug(s)
except Exception, e:
irc.error(utils.exnToString(e))
gameknotSnarfer = privmsgs.urlSnarfer(gameknotSnarfer)
gameknotSnarfer = wrap(gameknotSnarfer, decorators=['urlSnarfer'])
def gameknotStatsSnarfer(self, irc, msg, match):
r"http://gameknot\.com/stats\.pl\?([^&]+)"
@ -231,7 +232,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
name = match.group(1)
s = self.getStats(name)
irc.reply(s, prefixName=False)
gameknotStatsSnarfer = privmsgs.urlSnarfer(gameknotStatsSnarfer)
gameknotStatsSnarfer = wrap(gameknotStatsSnarfer,decorators=['urlSnarfer'])
Class = Gameknot

View File

@ -51,6 +51,7 @@ from itertools import imap, ifilter
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.webutils as webutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
@ -109,7 +110,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 = privmsgs.urlSnarfer(geekSnarfer)
geekSnarfer = wrap(geekSnarfer, decorators=['urlSnarfer'])
def geekquote(self, irc, msg, args):
"""[<id>]

View File

@ -51,6 +51,7 @@ import supybot.registry as registry
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.ircmsgs as ircmsgs
import supybot.plugins as plugins
import supybot.ircutils as ircutils
@ -418,7 +419,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
if data.results:
url = data.results[0].URL
irc.reply(url, prefixName=False)
googleSnarfer = privmsgs.urlSnarfer(googleSnarfer)
googleSnarfer = wrap(googleSnarfer, decorators=['urlSnarfer'])
_ggThread = re.compile(r'<br>Subject: ([^<]+)<br>', re.I)
_ggGroup = re.compile(r'Newsgroups: (?:<a[^>]+>)?([^<]+)(?:</a>)?', re.I)
@ -451,7 +452,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
else:
irc.errorPossibleBug('That doesn\'t appear to be a proper '
'Google Groups page.')
googleGroups = privmsgs.urlSnarfer(googleGroups)
googleGroups = wrap(googleGroups, decorators=['urlSnarfer'])
_calcRe = re.compile(r'<td nowrap><font size=\+1><b>(.*?)</b>', re.I)
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)

View File

@ -57,6 +57,7 @@ finally:
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.webutils as webutils
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
@ -191,7 +192,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp):
resp.append('%s: %s' % self._bold(m.groups()))
if resp:
irc.reply('; '.join(resp), prefixName = False)
aspnRecipes = privmsgs.urlSnarfer(aspnRecipes)
aspnRecipes = wrap(aspnRecipes, decorators=['urlSnarfer'])
Class = Python

View File

@ -50,6 +50,7 @@ import supybot.utils as utils
import rssparser
import supybot.plugins as plugins
from supybot.commands import wrap
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
@ -509,7 +510,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
irc.reply(resp, prefixName=False)
except TrackerError, e:
self.log.warning(str(e))
sfSnarfer = privmsgs.urlSnarfer(sfSnarfer)
sfSnarfer = wrap(sfSnarfer, decorators=['urlSnarfer'])
Class = Sourceforge

View File

@ -48,9 +48,10 @@ import itertools
import supybot.dbi as dbi
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import wrap
import supybot.ircmsgs as ircmsgs
import supybot.webutils as webutils
import supybot.ircutils as ircutils
import supybot.webutils as webutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks
@ -145,7 +146,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 = privmsgs.urlSnarfer(titleSnarfer)
titleSnarfer = wrap(titleSnarfer, decorators=['urlSnarfer'])
def stats(self, irc, msg, args):
"""[<channel>]

View File

@ -156,70 +156,6 @@ def channel(f):
ff(irc, msg, args, *L, **kwargs)
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
class UrlSnarfThread(threading.Thread):
def __init__(self, *args, **kwargs):
assert 'url' in kwargs
kwargs['name'] = 'Thread #%s (for snarfing %s)' % \
(world.threadsSpawned, kwargs.pop('url'))
world.threadsSpawned += 1
threading.Thread.__init__(self, *args, **kwargs)
self.setDaemon(True)
class SnarfQueue(ircutils.FloodQueue):
timeout = conf.supybot.snarfThrottle
def key(self, channel):
return channel
_snarfed = SnarfQueue()
class SnarfIrc(object):
def __init__(self, irc, channel, url):
self.irc = irc
self.url = url
self.channel = channel
def __getattr__(self, attr):
return getattr(self.irc, attr)
def reply(self, *args, **kwargs):
_snarfed.enqueue(self.channel, self.url)
self.irc.reply(*args, **kwargs)
# This lock is used to serialize the calls to snarfers, so earlier snarfers are
# guaranteed to beat out later snarfers.
_snarfLock = threading.Lock()
def urlSnarfer(f):
"""Protects the snarfer from loops and whatnot."""
def newf(self, irc, msg, match, *L, **kwargs):
url = match.group(0)
channel = msg.args[0]
if not ircutils.isChannel(channel):
return
if ircdb.channels.getChannel(channel).lobotomized:
self.log.info('Not snarfing in %s: lobotomized.', channel)
return
if _snarfed.has(channel, url):
self.log.info('Throttling snarf of %s in %s.', url, channel)
return
irc = SnarfIrc(irc, channel, url)
def doSnarf():
_snarfLock.acquire()
try:
if msg.repliedTo:
self.log.debug('Not snarfing, msg is already repliedTo.')
return
f(self, irc, msg, match, *L, **kwargs)
finally:
_snarfLock.release()
if threading.currentThread() is not world.mainThread:
doSnarf()
else:
L = list(L)
t = UrlSnarfThread(target=doSnarf, url=url)
t.start()
newf = utils.changeFunctionName(newf, f.func_name, f.__doc__)
return newf
class CapabilityCheckingPrivmsg(callbacks.Privmsg):
"""A small subclass of callbacks.Privmsg that checks self.capability
before allowing any command to be called.