From 4a355a43a15fa50f1132a0aafea8c97a1259a40e Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Wed, 12 Oct 2016 10:23:06 +0000 Subject: [PATCH] v0.16.5 improved user finding in .markov, no user will use you for chain generation --- bot.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index a8cbce2..0366fde 100644 --- a/bot.py +++ b/bot.py @@ -33,7 +33,7 @@ from secret import token name = "Maki" # bot version -version = "v0.16.4" +version = "v0.16.5" # text shown by .help command helptext = """I am a bot written in Python by MrDetonia @@ -48,7 +48,7 @@ My commands are: .seen - prints when user was last seen .say - say something .sayy - say something a e s t h e t i c a l l y -.markov - generate sentence using markov chains over a user's chat history +.markov [] - generate markov chain over chat history; a blank user will use you .roll d - roll x number of y sided dice .qr - generate a QR code ```""" @@ -182,7 +182,7 @@ def on_message(message): # echo aesthetic message response = ' '.join(message.content[6:]) - elif message.content.startswith('.markov '): + elif message.content.startswith('.markov'): # send typing signal to discord for attempt in range(5): try: @@ -196,12 +196,22 @@ def on_message(message): # generate a markov chain sentence based on the user's chat history tmp = message.content[8:] - target = message.server.get_member_named(tmp).id - if os.path.isfile('./markovs/' + target): + target = '' + + # if no user provided, markov the author + if tmp == '': + target = message.author.id + else: + try: + target = message.server.get_member_named(tmp).id + except AttributeError: + response = "I can't find that user!" + + if os.path.isfile('./markovs/' + target) and target != '': mc = markov.Markov(open('./markovs/' + target)) response = mc.generate_text(random.randint(20,40)) - else: - response = 'I haven\'t seen them speak yet!' + elif target != '': + response = "I haven't seen them speak yet!" elif message.content.startswith('.roll '): # DnD style dice roll