diff --git a/README.md b/README.md index 7fd10d4..0018248 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Features - [X] Get a random meme - [X] Get a set of memes - [X] Upload memes to bucket +- [X] Find the uploader of a meme - [ ] Check status of Plex instance Enviroment vars diff --git a/src/memes.py b/src/memes.py index c58263b..7a9ca76 100644 --- a/src/memes.py +++ b/src/memes.py @@ -185,7 +185,7 @@ def getMemeUploader(file_name): uploader = tags.get("uploader") if uploader != None: return uploader - return "Unkown" + return "No-one (probably tyler)" # gets a random meme # this will ensure that the meme is not in the last_memes list @@ -347,5 +347,27 @@ async def uploadMeme(command, message, discordClient): return "Thanks got your memes!" +async def memeBlame(command, message, discordClient): + query_string = "" + if len(command) <= 1: + if message.reference is not None: # this is a reply blame + m = await message.channel.fetch_message(message.reference.message_id) + if m.attachments is not None and len(m.attachments) > 0: + query_string = m.attachments[0].filename + else: return "No file attached to replied message!" + else: return "I need a file name or query!" + else: query_string = ' '.join(command[1:]) #get QUERY_STRING + return_string = "" + all_memes = getCurrentMemeList() + if query_string in all_memes: + author = getMemeUploader(query_string) + return_string = author + " uploaded " + query_string + else: + close_meme, total_close_memes = getCloseMemeToQuery(query_string) + author = getMemeUploader(close_meme) + return_string = "I think you meant \"" + close_meme + "\", which was " + return_string += "uploaded by " + author + + return return_string diff --git a/src/on_message.py b/src/on_message.py index 3ef4a92..02c55e3 100644 --- a/src/on_message.py +++ b/src/on_message.py @@ -1,11 +1,13 @@ #!/usr/bin/python3 import requests import os, random, sys -from memes import parseMeme, memeCount, memeDump, allMemes, uploadMeme +from memes import parseMeme, memeCount, memeDump, allMemes, uploadMeme, memeBlame import discord async def showHelp(very, useless, arguments): str = "```Usage:\n" + str += "!help\n" + str += " Print this message\n" str += "!meme [QUERY]\n" str += " Get a meme. Query for the exact name or search. Paramater is optional\n" str += "!memecount\n" @@ -14,12 +16,14 @@ async def showHelp(very, useless, arguments): str += " Get COUNT random memes. If COUNT is not provided, we default to 5\n" str += "!allmemes QUERY\n" 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 += "!blame [NAME/QUERY]\n" + str += " Returns who uploaded the meme that matches the name or query\n" + str += " You can also reply to a message with a meme attached\n" + str += " to find the uploader\n" str += "```" return str @@ -31,13 +35,14 @@ calldict = { "!memecount" : memeCount, "!memedump" : memeDump, "!allmemes" : allMemes, - "!help" : showHelp, "!up" : uploadMeme, "!upload" : uploadMeme, "!uploadmeme": uploadMeme, - #"!memeblame" : memeBlame + "!memeblame" : memeBlame, + "!blame" : memeBlame, # plex #"!plexleaderboard" : getTopUsers, + "!help" : showHelp, }