Add upload improvments #6
19
src/memes.py
19
src/memes.py
@ -282,6 +282,24 @@ async def uploadMeme(command, message, client):
|
|||||||
file_names = []
|
file_names = []
|
||||||
|
|
||||||
for file in message.attachments:
|
for file in message.attachments:
|
||||||
|
|
||||||
|
# if we want to override the name
|
||||||
|
uploaded_file_name = file.filename
|
||||||
|
if len(command) > 1:
|
||||||
|
uploaded_file_name = ""
|
||||||
|
for word in command[1:]:
|
||||||
|
uploaded_file_name += word + "_"
|
||||||
|
|
||||||
|
# remove the last _ from the name
|
||||||
|
uploaded_file_name = uploaded_file_name.rstrip(uploaded_file_name[-1])
|
||||||
|
|
||||||
|
# append the file extension
|
||||||
|
name, ext = os.path.splitext(file.filename)
|
||||||
|
uploaded_file_name += ext
|
||||||
|
|
||||||
|
print("File name is (" + uploaded_file_name + ")")
|
||||||
|
|
||||||
|
# no files of the same name
|
||||||
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!"
|
||||||
|
|
||||||
@ -298,6 +316,7 @@ async def uploadMeme(command, message, client):
|
|||||||
|
|
||||||
client.remove_object(bucket_name=S3_BUCKET,
|
client.remove_object(bucket_name=S3_BUCKET,
|
||||||
object_name=file.filename)
|
object_name=file.filename)
|
||||||
|
|
||||||
return "That meme is already in the cache (it's called " + memes_to_md5[result.etag] + ")"
|
return "That meme is already in the cache (it's called " + memes_to_md5[result.etag] + ")"
|
||||||
|
|
||||||
os.remove("/tmp/" + file.filename)
|
os.remove("/tmp/" + file.filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user