Add ability to upload #2

Merged
tyler merged 10 commits from uploading into main 2022-12-18 02:55:41 +00:00
2 changed files with 31 additions and 3 deletions
Showing only changes of commit 9ad81399cb - Show all commits

View File

@ -3,6 +3,7 @@ import os, random, io
from datetime import datetime from datetime import datetime
from fuzzywuzzy import fuzz, process from fuzzywuzzy import fuzz, process
from minio import Minio from minio import Minio
from minio.commonconfig import Tags
from minio.error import S3Error from minio.error import S3Error
from catbox import Uploader from catbox import Uploader
@ -258,3 +259,25 @@ async def memeDump(command, message, client):
else: else:
await message.channel.send(file=ready_meme) await message.channel.send(file=ready_meme)
return "Enjoy your memes :)" 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 #!/usr/bin/python3
import requests import requests
import os, random, sys import os, random, sys
from memes import parseMeme, memeCount, memeDump, allMemes from memes import parseMeme, memeCount, memeDump, allMemes, uploadMeme
import discord import discord
async def showHelp(very, useless, arguments): async def showHelp(very, useless, arguments):
@ -28,6 +28,10 @@ calldict = {
"!memedump" : memeDump, "!memedump" : memeDump,
"!allmemes" : allMemes, "!allmemes" : allMemes,
"!help" : showHelp, "!help" : showHelp,
"!up" : uploadMeme,
"!upload" : uploadMeme,
"!uploadmeme": uploadMeme,
#"!memeblame" : memeBlame
# plex # plex
#"!plexleaderboard" : getTopUsers, #"!plexleaderboard" : getTopUsers,
} }
@ -36,11 +40,12 @@ calldict = {
# parse the message # parse the message
async def parse_message(client, message): async def parse_message(client, message):
command = message.content.split() command = message.content.split()
cmd_input = command[0].lower()
# if i know this command # 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})') 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): if isinstance(result, discord.File):
print(f'{client.user} is replying with a file ({result.filename})') 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)