mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 03:54:20 +00:00
Disable markov command
This commit is contained in:
parent
6514d56519
commit
f07f4486ee
1 changed files with 25 additions and 24 deletions
|
@ -1,8 +1,8 @@
|
||||||
from typing import *
|
from typing import *
|
||||||
from royalnet.commands import *
|
from royalnet.commands import *
|
||||||
import markovify
|
# import markovify
|
||||||
import os
|
# import os
|
||||||
import re
|
# import re
|
||||||
|
|
||||||
|
|
||||||
class MarkovCommand(Command):
|
class MarkovCommand(Command):
|
||||||
|
@ -12,29 +12,30 @@ class MarkovCommand(Command):
|
||||||
|
|
||||||
syntax: str = "[modello]"
|
syntax: str = "[modello]"
|
||||||
|
|
||||||
_texts: Dict[str, markovify.NewlineText] = {}
|
# _texts: Dict[str, markovify.NewlineText] = {}
|
||||||
|
|
||||||
def __init__(self, interface: CommandInterface):
|
def __init__(self, interface: CommandInterface):
|
||||||
super().__init__(interface)
|
super().__init__(interface)
|
||||||
if interface.name == "telegram":
|
# if interface.name == "telegram":
|
||||||
files: List[str] = tuple(os.walk(self.config["Markov"]["models_directory"]))[0][2]
|
# files: List[str] = tuple(os.walk(self.config["Markov"]["models_directory"]))[0][2]
|
||||||
for file in files:
|
# for file in files:
|
||||||
match = re.match(r"(\S+)\.json$", file)
|
# match = re.match(r"(\S+)\.json$", file)
|
||||||
if match is None:
|
# if match is None:
|
||||||
continue
|
# continue
|
||||||
model_name = match.group(1)
|
# model_name = match.group(1)
|
||||||
with open(os.path.join(self.config["Markov"]["models_directory"], file)) as f:
|
# with open(os.path.join(self.config["Markov"]["models_directory"], file)) as f:
|
||||||
self._texts[model_name] = markovify.NewlineText.from_json(f.read())
|
# self._texts[model_name] = markovify.NewlineText.from_json(f.read())
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
if self.interface.name != "telegram":
|
raise CommandError(f"{self} è disattivato. Riprova tra un po' di giorni!")
|
||||||
raise UnsupportedError("[c]markov[/c] funziona solo su Telegram.")
|
# if self.interface.name != "telegram":
|
||||||
model_name = args.optional(0, self.config["Markov"]["default_model"])
|
# raise UnsupportedError("[c]markov[/c] funziona solo su Telegram.")
|
||||||
try:
|
# model_name = args.optional(0, self.config["Markov"]["default_model"])
|
||||||
sentence = self._texts[model_name].make_sentence()
|
# try:
|
||||||
except KeyError:
|
# sentence = self._texts[model_name].make_sentence()
|
||||||
raise InvalidInputError("Il modello richiesto non esiste.")
|
# except KeyError:
|
||||||
if sentence is None or sentence == "":
|
# raise InvalidInputError("Il modello richiesto non esiste.")
|
||||||
await data.reply(f"💭 Il bot ([c]{model_name}[/c])... non dice niente. Riprova!")
|
# if sentence is None or sentence == "":
|
||||||
else:
|
# await data.reply(f"💭 Il bot ([c]{model_name}[/c])... non dice niente. Riprova!")
|
||||||
await data.reply(f'💬 Il bot ([c]{model_name}[/c]) dice:\n{sentence}')
|
# else:
|
||||||
|
# await data.reply(f'💬 Il bot ([c]{model_name}[/c]) dice:\n{sentence}')
|
||||||
|
|
Loading…
Reference in a new issue