mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-18 16:12:42 +01:00
ShrinkUrl: Add ur1.ca support.
Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
parent
a8e3081b18
commit
caa36121a7
@ -40,11 +40,11 @@ def configure(advanced):
|
|||||||
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True)
|
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True)
|
||||||
|
|
||||||
class ShrinkService(registry.OnlySomeStrings):
|
class ShrinkService(registry.OnlySomeStrings):
|
||||||
"""Valid values include 'ln', 'tiny', 'xrl', 'goo', and 'x0'."""
|
"""Valid values include 'ln', 'tiny', 'xrl', 'goo', 'ur1', and 'x0'."""
|
||||||
validStrings = ('ln', 'tiny', 'xrl', 'goo', 'x0')
|
validStrings = ('ln', 'tiny', 'xrl', 'goo', 'ur1', 'x0')
|
||||||
|
|
||||||
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
||||||
"""Valid values include 'ln', 'tiny', 'xrl', 'goo', and 'x0'."""
|
"""Valid values include 'ln', 'tiny', 'xrl', 'goo', 'ur1', and 'x0'."""
|
||||||
Value = ShrinkService
|
Value = ShrinkService
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -259,6 +259,35 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
goo = thread(wrap(goo, ['url']))
|
goo = thread(wrap(goo, ['url']))
|
||||||
|
|
||||||
|
_ur1Api = 'http://ur1.ca/'
|
||||||
|
_ur1Regexp = re.compile(r'<a href="(?P<url>[^"]+)">')
|
||||||
|
def _getUr1Url(self, url):
|
||||||
|
try:
|
||||||
|
return self.db.get('ur1ca', utils.web.urlquote(url))
|
||||||
|
except KeyError:
|
||||||
|
parameters = utils.web.urlencode({'longurl': url})
|
||||||
|
response = utils.web.getUrl(self._ur1Api, data=parameters)
|
||||||
|
ur1ca = self._ur1Regexp.search(response.decode()).group('url')
|
||||||
|
if ur1ca > 0 :
|
||||||
|
self.db.set('ur1', url, ur1ca)
|
||||||
|
return ur1ca
|
||||||
|
else:
|
||||||
|
raise ShrinkError, text
|
||||||
|
|
||||||
|
def ur1(self, irc, msg, args, url):
|
||||||
|
"""<url>
|
||||||
|
|
||||||
|
Returns an ur1 version of <url>.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
ur1url = self._getUr1Url(url)
|
||||||
|
m = irc.reply(ur1url)
|
||||||
|
if m is not None:
|
||||||
|
m.tag('shrunken')
|
||||||
|
except ShrinkError, e:
|
||||||
|
irc.error(str(e))
|
||||||
|
ur1 = thread(wrap(ur1, ['url']))
|
||||||
|
|
||||||
_x0Api = 'http://api.x0.no/?%s'
|
_x0Api = 'http://api.x0.no/?%s'
|
||||||
def _getX0Url(self, url):
|
def _getX0Url(self, url):
|
||||||
try:
|
try:
|
||||||
|
@ -45,6 +45,8 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|||||||
(udUrl, r'http://xrl.us/bfnyji')],
|
(udUrl, r'http://xrl.us/bfnyji')],
|
||||||
'goo': [(sfUrl, r'http://goo.gl/3c59N'),
|
'goo': [(sfUrl, r'http://goo.gl/3c59N'),
|
||||||
(udUrl, r'http://goo.gl/ocTga')],
|
(udUrl, r'http://goo.gl/ocTga')],
|
||||||
|
'ur1': [(sfUrl, r'http://ur1.ca/9xl25'),
|
||||||
|
(udUrl, r'http://ur1.ca/9xl9k')],
|
||||||
'x0': [(sfUrl, r'http://x0.no/0l2j'),
|
'x0': [(sfUrl, r'http://x0.no/0l2j'),
|
||||||
(udUrl, r'http://x0.no/0l2k')]
|
(udUrl, r'http://x0.no/0l2k')]
|
||||||
}
|
}
|
||||||
@ -102,6 +104,9 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
|||||||
def testGoosnarf(self):
|
def testGoosnarf(self):
|
||||||
self._snarf('goo')
|
self._snarf('goo')
|
||||||
|
|
||||||
|
def testUr1snarf(self):
|
||||||
|
self._snarf('ur1')
|
||||||
|
|
||||||
def testX0snarf(self):
|
def testX0snarf(self):
|
||||||
self._snarf('x0')
|
self._snarf('x0')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user