Man module: display whatis by default, use english location instead of user one
This commit is contained in:
parent
dfa4c49d68
commit
b0d0b4a234
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
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_man, "man"))
|
add_hook("cmd_hook", Hook(cmd_man, "MAN"))
|
||||||
|
add_hook("cmd_hook", Hook(cmd_whatis, "man"))
|
||||||
|
|
||||||
def help_tiny ():
|
def help_tiny ():
|
||||||
"""Line inserted in the response to the command !help"""
|
"""Line inserted in the response to the command !help"""
|
||||||
@ -31,6 +33,7 @@ def cmd_man(msg):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
args.append(msg.cmds[1])
|
args.append(msg.cmds[1])
|
||||||
|
|
||||||
|
os.unsetenv("LANG")
|
||||||
res = Response(msg.sender, channel=msg.channel)
|
res = Response(msg.sender, channel=msg.channel)
|
||||||
with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
|
with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
|
||||||
for line in proc.stdout.read().split(b"\n"):
|
for line in proc.stdout.read().split(b"\n"):
|
||||||
@ -44,3 +47,20 @@ def cmd_man(msg):
|
|||||||
res.append_message("Il n'y a pas de page de manuel pour %s." % msg.cmds[1])
|
res.append_message("Il n'y a pas de page de manuel pour %s." % msg.cmds[1])
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def cmd_whatis(msg):
|
||||||
|
args = ["whatis", " ".join(msg.cmds[1:])]
|
||||||
|
|
||||||
|
res = Response(msg.sender, channel=msg.channel)
|
||||||
|
with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
|
||||||
|
for line in proc.stdout.read().split(b"\n"):
|
||||||
|
(line, n) = RGXP_s.subn(b'', line)
|
||||||
|
res.append_message(" ".join(line.decode().split()))
|
||||||
|
|
||||||
|
if len(res.messages) <= 0:
|
||||||
|
if num is not None:
|
||||||
|
res.append_message("Il n'y a pas d'entrée %s dans la section %d du manuel." % (msg.cmds[1], num))
|
||||||
|
else:
|
||||||
|
res.append_message("Il n'y a pas de page de manuel pour %s." % msg.cmds[1])
|
||||||
|
|
||||||
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user