diff --git a/plugins/ShrinkUrl/__init__.py b/plugins/ShrinkUrl/__init__.py index 3cfd0eefc..031ddc421 100644 --- a/plugins/ShrinkUrl/__init__.py +++ b/plugins/ShrinkUrl/__init__.py @@ -40,7 +40,7 @@ __author__ = supybot.authors.jemfinch # This is a dictionary mapping supybot.Author instances to lists of # contributions. -__contributors__ = {} +__contributors__ = {supybot.authors.jamessan: ['xrl.us support']} import config import plugin diff --git a/plugins/ShrinkUrl/config.py b/plugins/ShrinkUrl/config.py index 82a9c7920..a8383f210 100644 --- a/plugins/ShrinkUrl/config.py +++ b/plugins/ShrinkUrl/config.py @@ -40,7 +40,7 @@ def configure(advanced): conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True) class ShrinkService(registry.OnlySomeStrings): - validStrings = ('ln', 'tiny') + validStrings = ('ln', 'tiny', 'xrl') ShrinkUrl = conf.registerPlugin('ShrinkUrl') conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer', diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index 605d3eade..22dba4c38 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -199,6 +199,35 @@ class ShrinkUrl(callbacks.PluginRegexp): irc.errorPossibleBug(str(e)) tiny = thread(wrap(tiny, ['url'])) + _xrlApi = 'http://metamark.net/api/rest/simple' + def _getXrlUrl(self, url): + quotedurl = utils.web.urlquote(url) + try: + return self.db.get('xrl', quotedurl) + except KeyError: + data = utils.web.urlencode({'long_url': url}) + text = utils.web.getUrl(self._xrlApi, data=data) + if text.startswith('ERROR:'): + raise ShrinkError, text[6:] + self.db.set('xrl', quotedurl, text) + return text + + def xrl(self, irc, msg, args, url): + """ + + Returns an xrl.us version of . + """ + if len(url) < 17: + irc.error('Stop being a lazy-biotch and type the URL yourself.') + return + try: + xrlurl = self._getXrlUrl(url) + m = irc.reply(xrlurl) + if m is not None: + m.tag('shrunken') + except ShrinkError, e: + irc.error(str(e)) + xrl = thread(wrap(xrl, ['url'])) Class = ShrinkUrl diff --git a/plugins/ShrinkUrl/test.py b/plugins/ShrinkUrl/test.py index b326119da..a358f782d 100644 --- a/plugins/ShrinkUrl/test.py +++ b/plugins/ShrinkUrl/test.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2002-2004, Jeremiah Fincher +# Copyright (c) 2009, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -96,6 +97,38 @@ class ShrinkUrlTestCase(ChannelPluginTestCase): finally: conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(False) + def testXrlurl(self): + try: + conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(False) + self.assertRegexp( + 'shrinkurl xrl http://sourceforge.net/tracker/?' + 'func=add&group_id=58965&atid=489447', + r'http://xrl.us/bfnyi6') + conf.supybot.plugins.ShrinkUrl.default.setValue('xrl') + conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True) + self.assertRegexp( + 'shrinkurl xrl http://sourceforge.net/tracker/?' + 'func=add&group_id=58965&atid=489447', + r'http://xrl.us/bfnyi6') + finally: + conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(False) + + def testXrlsnarf(self): + try: + conf.supybot.snarfThrottle.setValue(1) + conf.supybot.plugins.ShrinkUrl.default.setValue('xrl') + conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True) + self.assertSnarfRegexp( + 'http://sourceforge.net/tracker/?func=add&' + 'group_id=58965&atid=489447', + r'http://xrl.us/bfnyi6.* \(at') + self.assertSnarfRegexp( + 'http://www.urbandictionary.com/define.php?' + 'term=all+your+base+are+belong+to+us', + r'http://xrl.us/bfnyji.* \(at') + finally: + conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(False) + def testNonSnarfing(self): tiny = conf.supybot.plugins.ShrinkUrl.shrinkSnarfer() snarf = conf.supybot.plugins.ShrinkUrl.nonSnarfingRegexp()