From a1d152a2b4bc93bf7b5f42f8452af88ca56739f6 Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Mon, 24 Jul 2023 16:16:30 +0100 Subject: [PATCH] Fix for #5 --- poetry.lock | 85 +++++++----------------------- pyproject.toml | 2 +- webexmemebot/{exit.py => close.py} | 0 webexmemebot/img.py | 52 ++++++++---------- webexmemebot/main.py | 7 ++- webexmemebot/meme.py | 11 ++-- 6 files changed, 51 insertions(+), 106 deletions(-) rename webexmemebot/{exit.py => close.py} (100%) diff --git a/poetry.lock b/poetry.lock index bebff58..59642cd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry 1.4.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "astroid" version = "2.15.6" description = "An abstract syntax tree for Python with inference support." -category = "dev" optional = false python-versions = ">=3.7.2" files = [ @@ -20,7 +19,6 @@ wrapt = {version = ">=1.14,<2", markers = "python_version >= \"3.11\""} name = "backoff" version = "2.2.1" description = "Function decoration for backoff and retry" -category = "main" optional = false python-versions = ">=3.7,<4.0" files = [ @@ -32,7 +30,6 @@ files = [ name = "black" version = "23.7.0" description = "The uncompromising code formatter." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -75,21 +72,19 @@ uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "certifi" -version = "2023.5.7" +version = "2023.7.22" description = "Python package for providing Mozilla's CA Bundle." -category = "main" optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2023.5.7-py3-none-any.whl", hash = "sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716"}, - {file = "certifi-2023.5.7.tar.gz", hash = "sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7"}, + {file = "certifi-2023.7.22-py3-none-any.whl", hash = "sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"}, + {file = "certifi-2023.7.22.tar.gz", hash = "sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082"}, ] [[package]] name = "cfgv" version = "3.3.1" description = "Validate configuration and produce human readable error messages." -category = "dev" optional = false python-versions = ">=3.6.1" files = [ @@ -101,7 +96,6 @@ files = [ name = "charset-normalizer" version = "3.2.0" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -186,7 +180,6 @@ files = [ name = "click" version = "8.1.6" description = "Composable command line interface toolkit" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -201,7 +194,6 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." -category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -213,7 +205,6 @@ files = [ name = "coloredlogs" version = "15.0.1" description = "Colored terminal output for Python's logging module" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -231,7 +222,6 @@ cron = ["capturer (>=2.4)"] name = "coverage" version = "7.2.7" description = "Code coverage measurement for Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -302,14 +292,13 @@ toml = ["tomli"] [[package]] name = "dill" -version = "0.3.6" -description = "serialize all of python" -category = "dev" +version = "0.3.7" +description = "serialize all of Python" optional = false python-versions = ">=3.7" files = [ - {file = "dill-0.3.6-py3-none-any.whl", hash = "sha256:a07ffd2351b8c678dfc4a856a3005f8067aea51d6ba6c700796a4d9e280f39f0"}, - {file = "dill-0.3.6.tar.gz", hash = "sha256:e5db55f3687856d8fbdab002ed78544e1c4559a130302693d839dfe8f93f2373"}, + {file = "dill-0.3.7-py3-none-any.whl", hash = "sha256:76b122c08ef4ce2eedcd4d1abd8e641114bfc6c2867f49f3c41facf65bf19f5e"}, + {file = "dill-0.3.7.tar.gz", hash = "sha256:cc1c8b182eb3013e24bd475ff2e9295af86c1a38eb1aff128dac8962a9ce3c03"}, ] [package.extras] @@ -319,7 +308,6 @@ graph = ["objgraph (>=1.7.2)"] name = "distlib" version = "0.3.7" description = "Distribution utilities" -category = "dev" optional = false python-versions = "*" files = [ @@ -331,7 +319,6 @@ files = [ name = "filelock" version = "3.12.2" description = "A platform independent file lock." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -347,7 +334,6 @@ testing = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "diff-cover (>=7.5)", "p name = "future" version = "0.18.3" description = "Clean single-source support for Python 3 and 2" -category = "main" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -358,7 +344,6 @@ files = [ name = "humanfriendly" version = "10.0" description = "Human friendly output for text interfaces using Python" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -371,14 +356,13 @@ pyreadline3 = {version = "*", markers = "sys_platform == \"win32\" and python_ve [[package]] name = "identify" -version = "2.5.25" +version = "2.5.26" description = "File identification library for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ - {file = "identify-2.5.25-py2.py3-none-any.whl", hash = "sha256:9df2489842707d431b38ce3410ef8df40da5b10a3e28a3fcac1a42523e956409"}, - {file = "identify-2.5.25.tar.gz", hash = "sha256:db4de0e758c0db8f81996816cd2f3f2f8c5c8d49a7fd02f3b4109aac6fd80e29"}, + {file = "identify-2.5.26-py2.py3-none-any.whl", hash = "sha256:c22a8ead0d4ca11f1edd6c9418c3220669b3b7533ada0a0ffa6cc0ef85cf9b54"}, + {file = "identify-2.5.26.tar.gz", hash = "sha256:7243800bce2f58404ed41b7c002e53d4d22bcf3ae1b7900c2d7aefd95394bf7f"}, ] [package.extras] @@ -388,7 +372,6 @@ license = ["ukkonen"] name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -400,7 +383,6 @@ files = [ name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -412,7 +394,6 @@ files = [ name = "isort" version = "5.12.0" description = "A Python utility / library to sort Python imports." -category = "dev" optional = false python-versions = ">=3.8.0" files = [ @@ -430,7 +411,6 @@ requirements-deprecated-finder = ["pip-api", "pipreqs"] name = "lazy-object-proxy" version = "1.9.0" description = "A fast and thorough lazy object proxy." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -476,7 +456,6 @@ files = [ name = "mccabe" version = "0.7.0" description = "McCabe checker, plugin for flake8" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -488,7 +467,6 @@ files = [ name = "mypy-extensions" version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." -category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -500,7 +478,6 @@ files = [ name = "nodeenv" version = "1.8.0" description = "Node.js virtual environment builder" -category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ @@ -515,7 +492,6 @@ setuptools = "*" name = "packaging" version = "23.1" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -527,7 +503,6 @@ files = [ name = "pathspec" version = "0.11.1" description = "Utility library for gitignore style pattern matching of file paths." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -539,7 +514,6 @@ files = [ name = "pillow" version = "10.0.0" description = "Python Imaging Library (Fork)" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -609,7 +583,6 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa name = "platformdirs" version = "3.9.1" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -625,7 +598,6 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest- name = "pluggy" version = "1.2.0" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -641,7 +613,6 @@ testing = ["pytest", "pytest-benchmark"] name = "pre-commit" version = "3.3.3" description = "A framework for managing and maintaining multi-language pre-commit hooks." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -660,7 +631,6 @@ virtualenv = ">=20.10.0" name = "pyjwt" version = "2.8.0" description = "JSON Web Token implementation in Python" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -678,7 +648,6 @@ tests = ["coverage[toml] (==5.0.4)", "pytest (>=6.0.0,<7.0.0)"] name = "pylint" version = "2.17.4" description = "python code static checker" -category = "dev" optional = false python-versions = ">=3.7.2" files = [ @@ -703,7 +672,6 @@ testutils = ["gitpython (>3)"] name = "pylint-exit" version = "1.2.0" description = "Exit code handler for pylint command line utility." -category = "dev" optional = false python-versions = "*" files = [ @@ -715,7 +683,6 @@ files = [ name = "pyreadline3" version = "3.4.1" description = "A python implementation of GNU readline." -category = "main" optional = false python-versions = "*" files = [ @@ -727,7 +694,6 @@ files = [ name = "pytest" version = "7.4.0" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -748,7 +714,6 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pyyaml" version = "6.0.1" description = "YAML parser and emitter for Python" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -798,7 +763,6 @@ files = [ name = "requests" version = "2.31.0" description = "Python HTTP for Humans." -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -820,7 +784,6 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] name = "requests-toolbelt" version = "1.0.0" description = "A utility belt for advanced users of python-requests" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -835,7 +798,6 @@ requests = ">=2.0.1,<3.0.0" name = "setuptools" version = "68.0.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -852,7 +814,6 @@ testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs ( name = "tomlkit" version = "0.11.8" description = "Style preserving TOML library" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -864,7 +825,6 @@ files = [ name = "urllib3" version = "2.0.4" description = "HTTP library with thread-safe connection pooling, file post, and more." -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -880,30 +840,28 @@ zstd = ["zstandard (>=0.18.0)"] [[package]] name = "virtualenv" -version = "20.24.1" +version = "20.24.2" description = "Virtual Python Environment builder" -category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.24.1-py3-none-any.whl", hash = "sha256:01aacf8decd346cf9a865ae85c0cdc7f64c8caa07ff0d8b1dfc1733d10677442"}, - {file = "virtualenv-20.24.1.tar.gz", hash = "sha256:2ef6a237c31629da6442b0bcaa3999748108c7166318d1f55cc9f8d7294e97bd"}, + {file = "virtualenv-20.24.2-py3-none-any.whl", hash = "sha256:43a3052be36080548bdee0b42919c88072037d50d56c28bd3f853cbe92b953ff"}, + {file = "virtualenv-20.24.2.tar.gz", hash = "sha256:fd8a78f46f6b99a67b7ec5cf73f92357891a7b3a40fd97637c27f854aae3b9e0"}, ] [package.dependencies] -distlib = ">=0.3.6,<1" -filelock = ">=3.12,<4" -platformdirs = ">=3.5.1,<4" +distlib = ">=0.3.7,<1" +filelock = ">=3.12.2,<4" +platformdirs = ">=3.9.1,<4" [package.extras] docs = ["furo (>=2023.5.20)", "proselint (>=0.13)", "sphinx (>=7.0.1)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] -test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.3.1)", "pytest-env (>=0.8.1)", "pytest-freezer (>=0.4.6)", "pytest-mock (>=3.10)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=67.8)", "time-machine (>=2.9)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] [[package]] name = "webex-bot" version = "0.4.0" description = "Python package for a Webex Bot based on websockets." -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -921,7 +879,6 @@ websockets = "10.2" name = "webexteamssdk" version = "1.6.1" description = "Community-developed Python SDK for the Webex Teams APIs" -category = "main" optional = false python-versions = "*" files = [ @@ -939,7 +896,6 @@ requests-toolbelt = "*" name = "websockets" version = "10.2" description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -997,7 +953,6 @@ files = [ name = "wrapt" version = "1.15.0" description = "Module for decorators, wrappers and monkey patching." -category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" files = [ @@ -1080,5 +1035,5 @@ files = [ [metadata] lock-version = "2.0" -python-versions = "3.11.2" -content-hash = "3168ca5606cfcd377fd7fadcefb3f5e242b026227aa87a1e5f11ac5a1da1c000" +python-versions = "^3.11.2" +content-hash = "c1e9bd7fe34e83c135f6e51d2b12e0c9ce8c0842daa25160988a0945e989532f" diff --git a/pyproject.toml b/pyproject.toml index 246e9ef..30d270f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = ["luketainton"] readme = "README.md" [tool.poetry.dependencies] -python = "3.11.2" +python = "^3.11.2" webex-bot = "^0.4.0" pillow = "^10.0.0" diff --git a/webexmemebot/exit.py b/webexmemebot/close.py similarity index 100% rename from webexmemebot/exit.py rename to webexmemebot/close.py diff --git a/webexmemebot/img.py b/webexmemebot/img.py index fedc4e4..55bd96c 100644 --- a/webexmemebot/img.py +++ b/webexmemebot/img.py @@ -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 diff --git a/webexmemebot/main.py b/webexmemebot/main.py index fab122f..870b3cd 100644 --- a/webexmemebot/main.py +++ b/webexmemebot/main.py @@ -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() diff --git a/webexmemebot/meme.py b/webexmemebot/meme.py index a4a531c..f78f729 100644 --- a/webexmemebot/meme.py +++ b/webexmemebot/meme.py @@ -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),