Add X Is X meme, small cleanups & style fixes

pull/104/head
Stijn De Clercq 2022-02-03 02:01:09 +01:00
parent 17964a23fb
commit bca4fbf616
1 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,7 @@ def generate(meme: Meme, fields):
if meme.fields == 1: if meme.fields == 1:
fields = [" ".join(fields)] fields = [" ".join(fields)]
fields = _applyMeme(meme, fields) fields = _apply_meme(meme, fields)
# List of fields to send to the API # List of fields to send to the API
boxes = [{"text": ""}, {"text": ""}, {"text": ""}, {"text": ""}] boxes = [{"text": ""}, {"text": ""}, {"text": ""}, {"text": ""}]
@ -33,7 +33,7 @@ def generate(meme: Meme, fields):
return {"success": False, "message": "Er is een fout opgetreden."} return {"success": False, "message": "Er is een fout opgetreden."}
# Post meme # Post meme
reply = _postMeme(meme, boxes) reply = _post_meme(meme, boxes)
# Adding a message parameter makes the code in the cog a lot cleaner # Adding a message parameter makes the code in the cog a lot cleaner
if not reply["success"]: if not reply["success"]:
@ -45,7 +45,7 @@ def generate(meme: Meme, fields):
return reply return reply
def _postMeme(meme: Meme, boxes): def _post_meme(meme: Meme, boxes):
""" """
Performs API request to generate the meme Performs API request to generate the meme
""" """
@ -65,7 +65,7 @@ def _postMeme(meme: Meme, boxes):
return memeReply return memeReply
def _applyMeme(meme: Meme, fields): def _apply_meme(meme: Meme, fields):
""" """
Some memes are in a special format that only requires Some memes are in a special format that only requires
a few words to be added, or needs the input to be changed. 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. Links certain meme id's to functions that need to be applied first.
""" """
memeDict = { memeDict = {
102156234: _mockingSpongebob, 102156234: mocking_spongebob,
91538330: _xXEverywhere, 91538330: _x_x_everywhere,
252600902: _alwaysHasBeen 252600902: _always_has_been,
167754325: _math_is_math
} }
# Meme needs no special treatment # Meme needs no special treatment
@ -86,17 +87,23 @@ def _applyMeme(meme: Meme, fields):
return memeDict[meme.meme_id](fields) return memeDict[meme.meme_id](fields)
def _mockingSpongebob(fields): def mocking_spongebob(fields):
return list(map(mock, fields)) return list(map(mock, fields))
def _xXEverywhere(fields): def _x_x_everywhere(fields):
word = fields[0] word = fields[0]
return ["{}".format(word), "{} everywhere".format(word)] return ["{}".format(word), "{} everywhere".format(word)]
def _alwaysHasBeen(fields): def _always_has_been(fields):
word = fields[0] 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()}!"]