From 6dcf4b43b8b2fecbbf93980c97c87f7b05d779b1 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Fri, 4 Nov 2022 22:49:16 -0400 Subject: [PATCH] complete basic uploading --- src/memes.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/memes.py b/src/memes.py index d1297d0..e8c9c23 100644 --- a/src/memes.py +++ b/src/memes.py @@ -82,12 +82,12 @@ def getClient(): # Helper methods # Methods to break up the calldict methods -def getCurrentMemeList(): +def getCurrentMemeList(force=False): global last_checked_all_memes global all_memes now = datetime.now() # if no update in the past 5 mins - if (now - last_checked_all_memes).seconds > 300: + if (now - last_checked_all_memes).seconds > 300 or force: print("Enough time has elapsed, refreshing meme cache...") last_checked_all_memes = now all_memes.clear() @@ -266,18 +266,30 @@ async def uploadMeme(command, message, client): if len(message.attachments) <= 0: return "You didn't attach anything! Please attach a file to upload" - tags = Tags.new_object_tags() - tags["uploader"] = message.author.name - print(tags) + uploader_tags = Tags.new_object_tags() + uploader_tags["uploader"] = message.author.name + print(uploader_tags) all_memes = getCurrentMemeList() + client = getClient() file_names = [] for file in message.attachments: if file.filename in all_memes: - return "File with name " + file.filename + " already exists!" + return "File with name '" + file.filename + "' already exists!" #TODO check for file hash + await file.save("/tmp/" + file.filename) + #upload the file to S3 + client.fput_object(bucket_name=S3_BUCKET, + object_name=file.filename, + file_path="/tmp/" + file.filename, + tags=uploader_tags, + content_type=None) - return "not implemented dickhead" + os.remove("/tmp/" + file.filename) + + getCurrentMemeList(force=True) + + return "Thanks got your memes!"