1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 21:44:21 +00:00
royalnet/royalpack/commands/markov.py

42 lines
1.7 KiB
Python
Raw Normal View History

2020-01-09 02:14:56 +00:00
from typing import *
from royalnet.commands import *
2020-01-10 18:04:52 +00:00
# import markovify
# import os
# import re
2020-01-09 02:14:56 +00:00
class MarkovCommand(Command):
name: str = "markov"
description: str = "Genera una frase da una catena di Markov."
syntax: str = "[modello]"
2020-01-10 18:04:52 +00:00
# _texts: Dict[str, markovify.NewlineText] = {}
2020-01-09 02:14:56 +00:00
def __init__(self, interface: CommandInterface):
super().__init__(interface)
2020-01-10 18:04:52 +00:00
# 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())
2020-01-09 02:14:56 +00:00
async def run(self, args: CommandArgs, data: CommandData) -> None:
2020-01-10 18:04:52 +00:00
raise CommandError(f"{self} è disattivato. Riprova tra un po' di giorni!")
# 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:
# raise InvalidInputError("Il modello richiesto non esiste.")
# 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}')