From 3ee12627c360dc47927990376957d3bb381d7da7 Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Sun, 18 Sep 2022 20:06:47 -0700 Subject: [PATCH] addign markov --- app/cogs/markov.py | 35 +++++++++++++++++++++++++++++++++++ app/requirements.txt | 1 + 2 files changed, 36 insertions(+) create mode 100644 app/cogs/markov.py diff --git a/app/cogs/markov.py b/app/cogs/markov.py new file mode 100644 index 00000000..ea9e2cd1 --- /dev/null +++ b/app/cogs/markov.py @@ -0,0 +1,35 @@ +from discord.ext import commands +import core_utils +import discord +import markovify + + +class Markov(commands.Cog): + def __init__(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="markov") + async def markov(self, ctx: commands.Context, user: discord.Member): + + # Get messages from passed in user + authors_mesages = [] + for message in await ctx.history(limit=10000).flatten(): + if message.author.id == user.id: + authors_mesages.append(message.content) + + # Make the model + user_model = markovify.Text(". ".join(authors_mesages)) + model_json = user_model.to_json() + + # f = open("/tmp/model.json", "a") + # f.write(model_json) + # f.close() + + dummy = [] + for i in range(10): + dummy.append(str(user_model.make_sentence(max_words=25, tries=100))) + await ctx.send(" ".join(dummy)) + + +def setup(bot): + bot.add_cog(Markov(bot)) diff --git a/app/requirements.txt b/app/requirements.txt index 5552a87a..f81e6708 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -9,3 +9,4 @@ git+https://github.com/pycord-development/pycord@8df222d86319dd16a5e559585246343 requests wikipedia wolframalpha +markovify \ No newline at end of file