From e90c98a75f8caa09812971ce8d69e421a2de8a4f Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Sun, 11 Jun 2023 23:51:29 +0200 Subject: [PATCH] Extend parsing to single quote and update auto_help with help command by command on demand --- glados_cmnds.py | 3 ++- irc_api/api.py | 13 +++++++++---- irc_api/irc.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/glados_cmnds.py b/glados_cmnds.py index bb0f974..1963f7b 100644 --- a/glados_cmnds.py +++ b/glados_cmnds.py @@ -10,10 +10,11 @@ def greetings_bye(bot, msg, *args): @api.channel("#glados") @api.on( event=lambda m: "bonjour glados" in m.text.lower(), - desc="Réagis au 'bonjour glados' uniquement si le message est envoyé depuis le channel"\ + desc="Réagis au 'bonjour glados' uniquement si le message est envoyé depuis le channel "\ "#glados." ) def greetings_hello(bot, msg, *args): + bot.send(msg.to, args) bot.send(msg.to, f"Oh un utilisateur sur #glados :o") diff --git a/irc_api/api.py b/irc_api/api.py index d969afc..5dda5d3 100644 --- a/irc_api/api.py +++ b/irc_api/api.py @@ -11,7 +11,7 @@ def command(name, desc=""): name=name, func=func, events=[lambda m: m.text.startswith(PREFIX + name)], - desc=desc + desc=desc, ) return decorator @@ -131,6 +131,11 @@ class Bot: @command("aide") def auto_help(bot, msg, *args): """Aide des commandes disponibles.""" - bot.irc.send(msg.to, f"Aide des commandes") - for cmnd in bot.irc.callbacks: - bot.irc.send(msg.to, f" – {cmnd.name} : {cmnd.desc}") + known_cmnds = {cmnd.name: cmnd for cmnd in bot.irc.callbacks} + if args and args[0] in known_cmnds.keys(): + bot.send(msg.to, f"Aide sur la commande : {args[0]}") + bot.send(msg.to, f" {known_cmnds[args[0]].desc}") + else: + bot.irc.send(msg.to, f"Aide des commandes") + for cmnd in bot.irc.callbacks: + bot.irc.send(msg.to, f" – {cmnd.name}") diff --git a/irc_api/irc.py b/irc_api/irc.py index 73b7a7d..75dc95b 100644 --- a/irc_api/irc.py +++ b/irc_api/irc.py @@ -235,5 +235,5 @@ class Message: def parse(message): - pattern = re.compile(r"((\"[\w\ \-]+\"\ *)|([\w\-]+\ *))") + pattern = re.compile(r"(((\"|\')[\w\ \-]+(\"|\')\ *)|([\w\'\-]+\ *))") return [match[0].strip("\" ").rstrip("\" ") for match in re.findall(pattern, message)]