Add ability to upload #2

Merged
tyler merged 10 commits from uploading into main 2022-12-18 02:55:41 +00:00
Showing only changes of commit 6dcf4b43b8 - Show all commits

View File

@ -82,12 +82,12 @@ def getClient():
# Helper methods # Helper methods
# Methods to break up the calldict methods # Methods to break up the calldict methods
def getCurrentMemeList(): def getCurrentMemeList(force=False):
global last_checked_all_memes global last_checked_all_memes
global all_memes global all_memes
now = datetime.now() now = datetime.now()
# if no update in the past 5 mins # 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...") print("Enough time has elapsed, refreshing meme cache...")
last_checked_all_memes = now last_checked_all_memes = now
all_memes.clear() all_memes.clear()
@ -266,18 +266,30 @@ async def uploadMeme(command, message, client):
if len(message.attachments) <= 0: if len(message.attachments) <= 0:
return "You didn't attach anything! Please attach a file to upload" return "You didn't attach anything! Please attach a file to upload"
tags = Tags.new_object_tags() uploader_tags = Tags.new_object_tags()
tags["uploader"] = message.author.name uploader_tags["uploader"] = message.author.name
print(tags) print(uploader_tags)
all_memes = getCurrentMemeList() all_memes = getCurrentMemeList()
client = getClient()
file_names = [] file_names = []
for file in message.attachments: for file in message.attachments:
if file.filename in all_memes: 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 #TODO check for file hash
await file.save("/tmp/" + file.filename) 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!"