Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import random, csv, discord, datetime
  2. from collections import defaultdict
  3.  
  4. TOKEN = '<SECRET>'
  5.  
  6. users = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
  7.  
  8. # csv from DiscordChatExporter v2.12.1
  9. with open('newgen.csv') as fh:
  10. c = csv.reader(fh, delimiter=";")
  11. for name, _, msg, _, _ in c:
  12. msg = "~S~ " + msg + " ~E~"
  13. [users[name][pre].update({suff: users[name][pre][suff]+1}) for pre, suff in zip(msg.split(" ")[:-1], msg.split(" ")[1:])]
  14.  
  15. def prod(usr):
  16. bld, tok = [], "~S~"
  17. while tok != "~E~":
  18. bld.append(tok)
  19. tok = random.choices(*zip(*users[usr][tok].items()))[0]
  20. return(" ".join(bld[1:]))
  21.  
  22. class BotClient(discord.Client):
  23. async def on_message(self, message):
  24. if message.content.startswith('!quote') and str(message.channel) == 'bot-and-spam':
  25. 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))
  26. except: await message.channel.send("fail")
  27.  
  28. c = BotClient()
  29. c.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement