Fix bug in title.py (and convert spaces to tabs), thanks @rubenwardy
parent
fa55206611
commit
d9318b8f53
49
title.py
49
title.py
|
@ -10,37 +10,38 @@ import web
|
||||||
r_title = re.compile(r'(?ims)<\s*title[^>]*>(.*?)<\s*/\s*title\s*>')
|
r_title = re.compile(r'(?ims)<\s*title[^>]*>(.*?)<\s*/\s*title\s*>')
|
||||||
|
|
||||||
def title(phenny, input):
|
def title(phenny, input):
|
||||||
uri = input.group(2).strip()
|
uri = input.group(2)
|
||||||
if uri:
|
if uri:
|
||||||
pass
|
pass
|
||||||
elif hasattr(phenny.bot, 'last_seen_uri'):
|
elif hasattr(phenny.bot, 'last_seen_uri'):
|
||||||
uri = phenny.bot.last_seen_uri
|
uri = phenny.bot.last_seen_uri
|
||||||
else:
|
else:
|
||||||
return phenny.reply("Give me an URI..")
|
return phenny.reply("Give me an URI..")
|
||||||
data, sc = web.get(uri, 4096)
|
uri = uri.strip()
|
||||||
if sc != 200:
|
data, sc = web.get(uri, 4096)
|
||||||
return phenny.say("HTTP error %d" % sc)
|
if sc != 200:
|
||||||
try:
|
return phenny.say("HTTP error %d" % sc)
|
||||||
data = str(data, 'utf-8')
|
try:
|
||||||
except UnicodeDecodeError:
|
data = str(data, 'utf-8')
|
||||||
return phenny.say("Doesn't seem to be HTML..")
|
except UnicodeDecodeError:
|
||||||
m = re.search(r_title, data)
|
return phenny.say("Doesn't seem to be HTML..")
|
||||||
if not m:
|
m = re.search(r_title, data)
|
||||||
return phenny.say("No title found.")
|
if not m:
|
||||||
title = m.group(1).strip()
|
return phenny.say("No title found.")
|
||||||
if len(title) > 75:
|
title = m.group(1).strip()
|
||||||
title = title[:75] + "[...]"
|
if len(title) > 75:
|
||||||
phenny.reply(title)
|
title = title[:75] + "[...]"
|
||||||
|
phenny.reply(title)
|
||||||
|
|
||||||
title.commands = ['title']
|
title.commands = ['title']
|
||||||
|
|
||||||
def noteuri(phenny, input):
|
def noteuri(phenny, input):
|
||||||
uri = input.group(1)
|
uri = input.group(1)
|
||||||
phenny.bot.last_seen_uri = uri
|
phenny.bot.last_seen_uri = uri
|
||||||
|
|
||||||
noteuri.rule = r'(https?://[^<> "\x01]+)'
|
noteuri.rule = r'(https?://[^<> "\x01]+)'
|
||||||
noteuri.priority = 'low'
|
noteuri.priority = 'low'
|
||||||
noteuri.nohook = True
|
noteuri.nohook = True
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(__doc__.strip())
|
print(__doc__.strip())
|
||||||
|
|
Loading…
Reference in New Issue