complete functionality to save file locally

This commit is contained in:
Tyler Perkins 2022-11-04 22:34:26 -04:00
parent 995eacbb30
commit 9ad81399cb
2 changed files with 31 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import os, random, io
from datetime import datetime
from fuzzywuzzy import fuzz, process
from minio import Minio
from minio.commonconfig import Tags
from minio.error import S3Error
from catbox import Uploader
@ -258,3 +259,25 @@ async def memeDump(command, message, client):
else:
await message.channel.send(file=ready_meme)
return "Enjoy your memes :)"
# get an uploaded meme and save it
async def uploadMeme(command, message, client):
#TODO check for memes sent using links
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)
all_memes = getCurrentMemeList()
file_names = []
for file in message.attachments:
if file.filename in all_memes:
return "File with name " + file.filename + " already exists!"
#TODO check for file hash
await file.save("/tmp/" + file.filename)
return "not implemented dickhead"

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
import requests
import os, random, sys
from memes import parseMeme, memeCount, memeDump, allMemes
from memes import parseMeme, memeCount, memeDump, allMemes, uploadMeme
import discord
async def showHelp(very, useless, arguments):
@ -28,6 +28,10 @@ calldict = {
"!memedump" : memeDump,
"!allmemes" : allMemes,
"!help" : showHelp,
"!up" : uploadMeme,
"!upload" : uploadMeme,
"!uploadmeme": uploadMeme,
#"!memeblame" : memeBlame
# plex
#"!plexleaderboard" : getTopUsers,
}
@ -36,11 +40,12 @@ calldict = {
# parse the message
async def parse_message(client, message):
command = message.content.split()
cmd_input = command[0].lower()
# if i know this command
if command[0] in calldict.keys():
if cmd_input in calldict.keys():
print(f'{client.user} was passed a command I know! ({message.content})')
result = await calldict[command[0]](command, message, client)
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)