diff --git a/cogs/fun.py b/cogs/fun.py index d5b9e42..961609e 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -91,7 +91,7 @@ class Fun(commands.Cog): return await ctx.send("Controleer je argumenten.") # Get the meme info that corresponds to this name - result = memes.getMeme(name) + result: memes.Meme = memes.getMeme(name) # No meme found if result is None: @@ -101,15 +101,15 @@ class Fun(commands.Cog): fields = list(fields) # If there's only one field, the user isn't required to use quotes - if result[2] == 1: + if result.fields == 1: fields = [" ".join(fields)] # Apply mock to mocking spongebob memes - if result[1] == "mocking spongebob": + if result.name == "mocking spongebob": fields = list(map(mock.mock, fields)) # X, X everywhere only takes X as an argument - if result[1] == "x, x everywhere": + if result.name == "x, x everywhere": fields[0] = " ".join(fields) fields.append(fields[0] + " everywhere") @@ -127,7 +127,7 @@ class Fun(commands.Cog): if req["success"]: caption = { - "template_id": result[0], + "template_id": result.meme_id, "username": os.getenv("IMGFLIPNAME"), "password": os.getenv("IMGFLIPPASSWORD"), "boxes[0][text]": boxes[0]["text"], diff --git a/functions/database/memes.py b/functions/database/memes.py index 1385651..2c2a443 100644 --- a/functions/database/memes.py +++ b/functions/database/memes.py @@ -1,3 +1,5 @@ +from attr import dataclass + from functions.database import utils @@ -18,9 +20,23 @@ def getMeme(name): cursor = connection.cursor() cursor.execute("SELECT * FROM memes WHERE name like %s", ["%" + name.lower() + "%"]) result = cursor.fetchall() + if len(result) == 0: return None - return result[0] + + meme = Meme(result[0][0], result[0][1], result[0][2]) + + return meme + + +@dataclass +class Meme: + """ + Dataclass to represent a meme in order to avoid having to use [] on tuples all the time + """ + meme_id: int + name: str + fields: int def getAllMemes():