Add other upload improvements #7

Merged
tyler merged 4 commits from upload-improvements into main 2022-12-18 04:15:16 +00:00
2 changed files with 24 additions and 11 deletions

View File

@ -210,6 +210,7 @@ def nameBuilder(command):
return uploaded_file_name
###############################################################################
# Calldict methods
@ -255,9 +256,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,17 +275,14 @@ 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
async def uploadMeme(command, message, client):
async def uploadMeme(command, message, discordClient):
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 +291,17 @@ async def uploadMeme(command, message, client):
client = getClient()
file_names = []
if len(message.attachments) <= 0:
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
for file in message.attachments:
# if we want to override the name
uploaded_file_name = file.filename
@ -311,7 +320,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)

View File

@ -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
@ -48,9 +52,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