ShrinkUrl: Add support for xrl.us

Closes one part of Debian #539858

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2009-10-04 21:06:48 -04:00
parent 200f716011
commit 9d66399420
4 changed files with 64 additions and 2 deletions

View File

@ -40,7 +40,7 @@ __author__ = supybot.authors.jemfinch
# This is a dictionary mapping supybot.Author instances to lists of # This is a dictionary mapping supybot.Author instances to lists of
# contributions. # contributions.
__contributors__ = {} __contributors__ = {supybot.authors.jamessan: ['xrl.us support']}
import config import config
import plugin import plugin

View File

@ -40,7 +40,7 @@ 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):
validStrings = ('ln', 'tiny') validStrings = ('ln', 'tiny', 'xrl')
ShrinkUrl = conf.registerPlugin('ShrinkUrl') ShrinkUrl = conf.registerPlugin('ShrinkUrl')
conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer', conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer',

View File

@ -199,6 +199,35 @@ class ShrinkUrl(callbacks.PluginRegexp):
irc.errorPossibleBug(str(e)) irc.errorPossibleBug(str(e))
tiny = thread(wrap(tiny, ['url'])) 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):
"""<url>
Returns an xrl.us version of <url>.
"""
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 Class = ShrinkUrl

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2002-2004, Jeremiah Fincher # Copyright (c) 2002-2004, Jeremiah Fincher
# Copyright (c) 2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -96,6 +97,38 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
finally: finally:
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(False) 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): def testNonSnarfing(self):
tiny = conf.supybot.plugins.ShrinkUrl.shrinkSnarfer() tiny = conf.supybot.plugins.ShrinkUrl.shrinkSnarfer()
snarf = conf.supybot.plugins.ShrinkUrl.nonSnarfingRegexp() snarf = conf.supybot.plugins.ShrinkUrl.nonSnarfingRegexp()