complete basic uploading

This commit is contained in:
Tyler Perkins 2022-11-04 22:49:16 -04:00
parent 9ad81399cb
commit 6dcf4b43b8

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!"