From 0bc963c78abd9116f8bb0d9dc30e6602f333f76a Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 17 Dec 2022 22:43:14 -0500 Subject: [PATCH 1/3] Fix not using name --- src/memes.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/memes.py b/src/memes.py index e0413b0..c7fc258 100644 --- a/src/memes.py +++ b/src/memes.py @@ -282,9 +282,6 @@ async def memeDump(command, message, client): # get an uploaded meme and save it async def uploadMeme(command, message, client): global memes_to_md5 - #TODO check for memes sent using links - if len(message.attachments) <= 0: - return "You didn't attach anything! Please attach a file to upload" uploader_tags = Tags.new_object_tags() uploader_tags["uploader"] = message.author.name @@ -293,6 +290,12 @@ async def uploadMeme(command, message, client): client = getClient() file_names = [] + if len(message.attachments) <= 0: + return "You didn't attach anything! Please attach a file to upload" + + #TODO left off on adding logic to + + for file in message.attachments: # if we want to override the name uploaded_file_name = file.filename @@ -311,7 +314,7 @@ async def uploadMeme(command, message, client): await file.save("/tmp/" + file.filename) result = client.fput_object(bucket_name=S3_BUCKET, - object_name=file.filename, + object_name=uploaded_file_name, file_path="/tmp/" + file.filename, tags=uploader_tags, content_type=None) From 693999ae21eee59c5e9f50364a120833ee15eab1 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 17 Dec 2022 22:47:16 -0500 Subject: [PATCH 2/3] Reply to sender --- src/memes.py | 8 ++++---- src/on_message.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/memes.py b/src/memes.py index c7fc258..d7d0ba3 100644 --- a/src/memes.py +++ b/src/memes.py @@ -255,9 +255,9 @@ async def allMemes(command, message, client): for meme in close_memes: ready_meme = getDiscordReadyObjectFromS3(meme) if isinstance(ready_meme, str): - await message.channel.send(ready_meme) + await message.channel.send(ready_meme, reference=message) else: - await message.channel.send(file=ready_meme) + await message.channel.send(file=ready_meme, reference=message) return "Enjoy your memes :)" else: return "I need a query!" @@ -274,9 +274,9 @@ async def memeDump(command, message, client): meme = getRandomMeme() ready_meme = getDiscordReadyObjectFromS3(meme) if isinstance(ready_meme, str): - await message.channel.send(ready_meme) + await message.channel.send(ready_meme, reference=message) else: - await message.channel.send(file=ready_meme) + await message.channel.send(file=ready_meme, reference=message) return "Enjoy your memes :)" # get an uploaded meme and save it diff --git a/src/on_message.py b/src/on_message.py index 91ba84f..ca45243 100644 --- a/src/on_message.py +++ b/src/on_message.py @@ -48,9 +48,9 @@ async def parse_message(client, message): result = await calldict[cmd_input](command, message, client) if isinstance(result, discord.File): print(f'{client.user} is replying with a file ({result.filename})') - return await message.channel.send(file=result) + return await message.channel.send(file=result, reference=message) else: print(f'{client.user} is replying with the string ({result})') - return await message.channel.send(result) + return await message.channel.send(result, reference=message) pass From 5c05a8a262784edeb2d93947e9405de3e8cc3f10 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 17 Dec 2022 23:14:11 -0500 Subject: [PATCH 3/3] Add reply upload functionality --- src/memes.py | 10 ++++++++-- src/on_message.py | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/memes.py b/src/memes.py index d7d0ba3..5a4fb2e 100644 --- a/src/memes.py +++ b/src/memes.py @@ -210,6 +210,7 @@ def nameBuilder(command): return uploaded_file_name + ############################################################################### # Calldict methods @@ -280,7 +281,7 @@ async def memeDump(command, message, client): return "Enjoy your memes :)" # get an uploaded meme and save it -async def uploadMeme(command, message, client): +async def uploadMeme(command, message, discordClient): global memes_to_md5 uploader_tags = Tags.new_object_tags() @@ -291,7 +292,12 @@ async def uploadMeme(command, message, client): file_names = [] if len(message.attachments) <= 0: - return "You didn't attach anything! Please attach a file to upload" + if message.reference is not None: # this is a reply upload + m = await message.channel.fetch_message(message.reference.message_id) + result = await uploadMeme(command, m, client) + return result + else: + return "You didn't attach anything! Please attach a file to upload" #TODO left off on adding logic to diff --git a/src/on_message.py b/src/on_message.py index ca45243..debcfae 100644 --- a/src/on_message.py +++ b/src/on_message.py @@ -16,6 +16,10 @@ async def showHelp(very, useless, arguments): str += " Get all memes that are like the given query\n" str += "!help\n" str += " Print this message\n" + str += "!up [NAME]\n" + str += " Upload a meme. If NAME is provided it will be named as such.\n" + str += " You need to either attach the meme with the message, or reply to a\n" + str += " message with the meme you want to upload\n" str += "```" return str