mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Clean memegen code up more, add more memes (#15)
This commit is contained in:
parent
77addbc30c
commit
7c47c6af73
2 changed files with 113 additions and 48 deletions
56
cogs/fun.py
56
cogs/fun.py
|
|
@ -3,10 +3,10 @@ from decorators import help
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from enums.help_categories import Category
|
||||
from functions import checks, mock, stringFormatters
|
||||
from functions import checks, stringFormatters
|
||||
from functions.database import memes, trump, dadjoke
|
||||
from functions.memes import generate
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import requests
|
||||
|
||||
|
|
@ -100,54 +100,14 @@ class Fun(commands.Cog):
|
|||
# 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.fields == 1:
|
||||
fields = [" ".join(fields)]
|
||||
generated = generate(result, fields)
|
||||
|
||||
# Apply mock to mocking spongebob memes
|
||||
if result.name == "mocking spongebob":
|
||||
fields = list(map(mock.mock, fields))
|
||||
# If the request was successful, remove the message calling it
|
||||
if generated["success"]:
|
||||
await self.utilsCog.removeMessage(ctx.message)
|
||||
|
||||
# X, X everywhere only takes X as an argument
|
||||
if result.name == "x, x everywhere":
|
||||
fields[0] = " ".join(fields)
|
||||
fields.append(fields[0] + " everywhere")
|
||||
|
||||
# List of fields to send to the API
|
||||
boxes = [{"text": ""}, {"text": ""}, {"text": ""}, {"text": ""}]
|
||||
|
||||
# Add all fields required & ignore the excess ones
|
||||
for i in range(len(fields)):
|
||||
if i > 3:
|
||||
break
|
||||
boxes[i]["text"] = fields[i]
|
||||
|
||||
# Check server status
|
||||
req = requests.get('https://api.imgflip.com/get_memes').json()
|
||||
|
||||
if req["success"]:
|
||||
caption = {
|
||||
"template_id": result.meme_id,
|
||||
"username": os.getenv("IMGFLIPNAME"),
|
||||
"password": os.getenv("IMGFLIPPASSWORD"),
|
||||
"boxes[0][text]": boxes[0]["text"],
|
||||
"boxes[1][text]": boxes[1]["text"],
|
||||
"boxes[2][text]": boxes[2]["text"],
|
||||
"boxes[3][text]": boxes[3]["text"]
|
||||
}
|
||||
|
||||
# Send the POST to the API
|
||||
memeReply = requests.post('https://api.imgflip.com/caption_image', caption).json()
|
||||
|
||||
if memeReply['success']:
|
||||
await ctx.send(str(memeReply['data']['url']))
|
||||
await self.utilsCog.removeMessage(ctx.message)
|
||||
else:
|
||||
await ctx.send(
|
||||
"Error! Controleer of je de juiste syntax hebt gebruikt. Gebruik het commando "
|
||||
"\"memes\" voor een lijst aan geaccepteerde meme-namen.")
|
||||
else:
|
||||
await ctx.send("Er is een fout opgetreden.")
|
||||
# Send the meme's url or the error message
|
||||
await ctx.send(generated["message"])
|
||||
|
||||
@commands.command(name="Memes")
|
||||
@commands.check(checks.allowedChannels)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue