diff --git a/fun_cmnds.py b/fun_cmnds.py index 59361bf..098ed2d 100644 --- a/fun_cmnds.py +++ b/fun_cmnds.py @@ -14,5 +14,6 @@ def history_limit(bot, msg, *args): @api.user("Shadow15510") +@api.on(lambda m: "glados" in m.text.lower()) def agree(bot, msg, *args): bot.send(msg.to, "Ouaip ! Complètement d'accord avec toi !") \ No newline at end of file diff --git a/glados_cmnds.py b/glados_cmnds.py index c3c1e39..94ce0b3 100644 --- a/glados_cmnds.py +++ b/glados_cmnds.py @@ -31,6 +31,6 @@ def react_on_glados(bot, msg, *args): else: bot.counter = 1 - if bot.counter > 3: + if bot.counter > 10: bot.send(msg.to, f"Bon, {msg.author}, tu vas arrêter de spammer un jour ou bien ?") bot.counter = 0 diff --git a/irc_api/api.py b/irc_api/api.py index 15a9252..c2708b4 100644 --- a/irc_api/api.py +++ b/irc_api/api.py @@ -127,6 +127,7 @@ class Bot: self.channels = channels self.auth = auth self.callbacks = {} + self.commands_help = {} if commands_modules: self.add_commands_modules(*commands_modules) @@ -163,9 +164,11 @@ class Bot: """ self.irc.send(f"PRIVMSG {target} :{message}") - def add_command(self, command): + def add_command(self, command, add_to_help=False): command.bot = self self.callbacks[command.name] = command + if add_to_help: + self.commands_help[command.name] = command def add_commands(self, *commands): """Add a list of commands to the bot. @@ -175,15 +178,17 @@ class Bot: commands : list A list of command's instances. """ + add_to_help = "auto_help" in [cmnd.name for cmnd in commands] for command in commands: - self.add_command(command) + self.add_command(command, add_to_help=add_to_help) def add_commands_modules(self, *commands_modules): for commands_module in commands_modules: + add_to_help = "auto_help" in dir(commands_module) for cmnd_name in dir(commands_module): cmnd = getattr(commands_module, cmnd_name) if isinstance(cmnd, Command): - self.add_command(cmnd) + self.add_command(cmnd, add_to_help=add_to_help) def remove_command(self, command_name: str): if command_name in self.callbacks.keys(): @@ -193,12 +198,12 @@ class Bot: @command("aide") def auto_help(bot, msg, *args): """Aide des commandes disponibles.""" - if args and args[0] in bot.callbacks.keys(): + if args and args[0] in bot.commands_help.keys(): bot.send(msg.to, f"Aide sur la commande : {args[0]}") - bot.send(msg.to, f" {bot.callbacks[args[0]].desc}") + bot.send(msg.to, f" {bot.commands_help[args[0]].desc}") else: bot.send(msg.to, f"Liste des commandes ({PREFIX}aide pour plus d'info)") - for cmnd_name in bot.callbacks.keys(): + for cmnd_name in bot.commands_help.keys(): bot.send(msg.to, f" – {cmnd_name}")