addign markov

This commit is contained in:
Luke Robles 2022-09-18 20:06:47 -07:00
parent 2f97a93c56
commit 3ee12627c3
2 changed files with 36 additions and 0 deletions

35
app/cogs/markov.py Normal file
View File

@ -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))

View File

@ -9,3 +9,4 @@ git+https://github.com/pycord-development/pycord@8df222d86319dd16a5e559585246343
requests requests
wikipedia wikipedia
wolframalpha wolframalpha
markovify