mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Fix a few bugs with my ln-s.net addition
This commit is contained in:
parent
3900c9301e
commit
69aaabd152
@ -65,12 +65,13 @@ class ShrinkService(registry.OnlySomeStrings):
|
|||||||
validStrings = ('ln', 'tiny')
|
validStrings = ('ln', 'tiny')
|
||||||
|
|
||||||
conf.registerPlugin('ShrinkUrl')
|
conf.registerPlugin('ShrinkUrl')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.ShrinkUrl, 'tinyurlSnarfer',
|
conf.registerChannelValue(conf.supybot.plugins.ShrinkUrl, 'shrinkSnarfer',
|
||||||
registry.Boolean(False, """Determines whether the
|
registry.Boolean(False, """Determines whether the
|
||||||
tinyurl snarfer is enabled. This snarfer will watch for URLs in the
|
shrink snarfer is enabled. This snarfer will watch for URLs in the
|
||||||
channel, and if they're sufficiently long (as determined by
|
channel, and if they're sufficiently long (as determined by
|
||||||
supybot.plugins.ShrinkUrl.minimumLength) it will post a
|
supybot.plugins.ShrinkUrl.minimumLength) it will post a
|
||||||
smaller URL from tinyurl.com."""))
|
smaller URL from either ln-s.net or tinyurl.com, as denoted in
|
||||||
|
supybot.plugins.ShrinkUrl.default."""))
|
||||||
conf.registerChannelValue(conf.supybot.plugins.ShrinkUrl, 'minimumLength',
|
conf.registerChannelValue(conf.supybot.plugins.ShrinkUrl, 'minimumLength',
|
||||||
registry.PositiveInteger(48, """The minimum length a URL must be before
|
registry.PositiveInteger(48, """The minimum length a URL must be before
|
||||||
the bot will shrink it."""))
|
the bot will shrink it."""))
|
||||||
@ -106,15 +107,17 @@ class CdbShrunkenUrlDB(object):
|
|||||||
self.lnDb[url] = lnurl
|
self.lnDb[url] = lnurl
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.db.close()
|
self.tinyDb.close()
|
||||||
|
self.lnDb.close()
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.db.flush()
|
self.tinyDb.flush()
|
||||||
|
self.lnDb.flush()
|
||||||
|
|
||||||
ShrunkenUrlDB = plugins.DB('ShrinkUrl', {'cdb': CdbShrunkenUrlDB})
|
ShrunkenUrlDB = plugins.DB('ShrinkUrl', {'cdb': CdbShrunkenUrlDB})
|
||||||
|
|
||||||
class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
||||||
regexps = ['tinyurlSnarfer', 'lnSnarfer']
|
regexps = ['shrinkSnarfer']
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db = ShrunkenUrlDB()
|
self.db = ShrunkenUrlDB()
|
||||||
self.__parent = super(ShrinkUrl, self)
|
self.__parent = super(ShrinkUrl, self)
|
||||||
@ -183,7 +186,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
if m is None:
|
if m is None:
|
||||||
print irc, irc.__class__
|
print irc, irc.__class__
|
||||||
m.tag('shrunken')
|
m.tag('shrunken')
|
||||||
tinyurlSnarfer = wrap(tinyurlSnarfer, decorators=['urlSnarfer'])
|
shrinkSnarfer = wrap(shrinkSnarfer, decorators=['urlSnarfer'])
|
||||||
|
|
||||||
def _getLnUrl(self, url):
|
def _getLnUrl(self, url):
|
||||||
try:
|
try:
|
||||||
@ -192,11 +195,12 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
url = webutils.urlquote(url)
|
url = webutils.urlquote(url)
|
||||||
text = webutils.getUrl('http://ln-s.net/home/api.jsp?url=%s' % url)
|
text = webutils.getUrl('http://ln-s.net/home/api.jsp?url=%s' % url)
|
||||||
(code, lnurl) = text.split(None, 1)
|
(code, lnurl) = text.split(None, 1)
|
||||||
|
lnurl = lnurl.strip()
|
||||||
if code == '200':
|
if code == '200':
|
||||||
self.db.setLn(url, lnurl)
|
self.db.setLn(url, lnurl)
|
||||||
else:
|
else:
|
||||||
lnurl = None
|
lnurl = None
|
||||||
return lnurl
|
return (lnurl, code)
|
||||||
|
|
||||||
def ln(self, irc, msg, args, url):
|
def ln(self, irc, msg, args, url):
|
||||||
"""<url>
|
"""<url>
|
||||||
@ -208,9 +212,8 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
return
|
return
|
||||||
(lnurl, error) = self._getLnUrl(url)
|
(lnurl, error) = self._getLnUrl(url)
|
||||||
if lnurl is not None:
|
if lnurl is not None:
|
||||||
s = lnurl.strip()
|
|
||||||
domain = webutils.getDomain(url)
|
domain = webutils.getDomain(url)
|
||||||
m = irc.reply(s)
|
m = irc.reply(lnurl)
|
||||||
m.tag('shrunken')
|
m.tag('shrunken')
|
||||||
else:
|
else:
|
||||||
irc.error(error)
|
irc.error(error)
|
||||||
|
Loading…
Reference in New Issue
Block a user