diff --git a/.gitignore b/.gitignore index 94fa4627..6741b127 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Royalnet ignores config*.toml downloads/ - +markov/ # Python ignores **/__pycache__/ diff --git a/README.md b/README.md index ebf2cff4..3487a7ff 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,6 @@ A [Royalnet](https://github.com/Steffo99/royalnet) pack to have fun with [Markov [Packs."markovpack"] Markov.models_directory = "markovpack" # The name of the directory containing the .json files Markov.default_model = "example" # The name of the .json file that should be parsed if no arguments are passed to the command + Markov.min_words = 5 # The minimum number of words a sentence should have to be sent ``` -4. Start Royalnet and have fun! \ No newline at end of file +4. Start Royalnet with `python -m royalnet` and have fun! \ No newline at end of file diff --git a/markovpack/commands/markov.py b/markovpack/commands/markov.py index 381b0c30..359acf6a 100644 --- a/markovpack/commands/markov.py +++ b/markovpack/commands/markov.py @@ -30,13 +30,18 @@ class MarkovCommand(Command): if self.interface.name != "telegram": raise UnsupportedError("[c]markov[/c] funziona solo su Telegram.") model_name = args.optional(0, self.config["Markov"]["default_model"]) - try: - sentence = self._texts[model_name].make_sentence() - except KeyError: - models = "\n- ".join([model_name for model_name in self._texts]) - raise InvalidInputError("Il modello richiesto non esiste." - f"Modelli disponibili: {models}") - if sentence is None or sentence == "": - await data.reply(f"💭 Il bot ([c]{model_name}[/c])... non dice niente. Riprova!") - else: - await data.reply(f'💬 Il bot ([c]{model_name}[/c]) dice:\n{sentence}') + while True: + try: + sentence = self._texts[model_name].make_sentence() + except KeyError: + models = [] + for mn in self._texts: + models.append(f"- [c]{mn}[/c]\n") + raise InvalidInputError("Il modello richiesto non esiste." + f"Modelli disponibili:\n{models}") + if sentence is None: + continue + if len(sentence.split()) < self.config["Markov"]["min_words"]: + continue + break + await data.reply(f'💬 Il bot ([c]{model_name}[/c]) dice:\n{sentence}') diff --git a/markovpack/version.py b/markovpack/version.py index a6f48398..6ee5af90 100644 --- a/markovpack/version.py +++ b/markovpack/version.py @@ -1 +1 @@ -semantic = "0.2.0" +semantic = "0.3.0" diff --git a/poetry.lock b/poetry.lock index 3509abcb..a37e7c6a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -253,6 +253,17 @@ sqlalchemy = ["sqlalchemy"] test = ["pytest-cov (>=2.6)", "pytest (>4.0)"] zmq = ["pyzmq"] +[[package]] +category = "main" +description = "A simple, extensible Markov chain generator. Uses include generating random semi-plausible sentences based on an existing text." +name = "markovify" +optional = false +python-versions = "*" +version = "0.8.0" + +[package.dependencies] +unidecode = "*" + [[package]] category = "main" description = "A Python Matrix client library, designed according to sans I/O principles." @@ -590,6 +601,14 @@ version = "2.0.0" [package.dependencies] pytz = "*" +[[package]] +category = "main" +description = "ASCII transliterations of Unicode text" +name = "unidecode" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.1.1" + [[package]] category = "main" description = "Unpadded Base64" @@ -664,7 +683,7 @@ python-versions = "*" version = "2020.1.15" [metadata] -content-hash = "e50984a2b35e6d1188ae58089db153a70de042d42e008ca6862331307f504f55" +content-hash = "a4f472f93cfad2f414322d8d78d082a658bc57a2d7f74cfcd96e0f1c653185c5" python-versions = "^3.8" [metadata.files] @@ -831,6 +850,9 @@ logbook = [ {file = "Logbook-1.5.3-cp37-cp37m-win_amd64.whl", hash = "sha256:0cf2cdbfb65a03b5987d19109dacad13417809dcf697f66e1a7084fb21744ea9"}, {file = "Logbook-1.5.3.tar.gz", hash = "sha256:66f454ada0f56eae43066f604a222b09893f98c1adc18df169710761b8f32fe8"}, ] +markovify = [ + {file = "markovify-0.8.0.tar.gz", hash = "sha256:c533a2e1aba8148bb98031b7159e8bf1a276c61db53d2e882ecb74fa5603a4f4"}, +] matrix-nio = [ {file = "matrix-nio-0.6.tar.gz", hash = "sha256:25a4ac9d5e1435035f5c5b6e9a6b453ac66ade25cb455ba6bbe9cc3ae1e0ef50"}, ] @@ -1033,6 +1055,10 @@ tzlocal = [ {file = "tzlocal-2.0.0-py2.py3-none-any.whl", hash = "sha256:11c9f16e0a633b4b60e1eede97d8a46340d042e67b670b290ca526576e039048"}, {file = "tzlocal-2.0.0.tar.gz", hash = "sha256:949b9dd5ba4be17190a80c0268167d7e6c92c62b30026cf9764caf3e308e5590"}, ] +unidecode = [ + {file = "Unidecode-1.1.1-py2.py3-none-any.whl", hash = "sha256:1d7a042116536098d05d599ef2b8616759f02985c85b4fef50c78a5aaf10822a"}, + {file = "Unidecode-1.1.1.tar.gz", hash = "sha256:2b6aab710c2a1647e928e36d69c21e76b453cd455f4e2621000e54b2a9b8cce8"}, +] unpaddedbase64 = [ {file = "unpaddedbase64-1.1.0-py2-none-any.whl", hash = "sha256:8917367e4e915b7dce1a72a99db8798c9f3d0d9a74cdd9aafac6d7c65ca495c5"}, {file = "unpaddedbase64-1.1.0-py2.py3-none-any.whl", hash = "sha256:81cb4eaaa28cc6a282dd3f2c3855eaa1fbaafa736b5ee64df69889e20540a339"}, diff --git a/pyproject.toml b/pyproject.toml index 1b386f96..d324840e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [tool.poetry] name = "markovpack" description = "A Royalnet pack to have fun with Markovify." - version = "0.2.0" + version = "0.3.0" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" homepage = "https://github.com/Steffo99/markovpack"