[networking] Add !title command to display the title of a page

This commit is contained in:
nemunaire 2015-09-07 19:07:43 +02:00
commit ec9481e65b

View file

@ -3,6 +3,7 @@
"""Various network tools (w3m, w3c validator, curl, traceurl, ...)"""
import logging
import re
from nemubot.exception import IRCException
from nemubot.hooks import hook
@ -37,6 +38,20 @@ def help_full():
return "!traceurl /url/: Follow redirections from /url/."
@hook("cmd_hook", "title")
def cmd_title(msg):
if not len(msg.args):
raise IRCException("Indicate the URL to visit.")
url = " ".join(msg.args)
res = re.search("<title>(.*?)</title>", page.fetch(" ".join(msg.args)), re.DOTALL)
if res is None:
raise IRCException("The page %s has no title" % url)
else:
return Response("%s: %s" % (url, res.group(1).replace("\n", " ")), channel=msg.channel)
@hook("cmd_hook", "curly")
def cmd_curly(msg):
if not len(msg.args):