From bca4fbf616c497f1ec3f4f2511453a077a17a083 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Thu, 3 Feb 2022 02:01:09 +0100 Subject: [PATCH] Add X Is X meme, small cleanups & style fixes --- functions/memes.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/functions/memes.py b/functions/memes.py index 561327f..4ffa2e4 100644 --- a/functions/memes.py +++ b/functions/memes.py @@ -14,7 +14,7 @@ def generate(meme: Meme, fields): if meme.fields == 1: fields = [" ".join(fields)] - fields = _applyMeme(meme, fields) + fields = _apply_meme(meme, fields) # List of fields to send to the API boxes = [{"text": ""}, {"text": ""}, {"text": ""}, {"text": ""}] @@ -33,7 +33,7 @@ def generate(meme: Meme, fields): return {"success": False, "message": "Er is een fout opgetreden."} # Post meme - reply = _postMeme(meme, boxes) + reply = _post_meme(meme, boxes) # Adding a message parameter makes the code in the cog a lot cleaner if not reply["success"]: @@ -45,7 +45,7 @@ def generate(meme: Meme, fields): return reply -def _postMeme(meme: Meme, boxes): +def _post_meme(meme: Meme, boxes): """ Performs API request to generate the meme """ @@ -65,7 +65,7 @@ def _postMeme(meme: Meme, boxes): return memeReply -def _applyMeme(meme: Meme, fields): +def _apply_meme(meme: Meme, fields): """ Some memes are in a special format that only requires a few words to be added, or needs the input to be changed. @@ -74,9 +74,10 @@ def _applyMeme(meme: Meme, fields): Links certain meme id's to functions that need to be applied first. """ memeDict = { - 102156234: _mockingSpongebob, - 91538330: _xXEverywhere, - 252600902: _alwaysHasBeen + 102156234: mocking_spongebob, + 91538330: _x_x_everywhere, + 252600902: _always_has_been, + 167754325: _math_is_math } # Meme needs no special treatment @@ -86,17 +87,23 @@ def _applyMeme(meme: Meme, fields): return memeDict[meme.meme_id](fields) -def _mockingSpongebob(fields): +def mocking_spongebob(fields): return list(map(mock, fields)) -def _xXEverywhere(fields): +def _x_x_everywhere(fields): word = fields[0] return ["{}".format(word), "{} everywhere".format(word)] -def _alwaysHasBeen(fields): +def _always_has_been(fields): word = fields[0] - return ["Wait, it's all {}?".format(word), "Always has been"] + return ["Wait, {}?".format(word), "Always has been"] + + +def _math_is_math(fields): + word = fields[0] + + return [f"{word.upper()} IS {word.upper()}!"]