Add memegen integration

This commit is contained in:
minerobber 2018-12-15 16:27:51 +00:00
parent e054c87db3
commit 4500d2b4a8
1 changed files with 32 additions and 0 deletions

32
plugins/memegen.py Normal file
View File

@ -0,0 +1,32 @@
import requests,plugin
def fixUp(text):
if not text: return "_" # escape empty string
text = text.replace("_","__") # escape underscores
text = text.replace(" ","_") # escape spaces
text = text.replace("-","--") # escape dashes
text = text.replace("''",'"') # escape double quote
text = text.replace("?","~q") # escape question marks
text = text.replace("%","~p") # escape question marks
text = text.replace("#","~h") # escape question marks
text = text.replace("/","~s") # escape question marks
return text
@plugin.command("meme","<template/url> Top Text | Bottom Text")
def memegen(bot,channel,nick,template,*msg):
if not msg:
raise TypeError() # usage screen
msg = " ".join(msg)
if "|" in msg:
top, bottom = msg.split("|")
else:
top, bottom = "", msg
top = fixUp(top)
bottom = fixUp(bottom)
if "://" in template: # URL
bot.say(channel,"{}: https://memegen.link/custom/{}/{}.jpg?alt={}".format(nick,top,bottom,template))
else:
r = requests.get("https://memegen.link/{}/{}/{}".format(template,top,bottom))
r.raise_for_status()
r = r.json()
bot.say(channel,"{}: {}".format(nick,r["direct"]["masked"]))