From 677a63a1c7bf00ccc9c25b91fc7a60332bbf5701 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 13 Mar 2003 07:14:33 +0000 Subject: [PATCH] *** empty log message *** --- plugins/Forums.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 plugins/Forums.py diff --git a/plugins/Forums.py b/plugins/Forums.py new file mode 100644 index 000000000..2f7fd07b8 --- /dev/null +++ b/plugins/Forums.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +from baseplugin import * + +import re +import urllib2 + +import ircmsgs +import ircutils +import callbacks + +htmlStripper = re.compile(r'<[^>]+>') +def stripHtml(s): + return htmlStripper.sub('', s) + +class Forums(callbacks.PrivmsgRegexp): + threaded = True + _ggThread = re.compile(r'from thread "(.*?)"') + _ggGroup = re.compile(r'Newsgroups: (.*?)') + def googlegroups(self, irc, msg, match): + r"http://groups.google.com/[^\s]+" + request = urllib2.Request(match.group(0), headers=\ + {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'}) + fd = urllib2.urlopen(request) + text = fd.read() + mThread = self._ggThread.search(text) + mGroup = self._ggGroup.search(text) + if mThread and mGroup: + irc.queueMsg(ircmsgs.privmsg(ircutils.reply(msg), + 'Google Groups: %s, %s' % (mGroup.group(1), mThread.group(1)))) + else: + irc.queueMsg(ircmsgs.privmsg(msg.args[0], + 'That doesn\'t appear to be a proper Google Groups page.')) + + gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<") + def gameknot(self, irc, msg, match): + r"http://gameknot.com/chess.pl?bd=\d+&r=\d+" + fd = urllib2.urlopen(match.group(0)) + s = fd.read() + try: + ((wRating, wName), (bRating, bName)) = self.gkPlayer.findall(s) + wRating = wRating.replace('
', ' ') + bRating = bRating.replace('
', ' ') + wRating = wRating.replace('Rating', 'Rating:') + bRating = bRating.replace('Rating', 'Rating:') + irc.queueMsg(ircmsgs.privmsg(msg.args[0], + '%s (%s) vs. %s (%s)' % (wName, wRating, bName, bRating))) + + except ValueError: + irc.queueMsg(ircmsgs.privmsg(msg.args[0], + 'That doesn\'t appear to be a proper Gameknot game.')) + + +Class = Forums