40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
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=50000).flatten():
|
|
if (
|
|
message.author.id == user.id
|
|
and "https" not in message.content
|
|
and message.content[0] != "!"
|
|
):
|
|
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))
|