From a3d066def742eca47f2cdaef08af32d50cf00d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Sun, 25 Jul 2021 15:53:36 +0200 Subject: [PATCH] Add possibility to disable commands --- _twitchbot/config.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/_twitchbot/config.py b/_twitchbot/config.py index 851de2a..9610e32 100644 --- a/_twitchbot/config.py +++ b/_twitchbot/config.py @@ -26,15 +26,22 @@ class Command: name: str message: str aliases: [str] + disabled: bool - def __init__(self, name: str, message: str, aliases: [str] = []): + def __init__(self, name: str, message: str, aliases: [str] = None, disabled: bool = False): self.name = name self.message = message - self.aliases = aliases + self.aliases = aliases if aliases is not None else [] + self.disabled = disabled @classmethod def from_dict(cls, params: dict): - return Command(params['name'], params['message'], params.get('aliases', [])) + return Command( + params['name'], + params['message'], + params.get('aliases', []), + params.get('disabled', False) + ) class TimerStrategy(Enum): @@ -102,8 +109,13 @@ class Config: help_command = Command("help", "Voici les commandes disponibles : ") for command in params.get('commands', []): - commands.append(Command.from_dict(command)) - help_command.message = "%s %s%s" % (help_command.message, commands_prefix, command['name']) + c = Command.from_dict(command) + + if c.disabled: + continue + + commands.append(c) + help_command.message = "%s %s%s" % (help_command.message, commands_prefix, c.name) if params.get('help', True): commands.append(help_command)