36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
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:
|
|
try:
|
|
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"]))
|
|
except requests.exceptions.HTTPError:
|
|
bot.say(channel,"ACCESS VIOLATION: Cannot find meme format {}.".format(template))
|