From 9ad81399cbcc0c40d3963fbf231f1e26b61b8ca0 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Fri, 4 Nov 2022 22:34:26 -0400 Subject: [PATCH] complete functionality to save file locally --- src/memes.py | 23 +++++++++++++++++++++++ src/on_message.py | 11 ++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/memes.py b/src/memes.py index af5241e..d1297d0 100644 --- a/src/memes.py +++ b/src/memes.py @@ -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" diff --git a/src/on_message.py b/src/on_message.py index d583247..91ba84f 100644 --- a/src/on_message.py +++ b/src/on_message.py @@ -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)