Fix for #5
This commit is contained in:
@ -24,38 +24,30 @@ def get_templates() -> list[dict]:
|
||||
return templates
|
||||
|
||||
|
||||
def format_meme_string(input_string: str) -> str:
|
||||
# https://memegen.link/#special-characters
|
||||
out_string: str = input_string.replace("_", "__")
|
||||
out_string: str = out_string.replace("-", "--")
|
||||
out_string: str = out_string.replace(" ", "_")
|
||||
out_string: str = out_string.replace("?", "~q")
|
||||
out_string: str = out_string.replace("&", "~a")
|
||||
out_string: str = out_string.replace("%", "~p")
|
||||
out_string: str = out_string.replace("#", "~h")
|
||||
out_string: str = out_string.replace("/", "~s")
|
||||
out_string: str = out_string.replace("\\", "~b")
|
||||
out_string: str = out_string.replace("<", "~l")
|
||||
out_string: str = out_string.replace(">", "~g")
|
||||
out_string: str = out_string.replace('"', "''")
|
||||
return out_string
|
||||
|
||||
|
||||
def generate_api_url(template: str, top_str: str, btm_str: str) -> str:
|
||||
tmpl_name: str
|
||||
tmpl_ext: str
|
||||
tmpl_name, tmpl_ext = template.split(".")
|
||||
|
||||
# https://memegen.link/#special-characters
|
||||
top_str = format_meme_string(top_str)
|
||||
btm_str = format_meme_string(btm_str)
|
||||
|
||||
top_str = top_str.replace("_", "__")
|
||||
top_str = top_str.replace("-", "--")
|
||||
top_str = top_str.replace(" ", "_")
|
||||
top_str = top_str.replace("?", "~q")
|
||||
top_str = top_str.replace("&", "~a")
|
||||
top_str = top_str.replace("%", "~p")
|
||||
top_str = top_str.replace("#", "~h")
|
||||
top_str = top_str.replace("/", "~s")
|
||||
top_str = top_str.replace("\\", "~b")
|
||||
top_str = top_str.replace("<", "~l")
|
||||
top_str = top_str.replace(">", "~g")
|
||||
top_str = top_str.replace('"', "''")
|
||||
|
||||
btm_str = btm_str.replace("_", "__")
|
||||
btm_str = btm_str.replace("-", "--")
|
||||
btm_str = btm_str.replace(" ", "_")
|
||||
btm_str = btm_str.replace("?", "~q")
|
||||
btm_str = btm_str.replace("&", "~a")
|
||||
btm_str = btm_str.replace("%", "~p")
|
||||
btm_str = btm_str.replace("#", "~h")
|
||||
btm_str = btm_str.replace("/", "~s")
|
||||
btm_str = btm_str.replace("\\", "~b")
|
||||
btm_str = btm_str.replace("<", "~l")
|
||||
btm_str = btm_str.replace(">", "~g")
|
||||
btm_str = btm_str.replace('"', "''")
|
||||
|
||||
url: str = (
|
||||
f"https://api.memegen.link/images/{tmpl_name}/{top_str}/{btm_str}.{tmpl_ext}"
|
||||
)
|
||||
url: str = f"https://api.memegen.link/images/{tmpl_name}/{top_str}/{btm_str}.{tmpl_ext}"
|
||||
return url
|
||||
|
@ -4,8 +4,7 @@ import os
|
||||
|
||||
from webex_bot.webex_bot import WebexBot
|
||||
|
||||
from webexmemebot import exit, meme
|
||||
|
||||
from webexmemebot import close, meme
|
||||
|
||||
WBX_API_KEY: str = os.environ["WEBEX_API_KEY"]
|
||||
|
||||
@ -21,10 +20,10 @@ def create_bot() -> WebexBot:
|
||||
return bot
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
bot: WebexBot = create_bot()
|
||||
bot.add_command(meme.MakeMemeCommand())
|
||||
bot.add_command(exit.ExitCommand())
|
||||
bot.add_command(close.ExitCommand())
|
||||
bot.commands.remove(bot.help_command)
|
||||
bot.help_command = meme.MakeMemeCommand()
|
||||
bot.run()
|
||||
|
@ -1,5 +1,3 @@
|
||||
import json
|
||||
|
||||
from webex_bot.models.command import Command
|
||||
from webex_bot.models.response import Response, response_from_adaptive_card
|
||||
from webexteamssdk.models.cards import (
|
||||
@ -46,14 +44,16 @@ class MakeMemeCommand(Command):
|
||||
size=FontSize.MEDIUM,
|
||||
),
|
||||
TextBlock(
|
||||
"This bot uses memegen.link to generate memes.",
|
||||
"This bot uses memegen.link to generate memes. Click 'View Templates' to view available templates.",
|
||||
weight=FontWeight.LIGHTER,
|
||||
size=FontSize.SMALL,
|
||||
wrap=True,
|
||||
),
|
||||
TextBlock(
|
||||
"Click 'View Templates' to view available templates.",
|
||||
"Both fields are required. If you do not want to specify a value, please type a space.",
|
||||
weight=FontWeight.LIGHTER,
|
||||
size=FontSize.SMALL,
|
||||
wrap=True,
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -68,8 +68,7 @@ class MakeMemeCommand(Command):
|
||||
id="meme_type",
|
||||
isMultiSelect=False,
|
||||
choices=[
|
||||
Choice(title=x["name"], value=x["choiceval"])
|
||||
for x in TEMPLATES
|
||||
Choice(title=x["name"], value=x["choiceval"]) for x in TEMPLATES
|
||||
],
|
||||
),
|
||||
Text(id="text_top", placeholder="Top Text", maxLength=100),
|
||||
|
Reference in New Issue
Block a user