[networking] Add !title command to display the title of a page
This commit is contained in:
parent
e837f9c8e5
commit
ec9481e65b
1 changed files with 15 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
"""Various network tools (w3m, w3c validator, curl, traceurl, ...)"""
|
"""Various network tools (w3m, w3c validator, curl, traceurl, ...)"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from nemubot.exception import IRCException
|
from nemubot.exception import IRCException
|
||||||
from nemubot.hooks import hook
|
from nemubot.hooks import hook
|
||||||
|
|
@ -37,6 +38,20 @@ def help_full():
|
||||||
return "!traceurl /url/: Follow redirections from /url/."
|
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")
|
@hook("cmd_hook", "curly")
|
||||||
def cmd_curly(msg):
|
def cmd_curly(msg):
|
||||||
if not len(msg.args):
|
if not len(msg.args):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue