From a4e43aa9beebfeb13e31468d8fcb89ddcdf007cc Mon Sep 17 00:00:00 2001 From: John Date: Tue, 19 Jun 2018 23:44:34 -0400 Subject: [PATCH 1/5] feat: !help command to look similar to Ayana --- app/dragon-bot.py | 20 +++++++++++++++++++- app/help_methods.py | 21 ++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 0cc8c1b3..86f24299 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -230,11 +230,29 @@ async def on_message(message): ) if message.content.startswith('!help'): - await client.send_message(message.channel, "Sorry {}, But the help command is currently broken. \nIf you'd like to help fix it, take a look at the open issue\nhttp://luker.zzzz.io/gitlab/ldooks/dragon-bot/issues/2".format(message.author.mention)) + #await client.send_message(message.channel, "Sorry {}, But the help command is currently broken. \nIf you'd like to help fix it, take a look at the open issue\nhttp://luker.zzzz.io/gitlab/ldooks/dragon-bot/issues/2".format(message.author.mention)) # await client.send_message( # message.author, # help_methods.parse_message(message.content) # ) + + if len(message.content) > 5: + await client.send_message(message.channel, help_methods.parse_message(message.content)) + else: + description = """Below you can see all the commands I know. +If you need further help with something join our Support Server. \n +**Have a nice day!** +COMMANDS +{} \n +**Use `!help ` for more information about a command.** \n +**Examples:** +`!help dog` for detailed help for the dog command \n +**Useful links:** +johnbest.me""".format(help_methods.parse_message(message.content)) + + embed = discord.Embed(title=None, description=description, color=0x428bca, type="rich") + embed.set_author(name="Hello! I'm {}".format(client.user.name), icon_url=client.user.default_avatar_url) + await client.send_message(message.channel, embed=embed) if message.content.startswith('!homepage'): await client.send_message( diff --git a/app/help_methods.py b/app/help_methods.py index 714a49b8..071ea2c4 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -1,3 +1,4 @@ +import discord def get_help_message(method): """ get_help_message(method) @@ -103,17 +104,15 @@ def get_help_message(method): # Print out every help method if method == 'show_all': - # Might be a better way to do this, but build a list of method : description - build_message = [] - for key, value in supported_methods.items(): - build_message.append("\n{} : {}\n".format(key, ' '.join(supported_methods[key]))) - # Join every element of the list with a space - message = ' '.join(build_message) + commands = '' + for key in supported_methods: + commands += ('`' + key + '`') + ', ' + message = commands[:-2] + else: # Join key : value of the help method they passed in - message = "{} : {}".format(method, ' '.join(supported_methods[method])) - - return "\n{}\n".format(message) + message = "```css\n{} : {}\n```".format(method, ' '.join(supported_methods[method])) + return message def parse_message(message): method = 'show_all' @@ -122,5 +121,5 @@ def parse_message(message): try: explanation = get_help_message(method) except KeyError: - return "I can't help you with that" - return "```css\n{}\n```".format(explanation) + return "This command could not be found." + return explanation From d28062ca4f937c9b4a479d25fd5c4530b7e07853 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 19 Jun 2018 23:55:26 -0400 Subject: [PATCH 2/5] feat: masked urls for !help --- app/dragon-bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 86f24299..ed578d5d 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -240,7 +240,7 @@ async def on_message(message): await client.send_message(message.channel, help_methods.parse_message(message.content)) else: description = """Below you can see all the commands I know. -If you need further help with something join our Support Server. \n +If you need further help with something join our [Support Server](http://discordapp.com). \n **Have a nice day!** COMMANDS {} \n @@ -248,9 +248,9 @@ COMMANDS **Examples:** `!help dog` for detailed help for the dog command \n **Useful links:** -johnbest.me""".format(help_methods.parse_message(message.content)) +[Support Server](http://discordapp.com), [Twitter](http://twitter.com)""".format(help_methods.parse_message(message.content)) - embed = discord.Embed(title=None, description=description, color=0x428bca, type="rich") + embed = discord.Embed(description=description, color=0x428bca, type="rich") embed.set_author(name="Hello! I'm {}".format(client.user.name), icon_url=client.user.default_avatar_url) await client.send_message(message.channel, embed=embed) From 787b4ce5b66f84c6aadf76b4b9617e14e273d92c Mon Sep 17 00:00:00 2001 From: John Date: Wed, 20 Jun 2018 00:40:58 -0400 Subject: [PATCH 3/5] refactor: !help command --- app/dragon-bot.py | 15 +-------------- app/help_methods.py | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index ed578d5d..f98885e6 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -239,20 +239,7 @@ async def on_message(message): if len(message.content) > 5: await client.send_message(message.channel, help_methods.parse_message(message.content)) else: - description = """Below you can see all the commands I know. -If you need further help with something join our [Support Server](http://discordapp.com). \n -**Have a nice day!** -COMMANDS -{} \n -**Use `!help ` for more information about a command.** \n -**Examples:** -`!help dog` for detailed help for the dog command \n -**Useful links:** -[Support Server](http://discordapp.com), [Twitter](http://twitter.com)""".format(help_methods.parse_message(message.content)) - - embed = discord.Embed(description=description, color=0x428bca, type="rich") - embed.set_author(name="Hello! I'm {}".format(client.user.name), icon_url=client.user.default_avatar_url) - await client.send_message(message.channel, embed=embed) + await client.send_message(message.channel, embed=help_methods.get_help_embed(client)) if message.content.startswith('!homepage'): await client.send_message( diff --git a/app/help_methods.py b/app/help_methods.py index 071ea2c4..bd0d463c 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -102,22 +102,38 @@ def get_help_message(method): ], } - # Print out every help method - if method == 'show_all': - commands = '' - for key in supported_methods: - commands += ('`' + key + '`') + ', ' - message = commands[:-2] + # Join key : value of the help method they passed in + return "```css\n{} : {}\n```".format(method, ' '.join(supported_methods[method])) - else: - # Join key : value of the help method they passed in - message = "```css\n{} : {}\n```".format(method, ' '.join(supported_methods[method])) - return message +def get_help_embed(client): + categories = { + 'fun': ['8ball', 'clap', 'decide', 'dog', 'excuse', 'greentext', 'lewd', 'wallpaper', 'message', 'homepage', 'weather', 'pout', 'smug', 'stock', 'tts'], + 'users': ['help', 'purge', 'roles', 'source'], + 'docker': ['docker', 'minecraft'], + 'admin': ['emoji'] + } + + description = "\nBelow you can see all the commands I know.\n\n**Have a nice day!**" + embed = discord.Embed(description=description, color=0x428bca, type="rich") + embed.set_author(name="Hello! I'm {}".format(client.user.name), icon_url=client.user.default_avatar_url) + + for category in categories: + + temp = '' + for command in categories[category]: + temp += '`' + command + '`' + ', ' + temp = temp[:-2] + embed.add_field(name=str(category).upper(), value=temp) + + description2 = "**Use `!help ` for more information about a command.** \n\n" + \ + "**Examples:** \n `!help dog` for detailed help for the dog command \n\n" + \ + "**Useful links:** [Support Server](http://discordapp.com), [Twitter](http://twitter.com)" + + embed.add_field(name="\u200b", value=description2, inline=False) + return embed def parse_message(message): - method = 'show_all' - if len(message.split()) > 1: - method = message.split()[1] + method = message.split()[1] try: explanation = get_help_message(method) except KeyError: From 29789d3331f5a2b63f5f1913b5c1c2e9e60d8baa Mon Sep 17 00:00:00 2001 From: John Date: Wed, 20 Jun 2018 02:36:14 -0400 Subject: [PATCH 4/5] refactor: use split() > 1 vs string length > 5 --- app/dragon-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index f98885e6..c5a6fd07 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -236,7 +236,7 @@ async def on_message(message): # help_methods.parse_message(message.content) # ) - if len(message.content) > 5: + if len(message.content.split()) > 1: await client.send_message(message.channel, help_methods.parse_message(message.content)) else: await client.send_message(message.channel, embed=help_methods.get_help_embed(client)) From dfe804b4ac45ee91fde7afb1210a190cf2c9c7c1 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 21 Jun 2018 17:03:55 -0400 Subject: [PATCH 5/5] refactor: remove commented out code --- app/dragon-bot.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index c5a6fd07..b83530eb 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -230,12 +230,6 @@ async def on_message(message): ) if message.content.startswith('!help'): - #await client.send_message(message.channel, "Sorry {}, But the help command is currently broken. \nIf you'd like to help fix it, take a look at the open issue\nhttp://luker.zzzz.io/gitlab/ldooks/dragon-bot/issues/2".format(message.author.mention)) - # await client.send_message( - # message.author, - # help_methods.parse_message(message.content) - # ) - if len(message.content.split()) > 1: await client.send_message(message.channel, help_methods.parse_message(message.content)) else: