mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-18 16:12:42 +01:00
ShrinkUrl plugin, add BitLy support.
Login+ApiKey required for it to function.
This commit is contained in:
parent
7c4a28d7fd
commit
147cccdf6c
@ -42,11 +42,11 @@ 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):
|
||||||
"""Valid values include 'tiny', 'ur1', and 'x0'."""
|
"""Valid values include 'tiny', 'ur1', 'x0', and 'bitly'."""
|
||||||
validStrings = ('tiny', 'ur1', 'x0')
|
validStrings = ('tiny', 'ur1', 'x0', 'bitly')
|
||||||
|
|
||||||
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
|
||||||
"""Valid values include 'ln', 'tiny', 'ur1', and 'x0'."""
|
"""Valid values include 'ln', 'tiny', 'ur1', 'x0', and 'bitly'."""
|
||||||
Value = ShrinkService
|
Value = ShrinkService
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -97,4 +97,13 @@ conf.registerChannelValue(ShrinkUrl, 'serviceRotation',
|
|||||||
ShrinkCycle([], _("""If set to a non-empty value, specifies the list of
|
ShrinkCycle([], _("""If set to a non-empty value, specifies the list of
|
||||||
services to rotate through for the shrinkSnarfer and outFilter.""")))
|
services to rotate through for the shrinkSnarfer and outFilter.""")))
|
||||||
|
|
||||||
|
conf.registerGroup(ShrinkUrl, 'bitly')
|
||||||
|
conf.registerGlobalValue(ShrinkUrl.bitly, 'login',
|
||||||
|
registry.String('', _("""Determines the API Login string used for
|
||||||
|
shortening using the Bit.ly service."""), private=True))
|
||||||
|
conf.registerGlobalValue(ShrinkUrl.bitly, 'apiKey',
|
||||||
|
registry.String('', _("""Determines the API Key string used for
|
||||||
|
shortening using the Bit.ly service."""), private=True))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -255,6 +255,39 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
x0 = thread(wrap(x0, ['httpUrl']))
|
x0 = thread(wrap(x0, ['httpUrl']))
|
||||||
|
|
||||||
|
_bitlyApi = 'http://api.bit.ly/shorten?format=txt&login=%s&apiKey=%s&longUrl=%s'
|
||||||
|
@retry
|
||||||
|
def _getbitlyUrl(self, url):
|
||||||
|
try:
|
||||||
|
return self.db.get('bitly', url)
|
||||||
|
except KeyError:
|
||||||
|
text = utils.web.getUrl(self._bitlyApi %
|
||||||
|
(self.registryValue('bitly.login'),
|
||||||
|
self.registryValue('bitly.apiKey'),
|
||||||
|
url)).decode()
|
||||||
|
if not text.startswith('http'):
|
||||||
|
raise ShrinkError(text)
|
||||||
|
self.db.set('bitly', url, text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
@internationalizeDocstring
|
||||||
|
def bitly(self, irc, msg, args, url):
|
||||||
|
"""<url>
|
||||||
|
|
||||||
|
Returns an bitly version of <url>.
|
||||||
|
"""
|
||||||
|
if not (self.registryValue('bitly.login') or
|
||||||
|
self.registryValue('bitly.apiKey')):
|
||||||
|
irc.error(_("""Bit.ly Requested but login and apiKey are empty."""))
|
||||||
|
try:
|
||||||
|
bitlyurl = self._getbitlyUrl(url)
|
||||||
|
m = irc.reply(bitlyurl)
|
||||||
|
if m is not None:
|
||||||
|
m.tag('shrunken')
|
||||||
|
except ShrinkError as e:
|
||||||
|
irc.error(str(e))
|
||||||
|
bitly = thread(wrap(bitly, ['httpUrl']))
|
||||||
|
|
||||||
@retry
|
@retry
|
||||||
def _getExpandUrl(self, url):
|
def _getExpandUrl(self, url):
|
||||||
url = utils.web.urlquote(url)
|
url = utils.web.urlquote(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user