Networking module: add a !curl command to display a webpage; issue #4
This commit is contained in:
parent
418e6ba32a
commit
81db3de0df
@ -5,12 +5,15 @@ import json
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
from tools import web
|
||||||
|
|
||||||
nemubotversion = 3.3
|
nemubotversion = 3.3
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
from hooks import Hook
|
from hooks import Hook
|
||||||
add_hook("cmd_hook", Hook(cmd_traceurl, "traceurl"))
|
add_hook("cmd_hook", Hook(cmd_traceurl, "traceurl"))
|
||||||
add_hook("cmd_hook", Hook(cmd_isup, "isup"))
|
add_hook("cmd_hook", Hook(cmd_isup, "isup"))
|
||||||
|
add_hook("cmd_hook", Hook(cmd_curl, "curl"))
|
||||||
|
|
||||||
|
|
||||||
def help_tiny ():
|
def help_tiny ():
|
||||||
@ -20,6 +23,20 @@ def help_tiny ():
|
|||||||
def help_full ():
|
def help_full ():
|
||||||
return "!traceurl /url/: Follow redirections from /url/."
|
return "!traceurl /url/: Follow redirections from /url/."
|
||||||
|
|
||||||
|
def cmd_curl(msg):
|
||||||
|
if len(msg.cmds) > 1:
|
||||||
|
req = web.getURLContent(" ".join(msg.cmds[1:]))
|
||||||
|
if req is not None:
|
||||||
|
res = Response(msg.sender, channel=msg.channel)
|
||||||
|
for m in req.decode().split("\n"):
|
||||||
|
res.append_message(m)
|
||||||
|
return res
|
||||||
|
else:
|
||||||
|
return Response(msg.sender, "Une erreur est survenue lors de l'accès à cette URL", channel=msg.channel)
|
||||||
|
else:
|
||||||
|
return Response(msg.sender, "Veuillez indiquer une URL à visiter.",
|
||||||
|
channel=msg.channel)
|
||||||
|
|
||||||
def cmd_traceurl(msg):
|
def cmd_traceurl(msg):
|
||||||
if 1 < len(msg.cmds) < 6:
|
if 1 < len(msg.cmds) < 6:
|
||||||
res = list()
|
res = list()
|
||||||
|
Loading…
Reference in New Issue
Block a user