* Corrected the gameknot Forums regex to not require the ("&r=\d+") part since

not all the URLs necessarily have it.
* Added the game title to the output as well (haven't done a ton of testing on
  the regex, but it worked on every game I tried it on)
This commit is contained in:
Daniel DiPaolo 2003-04-19 04:43:46 +00:00
parent c506306635
commit 99666246ed

View File

@ -76,8 +76,9 @@ class Forums(callbacks.PrivmsgRegexp):
_gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<")
_gkRating = re.compile(r": (\d+)[^:]+:<br>(\d+)[^,]+, (\d+)[^,]+, (\d+)")
_gkGameTitle = re.compile(r"<p><b>(.*?)\s*</b>&nbsp;\s*<span.*?>\(started")
def gameknot(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+)?"
#debug.printf('Got a GK URL from %s' % msg.prefix)
url = match.group(0)
fd = urllib2.urlopen(url)
@ -86,6 +87,8 @@ class Forums(callbacks.PrivmsgRegexp):
#debug.printf('Got the string.')
fd.close()
try:
gameTitle = self._gkGameTitle.search(s).groups()
gameTitle = ircutils.bold(gameTitle)
((wRating, wName), (bRating, bName)) = self._gkPlayer.findall(s)
wName = ircutils.bold(wName)
bName = ircutils.bold(bName)
@ -96,7 +99,8 @@ class Forums(callbacks.PrivmsgRegexp):
wStats = '%s; W-%s, L-%s, D-%s' % (wRating, wWins, wLosses, wDraws)
bStats = '%s; W-%s, L-%s, D-%s' % (bRating, bWins, bLosses, bDraws)
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
'%s (%s) vs. %s (%s) <%s>' % (wName,wStats,bName,bStats,url)))
'%s: %s (%s) vs. %s (%s) <%s>' % (
gameTitle, wName, wStats, bName, bStats, url)))
except ValueError:
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
'That doesn\'t appear to be a proper Gameknot game.'))