diff --git a/modules/networking/__init__.py b/modules/networking/__init__.py index 670c423..188dbb5 100644 --- a/modules/networking/__init__.py +++ b/modules/networking/__init__.py @@ -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("(.*?)", 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):