mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
ShrinkUrl: Use getattr() to simplify use of the growing number of services.
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
ca917d3528
commit
c055b16ea8
@ -83,14 +83,11 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
for m in utils.web.httpUrlRe.finditer(text):
|
for m in utils.web.httpUrlRe.finditer(text):
|
||||||
url = m.group(1)
|
url = m.group(1)
|
||||||
if len(url) > self.registryValue('minimumLength', channel):
|
if len(url) > self.registryValue('minimumLength', channel):
|
||||||
cmd = self.registryValue('default', channel)
|
cmd = self.registryValue('default', channel).capitalize()
|
||||||
try:
|
try:
|
||||||
if cmd == 'ln':
|
shortUrl = getattr(self, '_get%sUrl' % cmd)(url)
|
||||||
(shortUrl, _) = self._getLnUrl(url)
|
|
||||||
elif cmd == 'tiny':
|
|
||||||
shortUrl = self._getTinyUrl(url)
|
|
||||||
text = text.replace(url, shortUrl)
|
text = text.replace(url, shortUrl)
|
||||||
except utils.web.Error:
|
except (utils.web.Error, AttributeError):
|
||||||
pass
|
pass
|
||||||
newMsg = ircmsgs.privmsg(channel, text, msg=msg)
|
newMsg = ircmsgs.privmsg(channel, text, msg=msg)
|
||||||
newMsg.tag('shrunken')
|
newMsg.tag('shrunken')
|
||||||
@ -117,14 +114,11 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
self.log.debug('Matched nonSnarfingRegexp: %u', url)
|
self.log.debug('Matched nonSnarfingRegexp: %u', url)
|
||||||
return
|
return
|
||||||
minlen = self.registryValue('minimumLength', channel)
|
minlen = self.registryValue('minimumLength', channel)
|
||||||
cmd = self.registryValue('default', channel)
|
cmd = self.registryValue('default', channel).capitalize()
|
||||||
if len(url) >= minlen:
|
if len(url) >= minlen:
|
||||||
shorturl = None
|
try:
|
||||||
if cmd == 'tiny':
|
shorturl = getattr(self, '_get%sUrl' % cmd)(url)
|
||||||
shorturl = self._getTinyUrl(url)
|
except (utils.web.Error, AttributeError):
|
||||||
elif cmd == 'ln':
|
|
||||||
(shorturl, _) = self._getLnUrl(url)
|
|
||||||
if shorturl is None:
|
|
||||||
self.log.info('Couldn\'t get shorturl for %u', url)
|
self.log.info('Couldn\'t get shorturl for %u', url)
|
||||||
return
|
return
|
||||||
if self.registryValue('shrinkSnarfer.showDomain', channel):
|
if self.registryValue('shrinkSnarfer.showDomain', channel):
|
||||||
@ -136,7 +130,8 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
else:
|
else:
|
||||||
s = format('%u%s', shorturl, domain)
|
s = format('%u%s', shorturl, domain)
|
||||||
m = irc.reply(s, prefixNick=False)
|
m = irc.reply(s, prefixNick=False)
|
||||||
m.tag('shrunken')
|
if m is not None:
|
||||||
|
m.tag('shrunken')
|
||||||
shrinkSnarfer = urlSnarfer(shrinkSnarfer)
|
shrinkSnarfer = urlSnarfer(shrinkSnarfer)
|
||||||
shrinkSnarfer.__doc__ = utils.web.httpUrlRe
|
shrinkSnarfer.__doc__ = utils.web.httpUrlRe
|
||||||
|
|
||||||
@ -165,7 +160,8 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
(lnurl, error) = self._getLnUrl(url)
|
(lnurl, error) = self._getLnUrl(url)
|
||||||
if lnurl is not None:
|
if lnurl is not None:
|
||||||
m = irc.reply(lnurl)
|
m = irc.reply(lnurl)
|
||||||
m.tag('shrunken')
|
if m is not None:
|
||||||
|
m.tag('shrunken')
|
||||||
else:
|
else:
|
||||||
irc.error(error)
|
irc.error(error)
|
||||||
ln = thread(wrap(ln, ['url']))
|
ln = thread(wrap(ln, ['url']))
|
||||||
|
Loading…
Reference in New Issue
Block a user