diff --git a/bot.py b/bot.py index bf00586..3c1424b 100644 --- a/bot.py +++ b/bot.py @@ -8,7 +8,7 @@ import emotes import help from utils import debug -VERSION = "1.0" +VERSION = "1.1-dev" t0 = datetime.now() # Loading token @@ -18,6 +18,25 @@ token = os.getenv('DISCORD_TOKEN') client = discord.Client() +async def info(message, args): + """ + Computes the %info command + + :param message: message sent + :type message: :class:`discord.Message` + :param args: arguments of the command + :type args: list[:class:`str`] + """ + await message.channel.send(f"```Discord Analyst v{VERSION} started at {t0:%Y-%m-%d %H:%M}```") + + +COMMANDS = { + "%help": help.compute, + "%emotes": emotes.compute, + "%info": info +} + + @client.event async def on_ready(): """ @@ -47,6 +66,13 @@ async def on_message(message): if message.author == client.user: return + args = message.content.split(" ") + + if len(args) < 1 or args[0] not in COMMANDS: + return + + debug(message, f"command '{message.content}'") + # Check if bot can respond on current channel or DM user permissions = message.channel.permissions_for(message.guild.me) if not permissions.send_messages: @@ -58,14 +84,7 @@ async def on_message(message): return # Redirect to the correct command - args = message.content.split(" ") - if args[0] == "%info": - debug(message, f"command '{message.content}'") - await message.channel.send(f"Discord Analyst v{VERSION} started at {t0.isoformat()}") - if args[0] == "%help": - await help.compute(message, args) - if args[0] == "%emotes": - await emotes.compute(message, args) + await COMMANDS[args[0]](message, args) # Launch client diff --git a/help.py b/help.py index 4b25418..cf6c984 100644 --- a/help.py +++ b/help.py @@ -10,7 +10,6 @@ async def compute(message, args): :param args: arguments of the command :type args: list[str] """ - debug(message, f"command '{message.content}'") # Select correct response to send diff --git a/utils.py b/utils.py index fdfa46a..66e8a49 100644 --- a/utils.py +++ b/utils.py @@ -1,5 +1,6 @@ # DISCORD API + def debug(message, txt): """ Print a log with the context of the current event