mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
ShrinkUrl: Add support for x0.no
This commit is contained in:
parent
d8c13c1f21
commit
de4218b26e
@ -1,5 +1,6 @@
|
||||
###
|
||||
# Copyright (c) 2005, Jeremiah Fincher
|
||||
# Copyright (c) 2009, James Vega
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -28,7 +29,7 @@
|
||||
###
|
||||
|
||||
"""
|
||||
Shrinks URLs using tinyurl.com and ln-s.net.
|
||||
Shrinks URLs using various URL shrinking services.
|
||||
"""
|
||||
|
||||
import supybot
|
||||
@ -40,7 +41,8 @@ __author__ = supybot.authors.jemfinch
|
||||
|
||||
# This is a dictionary mapping supybot.Author instances to lists of
|
||||
# contributions.
|
||||
__contributors__ = {supybot.authors.jamessan: ['xrl.us support']}
|
||||
__contributors__ = {supybot.authors.jamessan: ['xrl.us support',
|
||||
'x0.no 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', 'xrl')
|
||||
validStrings = ('ln', 'tiny', 'xrl', 'x0')
|
||||
|
||||
ShrinkUrl = conf.registerPlugin('ShrinkUrl')
|
||||
conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer',
|
||||
|
@ -229,6 +229,34 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
||||
irc.error(str(e))
|
||||
xrl = thread(wrap(xrl, ['url']))
|
||||
|
||||
_x0Api = 'http://api.x0.no/?%s'
|
||||
def _getX0Url(self, url):
|
||||
try:
|
||||
return self.db.get('x0', url)
|
||||
except KeyError:
|
||||
text = utils.web.getUrl(self._x0Api % url)
|
||||
if text.startswith('ERROR:'):
|
||||
raise ShrinkError, text[6:]
|
||||
self.db.set('x0', url, text)
|
||||
return text
|
||||
|
||||
def x0(self, irc, msg, args, url):
|
||||
"""<url>
|
||||
|
||||
Returns an x0.no version of <url>.
|
||||
"""
|
||||
if len(url) < 17:
|
||||
irc.error('Stop being a lazy-biotch and type the URL yourself.')
|
||||
return
|
||||
try:
|
||||
x0url = self._getX0Url(url)
|
||||
m = irc.reply(x0url)
|
||||
if m is not None:
|
||||
m.tag('shrunken')
|
||||
except ShrinkError, e:
|
||||
irc.error(str(e))
|
||||
x0 = thread(wrap(x0, ['url']))
|
||||
|
||||
Class = ShrinkUrl
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -43,6 +43,8 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
||||
(udUrl, r'http://ln-s.net/2\$K')],
|
||||
'xrl': [(sfUrl, r'http://xrl.us/bfq8ik'),
|
||||
(udUrl, r'http://xrl.us/bfnyji')],
|
||||
'x0': [(sfUrl, r'http://x0.no/0l2j'),
|
||||
(udUrl, r'http://x0.no/0l2k')]
|
||||
}
|
||||
if network:
|
||||
def testShrink(self):
|
||||
@ -79,6 +81,9 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
|
||||
def testXrlsnarf(self):
|
||||
self._snarf('xrl')
|
||||
|
||||
def testX0snarf(self):
|
||||
self._snarf('x0')
|
||||
|
||||
def testNonSnarfing(self):
|
||||
shrink = conf.supybot.plugins.ShrinkUrl
|
||||
origService = shrink.default()
|
||||
|
Loading…
Reference in New Issue
Block a user