mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
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:
parent
200f716011
commit
9d66399420
@ -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
|
||||
|
@ -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',
|
||||
|
@ -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):
|
||||
"""<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
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user