From f2b62c3ce7885b6e0c26893dcb7dc06cdbee1400 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Mon, 25 Jan 2021 23:21:40 +0100 Subject: [PATCH] Clean up memegen code a bit --- cogs/fun.py | 12 ++++++------ cogs/modCommands.py | 2 +- functions/database/memes.py | 12 +++++++----- functions/memes.py | 0 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 functions/memes.py diff --git a/cogs/fun.py b/cogs/fun.py index f546aa6..d5b9e42 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -94,22 +94,22 @@ class Fun(commands.Cog): result = memes.getMeme(name) # No meme found - if not result[0]: - return await ctx.send(result[1]) + if result is None: + return await ctx.send("Deze meme staat niet in de database.") # Convert to list to support item assignment fields = list(fields) # If there's only one field, the user isn't required to use quotes - if result[1][2] == 1: + if result[2] == 1: fields = [" ".join(fields)] # Apply mock to mocking spongebob memes - if result[1][1] == "mocking spongebob": + if result[1] == "mocking spongebob": fields = list(map(mock.mock, fields)) # X, X everywhere only takes X as an argument - if result[1][1] == "x, x everywhere": + if result[1] == "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[1][0], + "template_id": result[0], "username": os.getenv("IMGFLIPNAME"), "password": os.getenv("IMGFLIPPASSWORD"), "boxes[0][text]": boxes[0]["text"], diff --git a/cogs/modCommands.py b/cogs/modCommands.py index 274d7fe..70a6077 100644 --- a/cogs/modCommands.py +++ b/cogs/modCommands.py @@ -130,7 +130,7 @@ class ModCommands(commands.Cog): # Adds a meme into the database @add.command(name="Meme", aliases=["Mem"], usage="[Id] [Name] [Aantal Velden]") async def meme(self, ctx, memeid, meme, fields): - await ctx.send(memes.insert(memeid, meme, fields)[1]) + await ctx.send(memes.insert(memeid, meme, fields)) # Adds a person's GitHub into the database @add.command(name="GitHub", aliases=["Gh", "Git"], usage="[Id] [Link]") diff --git a/functions/database/memes.py b/functions/database/memes.py index ab55c1e..1385651 100644 --- a/functions/database/memes.py +++ b/functions/database/memes.py @@ -2,13 +2,15 @@ from functions.database import utils def insert(id, name, fields): - if getMeme(name)[0]: - return [False, "Deze meme staat al in de database."] + if getMeme(name) is not None: + return "Deze meme staat al in de database." + connection = utils.connect() cursor = connection.cursor() cursor.execute("INSERT INTO memes(id, name, fields) VALUES (%s, %s, %s)", [int(id), name.lower(), int(fields)]) connection.commit() - return [True, "{} is toegevoegd aan de database.".format(name[0].upper() + name[1:].lower())] + + return "{} is toegevoegd aan de database.".format(name[0].upper() + name[1:].lower()) def getMeme(name): @@ -17,8 +19,8 @@ def getMeme(name): cursor.execute("SELECT * FROM memes WHERE name like %s", ["%" + name.lower() + "%"]) result = cursor.fetchall() if len(result) == 0: - return [False, "Deze meme staat niet in de database."] - return [True, result[0]] + return None + return result[0] def getAllMemes(): diff --git a/functions/memes.py b/functions/memes.py new file mode 100644 index 0000000..e69de29