refactor imgflip calls
This commit is contained in:
+45
-64
@@ -33,6 +33,13 @@ class Shitpost(commands.Cog):
|
|||||||
'clownsfiguur','krotenkoker','hansworst','grappenmaker','flapdrol','oen',
|
'clownsfiguur','krotenkoker','hansworst','grappenmaker','flapdrol','oen',
|
||||||
'achterlijk gebakje','demente dibbes','geitenbreier','koekwous','sufkop']
|
'achterlijk gebakje','demente dibbes','geitenbreier','koekwous','sufkop']
|
||||||
self.caldav_client = caldav.DAVClient(url=os.getenv('STROOP_CALDAV_HOST'))
|
self.caldav_client = caldav.DAVClient(url=os.getenv('STROOP_CALDAV_HOST'))
|
||||||
|
self.imgflips = {
|
||||||
|
'tering': '78416340',
|
||||||
|
'mark': '112898841',
|
||||||
|
'eriku': '93296473',
|
||||||
|
'tegeltje': '121572521',
|
||||||
|
'zout': '116231806'
|
||||||
|
}
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=False)
|
@commands.command(pass_context=True, hidden=False)
|
||||||
@@ -259,6 +266,25 @@ class Shitpost(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
yield from ctx.channel.send(ctx.author.mention + ' helaas, geen quote gevonden.')
|
yield from ctx.channel.send(ctx.author.mention + ' helaas, geen quote gevonden.')
|
||||||
|
|
||||||
|
def get_imgflip_embed(self, template: str, boven: str, onder: str, extra_options: dict = None):
|
||||||
|
params = dict(
|
||||||
|
template_id = template,
|
||||||
|
username = 'Stroopwafel',
|
||||||
|
password = os.getenv("STROOP_IMGFLIP_PASSWORD"),
|
||||||
|
text0 = boven,
|
||||||
|
text1 = onder
|
||||||
|
)
|
||||||
|
if extra_options:
|
||||||
|
params.update(extra_options)
|
||||||
|
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
||||||
|
if resp:
|
||||||
|
photourl = resp.json()['data']['url']
|
||||||
|
em = discord.Embed(type='photo')
|
||||||
|
em.set_image(url=photourl)
|
||||||
|
return em
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def tering(self, ctx, boven: str, onder: str):
|
def tering(self, ctx, boven: str, onder: str):
|
||||||
@@ -266,22 +292,12 @@ class Shitpost(commands.Cog):
|
|||||||
Bijvoorbeeld:
|
Bijvoorbeeld:
|
||||||
!tering \"Vanavond\" \"gaan we helemaal naar de tering\"
|
!tering \"Vanavond\" \"gaan we helemaal naar de tering\"
|
||||||
"""
|
"""
|
||||||
params = dict(
|
em = self.get_imgflip_embed(self.imgflips['tering'], boven, onder)
|
||||||
template_id = '78416340', #party hard
|
|
||||||
username = 'Stroopwafel',
|
|
||||||
password = os.getenv("STROOP_IMGFLIP_PASSWORD"),
|
|
||||||
text0 = boven,
|
|
||||||
text1 = onder
|
|
||||||
)
|
|
||||||
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
|
||||||
#todo check for success
|
|
||||||
photourl = resp.json()['data']['url']
|
|
||||||
em = discord.Embed(type='photo')
|
|
||||||
em.set_image(url=photourl)
|
|
||||||
try:
|
try:
|
||||||
yield from ctx.message.delete()
|
yield from ctx.message.delete()
|
||||||
except:
|
except:
|
||||||
print("No permission to delete message")
|
print("No permission to delete message")
|
||||||
|
if em:
|
||||||
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
@@ -291,22 +307,12 @@ class Shitpost(commands.Cog):
|
|||||||
Bijvoorbeeld:
|
Bijvoorbeeld:
|
||||||
!mark \"je moeder\" \"is een hoer\"
|
!mark \"je moeder\" \"is een hoer\"
|
||||||
"""
|
"""
|
||||||
params = dict(
|
em = self.get_imgflip_embed(self.imgflips['mark'], boven, onder)
|
||||||
template_id = '112898841', #de marku
|
|
||||||
username = 'Stroopwafel',
|
|
||||||
password = os.getenv("STROOP_IMGFLIP_PASSWORD"),
|
|
||||||
text0 = boven,
|
|
||||||
text1 = onder
|
|
||||||
)
|
|
||||||
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
|
||||||
#todo check for success
|
|
||||||
photourl = resp.json()['data']['url']
|
|
||||||
em = discord.Embed(title='De Mark heeft gesproken.', type='photo')
|
|
||||||
em.set_image(url=photourl)
|
|
||||||
try:
|
try:
|
||||||
yield from ctx.message.delete()
|
yield from ctx.message.delete()
|
||||||
except:
|
except:
|
||||||
print("No permission to delete message")
|
print("No permission to delete message")
|
||||||
|
if em:
|
||||||
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
@@ -316,36 +322,16 @@ class Shitpost(commands.Cog):
|
|||||||
Bijvoorbeeld:
|
Bijvoorbeeld:
|
||||||
!eriku \"je moeder\" \"is een hoer\"
|
!eriku \"je moeder\" \"is een hoer\"
|
||||||
"""
|
"""
|
||||||
params = dict(
|
em = self.get_imgflip_embed(self.imgflips['eriku'], boven, onder)
|
||||||
template_id = '93296473', #de eriku
|
|
||||||
username = 'Stroopwafel',
|
|
||||||
password = os.getenv('STROOP_IMGFLIP_PASSWORD'),
|
|
||||||
text0 = boven,
|
|
||||||
text1 = onder
|
|
||||||
)
|
|
||||||
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
|
||||||
#todo check for success
|
|
||||||
photourl = resp.json()['data']['url']
|
|
||||||
em = discord.Embed(title='De Eriku heeft gesproken. Prijs hem!', type='photo')
|
|
||||||
em.set_image(url=photourl)
|
|
||||||
try:
|
try:
|
||||||
yield from ctx.message.delete()
|
yield from ctx.message.delete()
|
||||||
except:
|
except:
|
||||||
print("No permission to delete message")
|
print("No permission to delete message")
|
||||||
|
if em:
|
||||||
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
def get_tegeltje(self, tekst, auteur):
|
||||||
@asyncio.coroutine
|
|
||||||
def tegeltje(self, ctx, tekst: str, auteur: str=" "):
|
|
||||||
"""Maak een mooi tegeltje met volkswijsheid
|
|
||||||
Bijvoorbeeld:
|
|
||||||
!tegeltje \"Oost west, 420 best\" \"Lourens\"
|
|
||||||
"""
|
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'template_id': '121572521', #delfts blauw
|
|
||||||
'username': 'Stroopwafel',
|
|
||||||
'password': os.getenv('STROOP_IMGFLIP_PASSWORD'),
|
|
||||||
'text0': 'dummy0',
|
'text0': 'dummy0',
|
||||||
'text1': 'dummy1',
|
'text1': 'dummy1',
|
||||||
'font': 'arial',
|
'font': 'arial',
|
||||||
@@ -365,16 +351,21 @@ class Shitpost(commands.Cog):
|
|||||||
'boxes[1][color]': '#0044cc',
|
'boxes[1][color]': '#0044cc',
|
||||||
'boxes[1][outline_color]': '#ffffff'
|
'boxes[1][outline_color]': '#ffffff'
|
||||||
}
|
}
|
||||||
|
return self.get_imgflip_embed(self.imgflips['tegeltje'], "", "", params)
|
||||||
|
|
||||||
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
#todo check for success
|
@asyncio.coroutine
|
||||||
photourl = resp.json()['data']['url']
|
def tegeltje(self, ctx, tekst: str, auteur: str=" "):
|
||||||
em = discord.Embed(title='Tegeltjeswijsheid:', type='photo')
|
"""Maak een mooi tegeltje met volkswijsheid
|
||||||
em.set_image(url=photourl)
|
Bijvoorbeeld:
|
||||||
|
!tegeltje \"Oost west, 420 best\" \"Lourens\"
|
||||||
|
"""
|
||||||
|
em = get_tegeltje(tekst, auteur)
|
||||||
try:
|
try:
|
||||||
yield from ctx.message.delete()
|
yield from ctx.message.delete()
|
||||||
except:
|
except:
|
||||||
print("No permission to delete message")
|
print("No permission to delete message")
|
||||||
|
if em:
|
||||||
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
@@ -384,22 +375,12 @@ class Shitpost(commands.Cog):
|
|||||||
Bijvoorbeeld:
|
Bijvoorbeeld:
|
||||||
!zout \"je moeder\" \"is een hoer\"
|
!zout \"je moeder\" \"is een hoer\"
|
||||||
"""
|
"""
|
||||||
params = dict(
|
em = self.get_imgflip_embed(self.imgflips['zout'], boven, onder)
|
||||||
template_id = '116231806', #de martijn
|
|
||||||
username = 'Stroopwafel',
|
|
||||||
password = os.getenv('STROOP_IMGFLIP_PASSWORD'),
|
|
||||||
text0 = boven,
|
|
||||||
text1 = onder
|
|
||||||
)
|
|
||||||
resp = requests.get(url='https://api.imgflip.com/caption_image', params=params)
|
|
||||||
#todo check for success
|
|
||||||
photourl = resp.json()['data']['url']
|
|
||||||
em = discord.Embed(title='De Martijn heeft gesproken.', type='photo')
|
|
||||||
em.set_image(url=photourl)
|
|
||||||
try:
|
try:
|
||||||
yield from ctx.message.delete()
|
yield from ctx.message.delete()
|
||||||
except:
|
except:
|
||||||
print("No permission to delete message")
|
print("No permission to delete message")
|
||||||
|
if em:
|
||||||
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
yield from ctx.channel.send(ctx.author.mention, embed=em)
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user