From 44015f2475d92e8f6ae2ce88f0fb7becfd9f7a2a Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 20 Jul 2022 05:24:05 +0200 Subject: [PATCH] better command parsing --- main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 94c64ab..19a441c 100644 --- a/main.py +++ b/main.py @@ -162,14 +162,22 @@ async def message_received(nick, target, message, **kwargs): async def handle_msg(nick, msg, target, now: float): global TASK_AUTHORS, TASK_QUEUE - if not msg.startswith("!dall "): + + def _err(target, err): + return bot.send("PRIVMSG", target=target, message=err) + + if "!dall" not in msg: return - msg = msg[6:].strip() + + spl = msg.split(' ') + if "!dall" not in spl[:2]: + return + + msg = msg[msg.find("!dall"):] + msg = msg[5:].strip() if len(msg) <= 8: - err = f"{nick}: longer query required." - bot.send("PRIVMSG", target=target, message=err) - return + return _err(target, f"longer query required.") TASK_AUTHORS.setdefault(nick, 0) if TASK_AUTHORS[nick] >= 3: