From a80e94bb839ed8c5cd00f1befddc71043163943d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 9 Jan 2020 13:41:31 +0100 Subject: [PATCH] fix a few bugs in markov --- pyproject.toml | 2 +- royalpack/commands/markov.py | 19 +++++++++++-------- royalpack/version.py | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f50d0225..b4a2fbc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.2.4" + version = "5.2.5" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/commands/markov.py b/royalpack/commands/markov.py index d4d5babf..47ca5ef2 100644 --- a/royalpack/commands/markov.py +++ b/royalpack/commands/markov.py @@ -16,16 +16,19 @@ class MarkovCommand(Command): def __init__(self, interface: CommandInterface): super().__init__(interface) - files: List[str] = tuple(os.walk(self.config["Markov"]["models_directory"]))[0][2] - for file in files: - match = re.match("(\S+)\.json", file) - if match is None: - continue - model_name = match.group(1) - with open(os.path.join(self.config["Markov"]["models_directory"], file)) as f: - self._texts[model_name] = markovify.NewlineText.from_json(f.read()) + if interface.name == "telegram": + files: List[str] = tuple(os.walk(self.config["Markov"]["models_directory"]))[0][2] + for file in files: + match = re.match(r"(\S+)\.json$", file) + if match is None: + continue + model_name = match.group(1) + with open(os.path.join(self.config["Markov"]["models_directory"], file)) as f: + self._texts[model_name] = markovify.NewlineText.from_json(f.read()) async def run(self, args: CommandArgs, data: CommandData) -> None: + 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() diff --git a/royalpack/version.py b/royalpack/version.py index f27de03a..843d1593 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.2.4" +semantic = "5.2.5"