adding a help message if someone uses meme incorrectly

This commit is contained in:
Luke Robles 2019-01-04 09:38:29 -08:00
parent f0665d5318
commit a88ca8a2b7
3 changed files with 17 additions and 9 deletions

View File

@ -127,8 +127,6 @@ async def on_message(message):
embed_description="[Direct Link]({})".format(user.avatar_url.replace('.webp', '.png')) embed_description="[Direct Link]({})".format(user.avatar_url.replace('.webp', '.png'))
) )
) )
if message.content.startswith('!meme'):
await client.send_message(message.channel, meme_gen.parse_message(message.content))
if message.content.startswith('!birb'): if message.content.startswith('!birb'):
await client.send_message( await client.send_message(
@ -239,6 +237,11 @@ async def on_message(message):
'You can only use this command in NSFW channels' 'You can only use this command in NSFW channels'
) )
if message.content.startswith('!meme'):
await client.delete_message(message)
await client.send_message(message.channel, meme_gen.parse_message(message.content))
if message.content.startswith('!weather'): if message.content.startswith('!weather'):
await client.send_message( await client.send_message(
message.channel, message.channel,

View File

@ -96,7 +96,7 @@ def get_help_message(method):
], ],
'meme': [ 'meme': [
'Generates a meme on the fly!', 'Generates a meme on the fly!',
'\nUsage: !meme doge top text; bottom text' '\n\nUsage: !meme doge top text; bottom text'
], ],
'homepage': [ 'homepage': [
'This function now outputs the SWEET-ASS picture of the day.', 'This function now outputs the SWEET-ASS picture of the day.',

View File

@ -1,10 +1,13 @@
import os, requests import os
import requests
import help_methods
supported_templates = sorted(list(map(lambda x: x.split('/')[-1], requests.get('https://memegen.link/api/templates/').json().values()))) supported_templates = sorted(list(map(lambda x: x.split('/')[-1], requests.get('https://memegen.link/api/templates/').json().values())))
def parse_message(message): def parse_message(message):
if len(message.split()) < 2: if len(message.split()) <= 2:
return get_templates() return get_meme_help()
escaped_chars = {'_' : '__', ' ' : '_', '-' : '--', '?' : '~q', '%' : '~p', '#' : '~h', '/' : '~s', '\'\'' : '\"'} escaped_chars = {'_' : '__', ' ' : '_', '-' : '--', '?' : '~q', '%' : '~p', '#' : '~h', '/' : '~s', '\'\'' : '\"'}
@ -39,6 +42,8 @@ def get_meme_url(template, upper, lower, usesTemplate):
meme = '{}/{}/{}/{}.{}'.format(base_URL, template, upper, lower, default_format) meme = '{}/{}/{}/{}.{}'.format(base_URL, template, upper, lower, default_format)
return meme return meme
def get_templates(): def get_meme_help():
return "You must supply a valid template for the meme. Templates are one of the following: \n```" + ', '.join(supported_templates) + '```' return "{}\nYou must supply a valid template for the meme. Templates are one of the following: \n```{}```".format(
help_methods.get_help_message('meme'),
', '.join(supported_templates)
)