Extend parsing to single quote and update auto_help with help command by command on demand

This commit is contained in:
Shadow15510 2023-06-11 23:51:29 +02:00
parent 637574f39d
commit e90c98a75f
3 changed files with 12 additions and 6 deletions

View File

@ -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")

View File

@ -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}")

View File

@ -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)]