From eaa981f60dd1f13d96ced20ad3da043d11ee1f65 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 24 Dec 2022 14:30:31 -0500 Subject: [PATCH 1/4] Add basic blame command --- src/memes.py | 20 +++++++++++++++++++- src/on_message.py | 7 ++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/memes.py b/src/memes.py index c58263b..569ec3a 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,23 @@ async def uploadMeme(command, message, discordClient): return "Thanks got your memes!" +async def memeBlame(command, message, discordClient): + if len(command) <= 1: + return "I need a file name or query!" + + 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..83ff86f 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, uploadMeme +from memes import parseMeme, memeCount, memeDump, allMemes, uploadMeme, memeBlame import discord async def showHelp(very, useless, arguments): @@ -31,13 +31,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, } -- 2.45.2 From f51e940cd4cafb1548d633aff156377712cf6323 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 24 Dec 2022 14:42:03 -0500 Subject: [PATCH 2/4] Add reply blame functionality --- src/memes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/memes.py b/src/memes.py index 569ec3a..7a9ca76 100644 --- a/src/memes.py +++ b/src/memes.py @@ -348,10 +348,16 @@ async def uploadMeme(command, message, discordClient): return "Thanks got your memes!" async def memeBlame(command, message, discordClient): + query_string = "" if len(command) <= 1: - return "I need a file name or query!" + 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 - query_string = ' '.join(command[1:]) #get QUERY_STRING return_string = "" all_memes = getCurrentMemeList() @@ -365,5 +371,3 @@ async def memeBlame(command, message, discordClient): return_string += "uploaded by " + author return return_string - - -- 2.45.2 From 85a1e2300bec01489cca37e8149876c4d5ffb38b Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 24 Dec 2022 14:46:23 -0500 Subject: [PATCH 3/4] Update help function --- src/on_message.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/on_message.py b/src/on_message.py index 83ff86f..02c55e3 100644 --- a/src/on_message.py +++ b/src/on_message.py @@ -6,6 +6,8 @@ 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 -- 2.45.2 From 144a7dc3a2dc91355ecf3a71700f14c9e05d2ea2 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 24 Dec 2022 14:46:45 -0500 Subject: [PATCH 4/4] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) 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 -- 2.45.2