Avoid catchall DirectAsk
This commit is contained in:
parent
7ae7e381c3
commit
e83c4091bf
|
@ -14,9 +14,11 @@ from nemubot.tools.xmlparser.node import ModuleState
|
||||||
|
|
||||||
from more import Response
|
from more import Response
|
||||||
|
|
||||||
|
|
||||||
def help_full ():
|
def help_full ():
|
||||||
return "This module store a lot of events: ny, we, " + (", ".join(context.datas.index.keys())) + "\n!eventslist: gets list of timer\n!start /something/: launch a timer"
|
return "This module store a lot of events: ny, we, " + (", ".join(context.datas.index.keys())) + "\n!eventslist: gets list of timer\n!start /something/: launch a timer"
|
||||||
|
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
#Define the index
|
#Define the index
|
||||||
context.data.setIndex("name")
|
context.data.setIndex("name")
|
||||||
|
@ -35,6 +37,7 @@ def fini(d, strend):
|
||||||
context.data.delChild(context.data.index[strend["name"]])
|
context.data.delChild(context.data.index[strend["name"]])
|
||||||
context.save()
|
context.save()
|
||||||
|
|
||||||
|
|
||||||
@hook.command("goûter")
|
@hook.command("goûter")
|
||||||
def cmd_gouter(msg):
|
def cmd_gouter(msg):
|
||||||
ndate = datetime.now(timezone.utc)
|
ndate = datetime.now(timezone.utc)
|
||||||
|
@ -44,6 +47,7 @@ def cmd_gouter(msg):
|
||||||
"Nous avons %s de retard pour le goûter :("),
|
"Nous avons %s de retard pour le goûter :("),
|
||||||
channel=msg.channel)
|
channel=msg.channel)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("week-end")
|
@hook.command("week-end")
|
||||||
def cmd_we(msg):
|
def cmd_we(msg):
|
||||||
ndate = datetime.now(timezone.utc) + timedelta(5 - datetime.today().weekday())
|
ndate = datetime.now(timezone.utc) + timedelta(5 - datetime.today().weekday())
|
||||||
|
@ -53,6 +57,7 @@ def cmd_we(msg):
|
||||||
"Youhou, on est en week-end depuis %s."),
|
"Youhou, on est en week-end depuis %s."),
|
||||||
channel=msg.channel)
|
channel=msg.channel)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("start")
|
@hook.command("start")
|
||||||
def start_countdown(msg):
|
def start_countdown(msg):
|
||||||
"""!start /something/: launch a timer"""
|
"""!start /something/: launch a timer"""
|
||||||
|
@ -132,6 +137,7 @@ def start_countdown(msg):
|
||||||
msg.date.strftime("%A %d %B %Y à %H:%M:%S")),
|
msg.date.strftime("%A %d %B %Y à %H:%M:%S")),
|
||||||
nick=msg.frm)
|
nick=msg.frm)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("end")
|
@hook.command("end")
|
||||||
@hook.command("forceend")
|
@hook.command("forceend")
|
||||||
def end_countdown(msg):
|
def end_countdown(msg):
|
||||||
|
@ -151,6 +157,7 @@ def end_countdown(msg):
|
||||||
else:
|
else:
|
||||||
return Response("%s n'est pas un compteur connu."% (msg.args[0]), channel=msg.channel, nick=msg.nick)
|
return Response("%s n'est pas un compteur connu."% (msg.args[0]), channel=msg.channel, nick=msg.nick)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("eventslist")
|
@hook.command("eventslist")
|
||||||
def liste(msg):
|
def liste(msg):
|
||||||
"""!eventslist: gets list of timer"""
|
"""!eventslist: gets list of timer"""
|
||||||
|
@ -166,6 +173,7 @@ def liste(msg):
|
||||||
else:
|
else:
|
||||||
return Response("Compteurs connus : %s." % ", ".join(context.data.index.keys()), channel=msg.channel)
|
return Response("Compteurs connus : %s." % ", ".join(context.data.index.keys()), channel=msg.channel)
|
||||||
|
|
||||||
|
|
||||||
@hook.command(match=lambda msg: isinstance(msg, Command) and msg.cmd in context.data.index)
|
@hook.command(match=lambda msg: isinstance(msg, Command) and msg.cmd in context.data.index)
|
||||||
def parseanswer(msg):
|
def parseanswer(msg):
|
||||||
res = Response(channel=msg.channel)
|
res = Response(channel=msg.channel)
|
||||||
|
@ -183,11 +191,11 @@ def parseanswer(msg):
|
||||||
res.append_message(countdown_format(context.data.index[msg.cmd].getDate("start"), context.data.index[msg.cmd]["msg_before"], context.data.index[msg.cmd]["msg_after"]))
|
res.append_message(countdown_format(context.data.index[msg.cmd].getDate("start"), context.data.index[msg.cmd]["msg_before"], context.data.index[msg.cmd]["msg_after"]))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
RGXP_ask = re.compile(r"^.*((create|new)\s+(a|an|a\s*new|an\s*other)?\s*(events?|commande?)|(nouvel(le)?|ajoute|cr[ée]{1,3})\s+(un)?\s*([eé]v[ée]nements?|commande?)).*$", re.I)
|
RGXP_ask = re.compile(r"^.*((create|new)\s+(a|an|a\s*new|an\s*other)?\s*(events?|commande?)|(nouvel(le)?|ajoute|cr[ée]{1,3})\s+(un)?\s*([eé]v[ée]nements?|commande?)).*$", re.I)
|
||||||
|
|
||||||
@hook.ask()
|
@hook.ask(match=lambda msg: RGXP_ask.match(msg.text))
|
||||||
def parseask(msg):
|
def parseask(msg):
|
||||||
if RGXP_ask.match(msg.text) is not None:
|
|
||||||
name = re.match("^.*!([^ \"'@!]+).*$", msg.text)
|
name = re.match("^.*!([^ \"'@!]+).*$", msg.text)
|
||||||
if name is None:
|
if name is None:
|
||||||
raise IMException("il faut que tu attribues une commande à l'événement.")
|
raise IMException("il faut que tu attribues une commande à l'événement.")
|
||||||
|
@ -201,11 +209,11 @@ def parseask(msg):
|
||||||
raise IMException("la date de l'événement est invalide !")
|
raise IMException("la date de l'événement est invalide !")
|
||||||
|
|
||||||
if texts.group(1) is not None and (texts.group(1) == "après" or texts.group(1) == "apres" or texts.group(1) == "after"):
|
if texts.group(1) is not None and (texts.group(1) == "après" or texts.group(1) == "apres" or texts.group(1) == "after"):
|
||||||
msg_after = texts.group (2)
|
msg_after = texts.group(2)
|
||||||
msg_before = texts.group (5)
|
msg_before = texts.group(5)
|
||||||
if (texts.group(4) is not None and (texts.group(4) == "après" or texts.group(4) == "apres" or texts.group(4) == "after")) or texts.group(1) is None:
|
if (texts.group(4) is not None and (texts.group(4) == "après" or texts.group(4) == "apres" or texts.group(4) == "after")) or texts.group(1) is None:
|
||||||
msg_before = texts.group (2)
|
msg_before = texts.group(2)
|
||||||
msg_after = texts.group (5)
|
msg_after = texts.group(5)
|
||||||
|
|
||||||
if msg_before.find("%s") == -1 or msg_after.find("%s") == -1:
|
if msg_before.find("%s") == -1 or msg_after.find("%s") == -1:
|
||||||
raise IMException("Pour que l'événement soit valide, ajouter %s à"
|
raise IMException("Pour que l'événement soit valide, ajouter %s à"
|
||||||
|
@ -225,7 +233,7 @@ def parseask(msg):
|
||||||
return Response("Nouvel événement !%s ajouté avec succès." % name.group(1),
|
return Response("Nouvel événement !%s ajouté avec succès." % name.group(1),
|
||||||
channel=msg.channel)
|
channel=msg.channel)
|
||||||
|
|
||||||
elif texts is not None and texts.group (2) is not None:
|
elif texts is not None and texts.group(2) is not None:
|
||||||
evt = ModuleState("event")
|
evt = ModuleState("event")
|
||||||
evt["server"] = msg.server
|
evt["server"] = msg.server
|
||||||
evt["channel"] = msg.channel
|
evt["channel"] = msg.channel
|
||||||
|
|
|
@ -72,9 +72,11 @@ class Bot(threading.Thread):
|
||||||
|
|
||||||
import re
|
import re
|
||||||
def in_ping(msg):
|
def in_ping(msg):
|
||||||
if re.match("^ *(m[' ]?entends?[ -]+tu|h?ear me|do you copy|ping)", msg.message, re.I) is not None:
|
|
||||||
return msg.respond("pong")
|
return msg.respond("pong")
|
||||||
self.treater.hm.add_hook(nemubot.hooks.Message(in_ping), "in", "DirectAsk")
|
self.treater.hm.add_hook(nemubot.hooks.Message(in_ping,
|
||||||
|
match=lambda msg: re.match("^ *(m[' ]?entends?[ -]+tu|h?ear me|do you copy|ping)",
|
||||||
|
msg.message, re.I)),
|
||||||
|
"in", "DirectAsk")
|
||||||
|
|
||||||
def in_echo(msg):
|
def in_echo(msg):
|
||||||
from nemubot.message import Text
|
from nemubot.message import Text
|
||||||
|
|
Loading…
Reference in New Issue
Block a user