fixed sending input unsafe

This commit is contained in:
klemek
2020-04-27 15:07:00 +02:00
parent fd8e0a6836
commit b9a8300f3a
+11 -6
View File
@@ -33,7 +33,6 @@ client = discord.Client()
SENT = {} SENT = {}
def debug(message, txt): def debug(message, txt):
""" """
Print a log with the context of the current event Print a log with the context of the current event
@@ -126,12 +125,18 @@ async def on_message(message):
left_wmark_text = None left_wmark_text = None
if len(args) > 1 and message.author.display_name is not None: if len(args) > 1 and message.author.display_name is not None:
left_wmark_text = f"By {message.author.display_name}" left_wmark_text = f"By {message.author.display_name}"
logging.info(args[0])
meme_id = re.sub(r'[^\w ]', "", args[0])
args[0] = meme_id
img = meme_otron.compute(*args, left_wmark_text=left_wmark_text) img = meme_otron.compute(*args, left_wmark_text=left_wmark_text)
if img is None: if img is None:
hint = db.find_nearest(args[0]) if len(meme_id) == 0:
response = f":warning: Template `{args[0]}` not found\n" response = f":warning: Template not found\n"
if hint is not None: else:
response += f"Did you mean `{hint}`?\n" hint = db.find_nearest(meme_id)
response = f":warning: Template `{meme_id}` not found\n"
if hint is not None:
response += f"Did you mean `{hint}`?\n"
response += f"You can find a more detailed help and a list of templates at:\n" \ response += f"You can find a more detailed help and a list of templates at:\n" \
f"<{DOC_URL}>" f"<{DOC_URL}>"
await message.channel.send(response) await message.channel.send(response)
@@ -140,7 +145,7 @@ async def on_message(message):
img.save(output, format="JPEG") img.save(output, format="JPEG")
response = None response = None
if len(args) == 1: if len(args) == 1:
meme = db.get_meme(args[0]) meme = db.get_meme(meme_id)
response = f"Template `{meme.id}`:" response = f"Template `{meme.id}`:"
if len(meme.aliases) > 0: if len(meme.aliases) > 0:
response += f"\n- Aliases: `{'`, `'.join(meme.aliases)}`" response += f"\n- Aliases: `{'`, `'.join(meme.aliases)}`"