Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, csv, discord, datetime
- from collections import defaultdict
- TOKEN = '<SECRET>'
- users = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
- # csv from DiscordChatExporter v2.12.1
- with open('log.csv') as fh:
- c = csv.reader(fh, delimiter=";")
- for name, _, msg, _, _ in c:
- msg = "~S~ " + msg + " ~E~"
- [users[name][pre].update({suff: users[name][pre][suff]+1}) for pre, suff in zip(msg.split(" ")[:-1], msg.split(" ")[1:])]
- def prod(usr):
- bld, tok = [], "~S~"
- while tok != "~E~":
- bld.append(tok)
- tok = random.choices(*zip(*users[usr][tok].items()))[0]
- return(" ".join(bld[1:]))
- class BotClient(discord.Client):
- async def on_message(self, message):
- if message.content.startswith('!quote') and str(message.channel) == 'bot-and-spam':
- try: await message.channel.send(embed=discord.Embed(type='rich', colour=discord.Colour.blue(), description=prod(str(message.mentions[0])), timestamp=datetime.datetime.now()).set_footer(text='markov 2-gram walk').set_author(name=message.mentions[0].display_name, icon_url=message.mentions[0].avatar_url))
- except: await message.channel.send("fail")
- c = BotClient()
- c.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement