Minor changes

This commit is contained in:
Shadow15510 2023-06-12 16:56:17 +02:00
parent 772b3387f6
commit 2643e7e944
2 changed files with 20 additions and 10 deletions

View File

@ -14,18 +14,18 @@ def greetings_hello(bot, msg):
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
@api.on(lambda m: isinstance(re.match(r"(.*)(au revoir|à plus|a\+|à toute|bye|see you|see you soon) glados(.*)", m.text, re.IGNORECASE), re.Match))
@api.on(lambda m: isinstance(re.match(r"(.*)(au revoir|(à|a) plus|a\+|(à|a) toute|@\+|bye|see you|see you soon) glados(.*)", m.text, re.IGNORECASE), re.Match))
def greetings_bye(bot, msg):
"""Dit au revoir à l'utilisateur."""
greetings = ("Au revoir", "À plus", "À toute", "Bye bye", "See you soon")
greetings = ("Au revoir,", "À plus,", "Bye bye,", "See you soon,", "Bye,")
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
@api.on(lambda m: isinstance(re.match(r"(.*)(merci|merci beaucoup|thx|thanks|thank you) glados(.*)", m.text, re.IGNORECASE), re.Match))
def thanks(bot, msg):
"""Répond aux remerciements de l'utilisateur."""
thanks_choice = ("Mais je vous en prie", "Tout le plaisir est pour moi", "C'est tout naturel", "Je n'en ferais rien")
bot.send(msg.to, f"{choice(thanks_choice)}, {msg.author}")
thanks_choice = ("Mais je vous en prie.", "Tout le plaisir est pour moi.", "C'est tout naturel.")
bot.send(msg.to, choice(thanks_choice))
@api.on(lambda m: isinstance(re.match(r"(.*)quelle heure(.*)?", m.text, re.IGNORECASE), re.Match))

View File

@ -226,11 +226,11 @@ def auto_help(bot, msg, fct_name: str=""):
bot.send(msg.to, f"Aide sur la commande : {fct_name}")
for line in bot.commands_help[fct_name].desc.splitlines():
bot.send(msg.to, f" {line}")
bot.send(msg.to, f" {line}")
else:
bot.send(msg.to, f"Liste des commandes ({PREFIX}aide <cmnd> pour plus d'info)")
for cmnd_name in bot.commands_help.keys():
bot.send(msg.to, f" - {cmnd_name}")
bot.send(msg.to, f" {cmnd_name}")
def parse(message):
@ -254,17 +254,24 @@ def convert(data, new_type, default=None):
def check_args(func, *input_args):
# args[0] = (type, is_optionnal)
# gets the defaults values given in arguments
defaults = getattr(func, "__defaults__")
if not defaults:
defaults = []
# gets the arguments and their types
annotations = getattr(func, "__annotations__")
if not annotations:
return []
# nb of required arguments
required_args = len(annotations) - len(defaults)
# if the number of given arguments just can't match
if len(input_args) < required_args:
return None
# construction of a list of tuples (type, default_value) for each arguments
check_args = []
for index, arg_type in enumerate(annotations.values()):
if index + 1 > required_args:
@ -272,9 +279,7 @@ def check_args(func, *input_args):
else:
check_args.append((arg_type, None))
if len(input_args) < required_args:
return None
# transtypes each given arguments to its target type
converted_args = []
for index, arg in enumerate(check_args):
if len(input_args) > index:
@ -282,5 +287,10 @@ def check_args(func, *input_args):
else:
converted_args.append(check_args[index][1])
# if an argument has no default value and transtyping has failed
if None in converted_args:
return None
return converted_args