addign markov
This commit is contained in:
parent
2f97a93c56
commit
3ee12627c3
35
app/cogs/markov.py
Normal file
35
app/cogs/markov.py
Normal 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))
|
@ -9,3 +9,4 @@ git+https://github.com/pycord-development/pycord@8df222d86319dd16a5e559585246343
|
|||||||
requests
|
requests
|
||||||
wikipedia
|
wikipedia
|
||||||
wolframalpha
|
wolframalpha
|
||||||
|
markovify
|
Loading…
x
Reference in New Issue
Block a user