Clean up memegen code a bit

pull/31/head
Stijn De Clercq 2021-01-25 23:21:40 +01:00
parent 8238bdf6de
commit f2b62c3ce7
4 changed files with 14 additions and 12 deletions

View File

@ -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"],

View File

@ -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]")

View File

@ -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():

View File