From 31b0f29a9e38f94fec8460c072f159c55bddf621 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Mon, 12 Jun 2023 18:29:58 +0200 Subject: [PATCH] factorization of auto-detected arguments --- glados_cmnds.py | 2 ++ irc_api/api.py | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/glados_cmnds.py b/glados_cmnds.py index e912566..3437b24 100644 --- a/glados_cmnds.py +++ b/glados_cmnds.py @@ -37,6 +37,8 @@ def hour(bot, msg): @api.command("wiki", desc="wiki [limite=1]\nFait une recherche wikipedia.") def wiki(bot, msg, text: str, limit: int=1): + if not (1 < limit <= 10): + limit = 1 session = requests.Session() params = { 'action': 'opensearch', diff --git a/irc_api/api.py b/irc_api/api.py index 350ae03..081e758 100644 --- a/irc_api/api.py +++ b/irc_api/api.py @@ -271,21 +271,19 @@ def check_args(func, *input_args): 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: - check_args.append((arg_type, defaults[index - required_args])) - else: - check_args.append((arg_type, None)) - - # transtypes each given arguments to its target type converted_args = [] - for index, arg in enumerate(check_args): - if len(input_args) > index: - converted_args.append(convert(input_args[index], *check_args[index])) + for index, arg_type in enumerate(annotations.values()): + # construction of a tuple (type, default_value) for each expected argument + if index + 1 > required_args: + check_args = (arg_type, defaults[index - required_args]) else: - converted_args.append(check_args[index][1]) + check_args = (arg_type, None) + + # transtypes each given arguments to its target type + if len(input_args) > index: + converted_args.append(convert(input_args[index], *check_args)) + else: + converted_args.append(check_args[1]) # if an argument has no default value and transtyping has failed if None in converted_args: