From 228c2b480bbd7009aad3bc15946c8767fa34f9e1 Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Thu, 13 Aug 2020 02:52:22 -0600 Subject: [PATCH] :sparkles: Add custom help command --- PlexBot/__main__.py | 2 ++ PlexBot/bot.py | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/PlexBot/__main__.py b/PlexBot/__main__.py index 8dfae5e..bd5dd58 100644 --- a/PlexBot/__main__.py +++ b/PlexBot/__main__.py @@ -29,6 +29,8 @@ plex_log.setLevel(config["plex"]["log_level"]) bot_log.setLevel(config["discord"]["log_level"]) bot = Bot(command_prefix=BOT_PREFIX) +# Remove help command, we have our own custom one. +bot.remove_command("help") bot.add_cog(General(bot)) bot.add_cog(Plex(bot, BASE_URL, PLEX_TOKEN, LIBRARY_NAME, BOT_PREFIX)) bot.run(TOKEN) diff --git a/PlexBot/bot.py b/PlexBot/bot.py index 2a50782..5e53759 100644 --- a/PlexBot/bot.py +++ b/PlexBot/bot.py @@ -19,6 +19,24 @@ root_log = logging.getLogger() plex_log = logging.getLogger("Plex") bot_log = logging.getLogger("Bot") +help_text = """ +General: + kill [silent] - Halt the bot [silently]. + help - Print this help message. + cleanup - Delete old messages from the bot. + +Plex: + play - Play a song from the plex server. + album - Queue an entire album to play. + np - Print the current playing song. + stop - Halt playback and leave vc. + pause - Pause playback. + resume - Resume playback. + clear - Clear play queue. + +[] - Optional args. +""" + class General(commands.Cog): """General commands @@ -60,6 +78,22 @@ class General(commands.Cog): await self.bot.close() bot_log.info("Stopping upon the request of %s", ctx.author.mention) + @command(name="help") + async def help(self, ctx): + """Prints command help + + Args: + ctx: discord.ext.commands.Context message context from command + + Returns: + None + + Raise: + None + """ + + await ctx.send(f"```{help_text}```") + @command() async def cleanup(self, ctx, limit=250): """Delete old messages from bot @@ -91,11 +125,11 @@ class General(commands.Cog): class Plex(commands.Cog): - """Discord commands pertinent to interacting with Plex - - Contains user commands such as play, pause, resume, stop, etc. - Grabs, and parses all data from plex database. + """ + Discord commands pertinent to interacting with Plex + Contains user commands such as play, pause, resume, stop, etc. + Grabs, and parses all data from plex database. """ # pylint: disable=too-many-instance-attributes