Web: Add supybot.plugins.snarfMultipleUrls. Also, fix Web's test cases.

This commit is contained in:
Valentin Lorentz 2018-04-14 21:50:32 +02:00
parent f26f098d82
commit cd479717b8
3 changed files with 29 additions and 7 deletions

View File

@ -55,6 +55,9 @@ conf.registerChannelValue(Web, 'snarferReportIOExceptions',
conf.registerChannelValue(Web, 'snarferShowDomain',
registry.Boolean(True, _("""Determines whether domain names should be
displayed by the title snarfer.""")))
conf.registerChannelValue(Web, 'snarfMultipleUrls',
registry.Boolean(False, _("""Determines whether the title snarfer will
query all URLs in a message, or only the first one.""")))
conf.registerChannelValue(Web, 'snarferShowTargetDomain',
registry.Boolean(False, _("""Determines whether the domain name displayed
by the snarfer will be the original one (posted on IRC) or the target one

View File

@ -204,6 +204,9 @@ class Web(callbacks.PluginRegexp):
if self.registryValue('snarferShowDomain', channel):
s += format(_(' (at %s)'), domain)
irc.reply(s, prefixNick=False)
if self.registryValue('snarfMultipleUrls', channel):
# FIXME: hack
msg.tag('repliedTo', False)
titleSnarfer = urlSnarfer(titleSnarfer)
titleSnarfer.__doc__ = utils.web._httpUrlRe

View File

@ -83,16 +83,32 @@ class WebTestCase(ChannelPluginTestCase):
finally:
conf.supybot.plugins.Web.titleSnarfer.setValue(False)
def testMultipleTitleSnarfer(self):
try:
conf.supybot.plugins.Web.titleSnarfer.setValue(True)
conf.supybot.plugins.Web.snarfMultipleUrls.setValue(True)
self.feedMsg(
'https://microsoft.com/ https://google.com/')
m1 = self.getMsg(' ')
m2 = self.getMsg(' ')
self.assertTrue(('Microsoft' in m1.args[1]) ^
('Microsoft' in m2.args[1]))
self.assertTrue(('Google' in m1.args[1]) ^
('Google' in m2.args[1]))
finally:
conf.supybot.plugins.Web.titleSnarfer.setValue(False)
conf.supybot.plugins.Web.snarfMultipleUrls.setValue(False)
def testNonSnarfing(self):
snarf = conf.supybot.plugins.Web.nonSnarfingRegexp()
title = conf.supybot.plugins.Web.titleSnarfer()
try:
conf.supybot.plugins.Web.nonSnarfingRegexp.set('m/sf/')
conf.supybot.plugins.Web.nonSnarfingRegexp.set('m/fr/')
try:
conf.supybot.plugins.Web.titleSnarfer.setValue(True)
self.assertSnarfNoResponse('http://sf.net/', 2)
self.assertSnarfRegexp('http://www.sourceforge.net/',
r'Sourceforge\.net')
self.assertSnarfNoResponse('https://www.google.fr/', 2)
self.assertSnarfRegexp('https://www.google.com/',
r'Google')
finally:
conf.supybot.plugins.Web.titleSnarfer.setValue(title)
finally:
@ -116,10 +132,10 @@ class WebTestCase(ChannelPluginTestCase):
conf.supybot.plugins.Web.checkIgnored.setValue(False)
(oldprefix, self.prefix) = (self.prefix, 'foo!bar@baz')
try:
self.assertSnarfRegexp('https://google.com/', 'Google')
self.assertSnarfRegexp('https://google.it/', 'Google')
self.assertNotError('admin ignore add %s' % self.prefix)
self.assertSnarfRegexp('https://www.google.com/', 'Google')
self.assertNoResponse('title http://www.google.com/')
self.assertSnarfRegexp('https://www.google.it/', 'Google')
self.assertNoResponse('title http://www.google.it/')
finally:
conf.supybot.plugins.Web.titleSnarfer.setValue(False)
conf.supybot.plugins.Web.checkIgnored.setValue(True)