mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
Reworked the togglesnarfer stuff
This commit is contained in:
parent
1e4879dfb1
commit
61576fdd13
@ -78,7 +78,8 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
regexps = ['gameknotSnarfer', 'gameknotStatsSnarfer']
|
regexps = ['gameknotSnarfer', 'gameknotStatsSnarfer']
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
self.snarfer = True
|
self.snarfers = {'game' : True,
|
||||||
|
'stat' : True}
|
||||||
|
|
||||||
_gkrating = re.compile(r'<font color="#FFFF33">(\d+)</font>')
|
_gkrating = re.compile(r'<font color="#FFFF33">(\d+)</font>')
|
||||||
_gkgames = re.compile(r's: </td><td class=sml>(\d+)</td></tr>')
|
_gkgames = re.compile(r's: </td><td class=sml>(\d+)</td></tr>')
|
||||||
@ -160,16 +161,41 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
irc.reply(msg, self.getStats(name))
|
irc.reply(msg, self.getStats(name))
|
||||||
|
|
||||||
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]
|
||||||
Disables the snarfer that responds to all Sourceforge Tracker links
|
elif state in self._enable:
|
||||||
"""
|
self.snarfers[snarfer] = True
|
||||||
self.snarfer = not self.snarfer
|
elif state in self._disable:
|
||||||
if self.snarfer:
|
self.snarfers[snarfer] = False
|
||||||
irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess)
|
resp = []
|
||||||
|
for k in self.snarfers:
|
||||||
|
if self.snarfers[k]:
|
||||||
|
resp.append('%s%s: On' % (k[0].upper(), k[1:]))
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess)
|
resp.append('%s%s: Off' % (k[0].upper(), k[1:]))
|
||||||
|
irc.reply(msg, '%s (%s)' % (conf.replySuccess, '; '.join(resp)))
|
||||||
|
|
||||||
|
_enable = ('on', 'enable')
|
||||||
|
_disable = ('off', 'disable')
|
||||||
|
def togglesnarfer(self, irc, msg, args):
|
||||||
|
"""<game|stat> [<on|off>]
|
||||||
|
|
||||||
|
Toggles the snarfer that responds to Gameknot game links or stat 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.
|
||||||
|
"""
|
||||||
|
(snarfer, state) = privmsgs.getArgs(args, optional=1)
|
||||||
|
snarfer = snarfer.lower()
|
||||||
|
state = state.lower()
|
||||||
|
if snarfer not in self.snarfers:
|
||||||
|
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')
|
togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin')
|
||||||
|
|
||||||
_gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<")
|
_gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<")
|
||||||
@ -179,7 +205,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
_gkReason = re.compile(r'won\s+\(\S+\s+(\S+)\)')
|
_gkReason = re.compile(r'won\s+\(\S+\s+(\S+)\)')
|
||||||
def gameknotSnarfer(self, irc, msg, match):
|
def gameknotSnarfer(self, irc, msg, match):
|
||||||
r"http://(?:www\.)?gameknot\.com/chess\.pl\?bd=\d+(&r=\d+)?"
|
r"http://(?:www\.)?gameknot\.com/chess\.pl\?bd=\d+(&r=\d+)?"
|
||||||
if not self.snarfer:
|
if not self.snarfers['stat']:
|
||||||
return
|
return
|
||||||
#debug.printf('Got a GK URL from %s' % msg.prefix)
|
#debug.printf('Got a GK URL from %s' % msg.prefix)
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
@ -232,7 +258,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
|
|
||||||
def gameknotStatsSnarfer(self, irc, msg, match):
|
def gameknotStatsSnarfer(self, irc, msg, match):
|
||||||
r"http://gameknot\.com/stats\.pl\?([^&]+)"
|
r"http://gameknot\.com/stats\.pl\?([^&]+)"
|
||||||
if not self.snarfer:
|
if not self.snarfer['game']:
|
||||||
return
|
return
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
s = self.getStats(name)
|
s = self.getStats(name)
|
||||||
|
@ -45,6 +45,7 @@ import urllib2
|
|||||||
import google
|
import google
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
|
import debug
|
||||||
import utils
|
import utils
|
||||||
import ircmsgs
|
import ircmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
@ -78,12 +79,19 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
onStart.append('alias googlelinux "google --restrict=linux $1"')
|
onStart.append('alias googlelinux "google --restrict=linux $1"')
|
||||||
onStart.append('alias googlebsd "google --restrict=bsd $1"')
|
onStart.append('alias googlebsd "google --restrict=bsd $1"')
|
||||||
onStart.append('alias googlemac "google --restrict=mac $1"')
|
onStart.append('alias googlemac "google --restrict=mac $1"')
|
||||||
|
if advanced:
|
||||||
print 'The Google plugin has the functionality to watch for URLs'
|
print 'The Google plugin has the functionality to watch for URLs'
|
||||||
print 'that match a specific pattern (we call this a snarfer). When'
|
print 'that match a specific pattern (we call this a snarfer).'
|
||||||
print 'supybot sees such a URL, he will parse the web page for'
|
print 'When supybot sees such a URL, he will parse the web page'
|
||||||
print 'information and reply with the results.\n'
|
print 'for information and reply with the results.\n'
|
||||||
if yn('Do you want the Google snarfer enabled by default?') == 'n':
|
print 'Google has two available snarfers: Google Groups link'
|
||||||
onStart.append('Google togglesnarfer')
|
print 'snarfing and a google search snarfer.\n'
|
||||||
|
if yn('Do you want the Google Groups link snarfer enabled by '\
|
||||||
|
'default?') == 'n':
|
||||||
|
onStart.append('Google togglesnarfer groups off')
|
||||||
|
if yn('Do you want the Google search snarfer enabled by default?')
|
||||||
|
== 'y':
|
||||||
|
onStart.append('Google togglesnarfer search on')
|
||||||
else:
|
else:
|
||||||
print 'You\'ll need to get a key before you can use this plugin.'
|
print 'You\'ll need to get a key before you can use this plugin.'
|
||||||
print 'You can apply for a key at http://www.google.com/apis/'
|
print 'You can apply for a key at http://www.google.com/apis/'
|
||||||
@ -134,7 +142,8 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
super(self.__class__, self).__init__()
|
super(self.__class__, self).__init__()
|
||||||
self.total = 0
|
self.total = 0
|
||||||
self.totalTime = 0
|
self.totalTime = 0
|
||||||
self.snarfer = True
|
self.snarfers = {'groups' : True,
|
||||||
|
'search' : False}
|
||||||
self.last24hours = structures.queue()
|
self.last24hours = structures.queue()
|
||||||
|
|
||||||
def formatData(self, data):
|
def formatData(self, data):
|
||||||
@ -165,16 +174,41 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
licensekey = privmsgs.checkCapability(licensekey, 'admin')
|
licensekey = privmsgs.checkCapability(licensekey, 'admin')
|
||||||
|
|
||||||
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]
|
||||||
Disables the snarfer that responds to all Sourceforge Tracker links
|
elif state in self._enable:
|
||||||
"""
|
self.snarfers[snarfer] = True
|
||||||
self.snarfer = not self.snarfer
|
elif state in self._disable:
|
||||||
if self.snarfer:
|
self.snarfers[snarfer] = False
|
||||||
irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess)
|
resp = []
|
||||||
|
for k in self.snarfers:
|
||||||
|
if self.snarfers[k]:
|
||||||
|
resp.append('%s%s: On' % (k[0].upper(), k[1:]))
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess)
|
resp.append('%s%s: Off' % (k[0].upper(), k[1:]))
|
||||||
|
irc.reply(msg, '%s (%s)' % (conf.replySuccess, '; '.join(resp)))
|
||||||
|
|
||||||
|
_enable = ('on', 'enable')
|
||||||
|
_disable = ('off', 'disable')
|
||||||
|
def togglesnarfer(self, irc, msg, args):
|
||||||
|
"""<groups|search> [<on|off>]
|
||||||
|
|
||||||
|
Toggles the snarfer that responds to Google Groups links or Google
|
||||||
|
searches. 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.
|
||||||
|
"""
|
||||||
|
(snarfer, state) = privmsgs.getArgs(args, optional=1)
|
||||||
|
snarfer = snarfer.lower()
|
||||||
|
state = state.lower()
|
||||||
|
if snarfer not in self.snarfers:
|
||||||
|
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')
|
togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin')
|
||||||
|
|
||||||
def google(self, irc, msg, args):
|
def google(self, irc, msg, args):
|
||||||
@ -278,7 +312,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
|
|
||||||
def googleSnarfer(self, irc, msg, match):
|
def googleSnarfer(self, irc, msg, match):
|
||||||
r"^google\s+(.*)$"
|
r"^google\s+(.*)$"
|
||||||
if not self.snarfer:
|
if not self.snarfers['search']:
|
||||||
return
|
return
|
||||||
searchString = match.group(1)
|
searchString = match.group(1)
|
||||||
try:
|
try:
|
||||||
@ -295,7 +329,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
_ggGroup = re.compile(r'Newsgroups: <a[^>]+>([^<]+)</a>')
|
_ggGroup = re.compile(r'Newsgroups: <a[^>]+>([^<]+)</a>')
|
||||||
def googleGroups(self, irc, msg, match):
|
def googleGroups(self, irc, msg, match):
|
||||||
r"http://groups.google.com/[^\s]+"
|
r"http://groups.google.com/[^\s]+"
|
||||||
if not self.snarfer:
|
if not self.snarfer['group']:
|
||||||
return
|
return
|
||||||
request = urllib2.Request(match.group(0), headers=\
|
request = urllib2.Request(match.group(0), headers=\
|
||||||
{'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'})
|
{'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'})
|
||||||
|
Loading…
Reference in New Issue
Block a user