Split help module by module
This commit is contained in:
parent
8f1553883f
commit
c77a5db520
|
@ -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 !")
|
|
@ -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
|
||||
|
|
|
@ -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 <cmnd> 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}")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue