commit before utter laptop death
This commit is contained in:
parent
4e111b410d
commit
d6b51c787a
11 changed files with 163 additions and 221 deletions
|
@ -32,11 +32,12 @@ settings = settings_manager.settings
|
|||
class Markov(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: discord.ext.commands.Bot = bot
|
||||
self.model: markovify.NewlineText
|
||||
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def retrain(self, ctx: discord.ext.commands.Context):
|
||||
markov_model: Optional[markovify.Text] = load_markov_model()
|
||||
message_ref: discord.Message | None = await send_message(
|
||||
ctx, f"{_('command_markov_retrain')}"
|
||||
)
|
||||
|
@ -71,8 +72,8 @@ class Markov(commands.Cog):
|
|||
await ctx.send("Failed to retrain!")
|
||||
return False
|
||||
|
||||
self.model = model
|
||||
save_markov_model(self.model)
|
||||
markov_model = model
|
||||
save_markov_model(markov_model)
|
||||
|
||||
logger.debug(f"Completed retraining in {round(time.time() - start_time,3)}s")
|
||||
|
||||
|
@ -86,33 +87,25 @@ class Markov(commands.Cog):
|
|||
|
||||
@commands.command()
|
||||
async def talk(self, ctx: commands.Context, sentence_size: int = 5) -> None:
|
||||
if not self.model:
|
||||
await send_message(ctx, f"{_('command_markovcommand_talk_insufficent_text')}")
|
||||
markov_model: Optional[markovify.Text] = load_markov_model()
|
||||
if markov_model is None:
|
||||
await send_message(ctx, _("command_markovcommand_talk_insufficent_text"))
|
||||
return
|
||||
|
||||
response: str = ""
|
||||
raw_sentence = None
|
||||
if sentence_size == 1:
|
||||
response = (
|
||||
self.model.make_short_sentence(max_chars=100, tries=100)
|
||||
or _('command_markovcommand_talk_generation_fail')
|
||||
)
|
||||
|
||||
raw_sentence = markov_model.make_short_sentence(max_chars=100, tries=100)
|
||||
else:
|
||||
response = improve_sentence_coherence(
|
||||
self.model.make_sentence(tries=100, max_words=sentence_size)
|
||||
or _('command_talk_generation_fail')
|
||||
)
|
||||
raw_sentence = markov_model.make_sentence(tries=100, max_words=sentence_size)
|
||||
print(raw_sentence)
|
||||
|
||||
cleaned_response: str = re.sub(r"[^\w\s]", "", response).lower()
|
||||
coherent_response: str = rephrase_for_coherence(cleaned_response)
|
||||
if random.random() < 0.9 and is_positive(raw_sentence):
|
||||
gif_url = random.choice(settings["bot"]["misc"]["positive_gifs"])
|
||||
raw_sentence = f"{raw_sentence}\n[jif]({gif_url})"
|
||||
|
||||
if random.random() < 0.9 and is_positive(coherent_response):
|
||||
gif_url: str = random.choice(settings["bot"]["misc"]["positive_gifs"])
|
||||
os.environ["gooberlatestgen"] = raw_sentence
|
||||
await send_message(ctx, raw_sentence)
|
||||
|
||||
coherent_response = f"{coherent_response}\n[jif]({gif_url})"
|
||||
|
||||
os.environ["gooberlatestgen"] = coherent_response
|
||||
await send_message(ctx, coherent_response)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue