Reworked the togglesnarfer mechanism

This commit is contained in:
James Vega 2003-10-27 22:57:05 +00:00
parent 8ff643d540
commit 1e4879dfb1
2 changed files with 87 additions and 33 deletions

View File

@ -84,12 +84,13 @@ class BugError(Exception):
def configure(onStart, afterConnect, advanced): def configure(onStart, afterConnect, advanced):
from questions import expect, anything, yn from questions import expect, anything, yn
onStart.append('load Bugzilla') onStart.append('load Bugzilla')
print 'The Bugzilla plugin has the functionality to watch for URLs' if advanced:
print 'that match a specific pattern (we call this a snarfer). When' print 'The Bugzilla plugin has the functionality to watch for URLs'
print 'supybot sees such a URL, he will parse the web page for information' print 'that match a specific pattern (we call this a snarfer). When'
print 'and reply with the results.\n' print 'supybot sees such a URL, he will parse the web page for'
if yn('Do you want the Bugzilla snarfer enabled by default?') == 'n': print 'information and reply with the results.\n'
onStart.append('Bugzilla togglesnarfer') if yn('Do you want the Bugzilla snarfer enabled by default?') == 'n':
onStart.append('Bugzilla togglesnarfer bug off')
class Bugzilla(callbacks.PrivmsgCommandAndRegexp): class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
"""Show a link to a bug report with a brief description""" """Show a link to a bug report with a brief description"""
@ -99,23 +100,49 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
callbacks.PrivmsgCommandAndRegexp.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self)
self.entre = re.compile('&(\S*?);') self.entre = re.compile('&(\S*?);')
self.db = makeDb(dbfilename) self.db = makeDb(dbfilename)
self.snarfer = True self.snarfers = {'bug' : True}
def die(self): def die(self):
self.db.close() self.db.close()
del self.db del self.db
def togglesnarfer(self, irc, msg, args): def _toggleHelper(self, irc, msg, state, snarfer):
"""takes no argument if not state:
self.snarfers[snarfer] = not self.snarfers[snarfer]
elif state in self._enable:
self.snarfers[snarfer] = True
elif state in self._disable:
self.snarfers[snarfer] = False
resp = []
for k in self.snarfers:
if self.snarfers[k]:
resp.append('%s%s: On' % (k[0].upper(), k[1:]))
else:
resp.append('%s%s: Off' % (k[0].upper(), k[1:]))
irc.reply(msg, '%s (%s)' % (conf.replySuccess, '; '.join(resp)))
Disables the snarfer that responds to all Bugzilla links _enable = ('on', 'enable')
_disable = ('off', 'disable')
def togglesnarfer(self, irc, msg, args):
"""<bug> [<on|off>]
Toggles the snarfer that responds to Bugzilla-style bug links. If
nothing is specified, all snarfers will have their states
toggled (on -> off, off -> on). If only a state is specified, all
snarfers will have their state set to the specified state. If a
specific snarfer is specified, the changes will apply only to that
snarfer.
""" """
self.snarfer = not self.snarfer (snarfer, state) = privmsgs.getArgs(args, optional=1)
if self.snarfer: snarfer = snarfer.lower()
irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess) state = state.lower()
else: if snarfer not in self.snarfers:
irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess) raise callbacks.ArgumentError
togglesnarfer=privmsgs.checkCapability(togglesnarfer,'admin') if state and state not in self._enable and state not in self._disable:
raise callbacks.ArgumentError
self._toggleHelper(irc, msg, state, snarfer)
togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin')
def addzilla(self, irc, msg, args): def addzilla(self, irc, msg, args):
"""shorthand url description """shorthand url description
Add a bugzilla to the list of defined bugzillae. Add a bugzilla to the list of defined bugzillae.
@ -176,7 +203,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
return return
def bzSnarfer(self, irc, msg, match): def bzSnarfer(self, irc, msg, match):
r"(.*)/show_bug.cgi\?id=([0-9]+)" r"(.*)/show_bug.cgi\?id=([0-9]+)"
if not self.snarfer: if not self.snarfers['bug']:
return return
queryurl = '%s/xml.cgi?id=%s' % (match.group(1), match.group(2)) queryurl = '%s/xml.cgi?id=%s' % (match.group(1), match.group(2))
try: try:

View File

@ -55,12 +55,13 @@ def configure(onStart, afterConnect, advanced):
# commands you would like to be run when the bot has finished connecting. # commands you would like to be run when the bot has finished connecting.
from questions import expect, anything, something, yn from questions import expect, anything, something, yn
onStart.append('load Ebay') onStart.append('load Ebay')
print 'The Ebay plugin has the functionality to watch for URLs' if advanced:
print 'that match a specific pattern (we call this a snarfer). When' print 'The Ebay plugin has the functionality to watch for URLs'
print 'supybot sees such a URL, he will parse the web page for information' print 'that match a specific pattern (we call this a snarfer). When'
print 'and reply with the results.\n' print 'supybot sees such a URL, he will parse the web page for'
if yn('Do you want the Ebay snarfer enabled by default?') == 'n': print 'information and reply with the results.\n'
onStart.append('Ebay togglesnarfer') if yn('Do you want the Ebay snarfer enabled by default?') == 'n':
onStart.append('Ebay togglesnarfer auction off')
example = utils.wrapLines(""" example = utils.wrapLines("""
Add an example IRC session using this module here. Add an example IRC session using this module here.
@ -75,7 +76,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp):
regexps = ['ebaySnarfer'] regexps = ['ebaySnarfer']
def __init__(self): def __init__(self):
callbacks.PrivmsgCommandAndRegexp.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self)
self.snarfer = True self.snarfers = {'auction' : True}
_reopts = re.I | re.S _reopts = re.I | re.S
_info = re.compile(r'<title>eBay item (\d+) \([^)]+\) - ([^<]+)</title>', _info = re.compile(r'<title>eBay item (\d+) \([^)]+\) - ([^<]+)</title>',
@ -114,16 +115,42 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp):
_getSeller = lambda self, s: '%s: %s (%s)' % (ircutils.bold('Seller'), _getSeller = lambda self, s: '%s: %s (%s)' % (ircutils.bold('Seller'),
self._seller.search(s).group(1), self._seller.search(s).group(2)) self._seller.search(s).group(1), self._seller.search(s).group(2))
def togglesnarfer(self, irc, msg, args): def _toggleHelper(self, irc, msg, state, snarfer):
"""takes no argument if not state:
self.snarfers[snarfer] = not self.snarfers[snarfer]
elif state in self._enable:
self.snarfers[snarfer] = True
elif state in self._disable:
self.snarfers[snarfer] = False
resp = []
for k in self.snarfers:
if self.snarfers[k]:
resp.append('%s%s: On' % (k[0].upper(), k[1:]))
else:
resp.append('%s%s: Off' % (k[0].upper(), k[1:]))
irc.reply(msg, '%s (%s)' % (conf.replySuccess, '; '.join(resp)))
Disables the snarfer that responds to all Sourceforge Tracker links _enable = ('on', 'enable')
_disable = ('off', 'disable')
def togglesnarfer(self, irc, msg, args):
"""<auction> [<on|off>]
Toggles the snarfer that responds to eBay auction links. If
nothing is specified, all snarfers will have their states
toggled (on -> off, off -> on). If only a state is specified, all
snarfers will have their state set to the specified state. If a
specific snarfer is specified, the changes will apply only to that
snarfer.
""" """
self.snarfer = not self.snarfer (snarfer, state) = privmsgs.getArgs(args, optional=1)
if self.snarfer: snarfer = snarfer.lower()
irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess) state = state.lower()
else: if snarfer not in self.snarfers:
irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess) raise callbacks.ArgumentError
if state and state not in self._enable and state not in self._disable:
raise callbacks.ArgumentError
self._toggleHelper(irc, msg, state, snarfer)
togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin')
def ebay(self, irc, msg, args): def ebay(self, irc, msg, args):
"""[--link] <item> """[--link] <item>
@ -147,7 +174,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp):
def ebaySnarfer(self, irc, msg, match): def ebaySnarfer(self, irc, msg, match):
r"http://cgi\.ebay\.com/ws/eBayISAPI\.dll\?ViewItem(?:&item=\d+|"\ r"http://cgi\.ebay\.com/ws/eBayISAPI\.dll\?ViewItem(?:&item=\d+|"\
"&category=\d+)+" "&category=\d+)+"
if not self.snarfer: if not self.snarfers['auction']:
return return
url = match.group(0) url = match.group(0)
self._getResponse(irc, msg, url, snarf = True) self._getResponse(irc, msg, url, snarf = True)