mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Updated calc.
This commit is contained in:
parent
06afd9ff3d
commit
d86ebf4e7f
@ -408,6 +408,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
googleGroups = privmsgs.urlSnarfer(googleGroups)
|
||||
|
||||
_calcRe = re.compile(r'<td nowrap><font size=\+1><b>(.*?)</b>', re.I)
|
||||
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)
|
||||
_calcFontRe = re.compile(r'<font size=-2>(.*?)</font>')
|
||||
_calcTimesRe = re.compile(r'×')
|
||||
def calc(self, irc, msg, args):
|
||||
"""<expression>
|
||||
|
||||
@ -420,7 +423,11 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
html = webutils.getUrl(url)
|
||||
match = self._calcRe.search(html)
|
||||
if match is not None:
|
||||
irc.reply(match.group(1))
|
||||
s = match.group(1)
|
||||
s = self._calcSupRe.sub(r'^(\1)', s)
|
||||
s = self._calcFontRe.sub(r' , ', s)
|
||||
s = self._calcTimesRe.sub(r' * ', s)
|
||||
irc.reply(s)
|
||||
else:
|
||||
irc.reply('Google\'s calculator didn\'t come up with anything.')
|
||||
|
||||
|
@ -34,6 +34,16 @@ from testsupport import *
|
||||
class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
plugins = ('Google',)
|
||||
if network:
|
||||
def testCalc(self):
|
||||
self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t')
|
||||
self.assertNotRegexp('google calc '
|
||||
'the speed of light '
|
||||
'in microns / fortnight', '<sup>')
|
||||
self.assertNotRegexp('google calc '
|
||||
'the speed of light '
|
||||
'in microns / fortnight', '×')
|
||||
|
||||
|
||||
def testNoNoLicenseKeyError(self):
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
|
||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
||||
|
Loading…
Reference in New Issue
Block a user