diff --git a/plugins/ShrinkUrl/config.py b/plugins/ShrinkUrl/config.py index c8ed07267..bb9c7338d 100644 --- a/plugins/ShrinkUrl/config.py +++ b/plugins/ShrinkUrl/config.py @@ -40,11 +40,11 @@ def configure(advanced): conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True) class ShrinkService(registry.OnlySomeStrings): - """Valid values include 'ln', 'tiny', 'xrl', 'goo', and 'x0'.""" - validStrings = ('ln', 'tiny', 'xrl', 'goo', 'x0') + """Valid values include 'ln', 'tiny', 'xrl', 'goo', 'ur1', and 'x0'.""" + validStrings = ('ln', 'tiny', 'xrl', 'goo', 'ur1', 'x0') 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 def __init__(self, *args, **kwargs): diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index 2e8d464f3..c09bb3b80 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -259,6 +259,35 @@ class ShrinkUrl(callbacks.PluginRegexp): irc.error(str(e)) goo = thread(wrap(goo, ['url'])) + _ur1Api = 'http://ur1.ca/' + _ur1Regexp = re.compile(r'') + 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): + """ + + Returns an ur1 version of . + """ + 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' def _getX0Url(self, url): try: diff --git a/plugins/ShrinkUrl/test.py b/plugins/ShrinkUrl/test.py index ffe18f2df..1b3a7aa40 100644 --- a/plugins/ShrinkUrl/test.py +++ b/plugins/ShrinkUrl/test.py @@ -45,6 +45,8 @@ class ShrinkUrlTestCase(ChannelPluginTestCase): (udUrl, r'http://xrl.us/bfnyji')], 'goo': [(sfUrl, r'http://goo.gl/3c59N'), (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'), (udUrl, r'http://x0.no/0l2k')] } @@ -102,6 +104,9 @@ class ShrinkUrlTestCase(ChannelPluginTestCase): def testGoosnarf(self): self._snarf('goo') + def testUr1snarf(self): + self._snarf('ur1') + def testX0snarf(self): self._snarf('x0')