mirror of https://github.com/stijndcl/didier
				
				
				
			Clean up memegen code a bit
							parent
							
								
									8238bdf6de
								
							
						
					
					
						commit
						f2b62c3ce7
					
				
							
								
								
									
										12
									
								
								cogs/fun.py
								
								
								
								
							
							
						
						
									
										12
									
								
								cogs/fun.py
								
								
								
								
							| 
						 | 
					@ -94,22 +94,22 @@ class Fun(commands.Cog):
 | 
				
			||||||
        result = memes.getMeme(name)
 | 
					        result = memes.getMeme(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # No meme found
 | 
					        # No meme found
 | 
				
			||||||
        if not result[0]:
 | 
					        if result is None:
 | 
				
			||||||
            return await ctx.send(result[1])
 | 
					            return await ctx.send("Deze meme staat niet in de database.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Convert to list to support item assignment
 | 
					        # Convert to list to support item assignment
 | 
				
			||||||
        fields = list(fields)
 | 
					        fields = list(fields)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # If there's only one field, the user isn't required to use quotes
 | 
					        # 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)]
 | 
					            fields = [" ".join(fields)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Apply mock to mocking spongebob memes
 | 
					        # Apply mock to mocking spongebob memes
 | 
				
			||||||
        if result[1][1] == "mocking spongebob":
 | 
					        if result[1] == "mocking spongebob":
 | 
				
			||||||
            fields = list(map(mock.mock, fields))
 | 
					            fields = list(map(mock.mock, fields))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # X, X everywhere only takes X as an argument
 | 
					        # 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[0] = " ".join(fields)
 | 
				
			||||||
            fields.append(fields[0] + " everywhere")
 | 
					            fields.append(fields[0] + " everywhere")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,7 +127,7 @@ class Fun(commands.Cog):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if req["success"]:
 | 
					        if req["success"]:
 | 
				
			||||||
            caption = {
 | 
					            caption = {
 | 
				
			||||||
                "template_id": result[1][0],
 | 
					                "template_id": result[0],
 | 
				
			||||||
                "username": os.getenv("IMGFLIPNAME"),
 | 
					                "username": os.getenv("IMGFLIPNAME"),
 | 
				
			||||||
                "password": os.getenv("IMGFLIPPASSWORD"),
 | 
					                "password": os.getenv("IMGFLIPPASSWORD"),
 | 
				
			||||||
                "boxes[0][text]": boxes[0]["text"],
 | 
					                "boxes[0][text]": boxes[0]["text"],
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ class ModCommands(commands.Cog):
 | 
				
			||||||
    # Adds a meme into the database
 | 
					    # Adds a meme into the database
 | 
				
			||||||
    @add.command(name="Meme", aliases=["Mem"], usage="[Id] [Name] [Aantal Velden]")
 | 
					    @add.command(name="Meme", aliases=["Mem"], usage="[Id] [Name] [Aantal Velden]")
 | 
				
			||||||
    async def meme(self, ctx, memeid, meme, fields):
 | 
					    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
 | 
					    # Adds a person's GitHub into the database
 | 
				
			||||||
    @add.command(name="GitHub", aliases=["Gh", "Git"], usage="[Id] [Link]")
 | 
					    @add.command(name="GitHub", aliases=["Gh", "Git"], usage="[Id] [Link]")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,13 +2,15 @@ from functions.database import utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def insert(id, name, fields):
 | 
					def insert(id, name, fields):
 | 
				
			||||||
    if getMeme(name)[0]:
 | 
					    if getMeme(name) is not None:
 | 
				
			||||||
        return [False, "Deze meme staat al in de database."]
 | 
					        return "Deze meme staat al in de database."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connection = utils.connect()
 | 
					    connection = utils.connect()
 | 
				
			||||||
    cursor = connection.cursor()
 | 
					    cursor = connection.cursor()
 | 
				
			||||||
    cursor.execute("INSERT INTO memes(id, name, fields) VALUES (%s, %s, %s)", [int(id), name.lower(), int(fields)])
 | 
					    cursor.execute("INSERT INTO memes(id, name, fields) VALUES (%s, %s, %s)", [int(id), name.lower(), int(fields)])
 | 
				
			||||||
    connection.commit()
 | 
					    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):
 | 
					def getMeme(name):
 | 
				
			||||||
| 
						 | 
					@ -17,8 +19,8 @@ def getMeme(name):
 | 
				
			||||||
    cursor.execute("SELECT * FROM memes WHERE name like %s", ["%" + name.lower() + "%"])
 | 
					    cursor.execute("SELECT * FROM memes WHERE name like %s", ["%" + name.lower() + "%"])
 | 
				
			||||||
    result = cursor.fetchall()
 | 
					    result = cursor.fetchall()
 | 
				
			||||||
    if len(result) == 0:
 | 
					    if len(result) == 0:
 | 
				
			||||||
        return [False, "Deze meme staat niet in de database."]
 | 
					        return None
 | 
				
			||||||
    return [True, result[0]]
 | 
					    return result[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def getAllMemes():
 | 
					def getAllMemes():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue