diff --git a/modules/ask.py b/modules/ask.py index 77999bd7..45c1e1b6 100644 --- a/modules/ask.py +++ b/modules/ask.py @@ -1,7 +1,9 @@ #!/usr/bin/env python ''' -ask.py - jenni's Ask Module -Copyright 2011-2013, Michael Yanovich (yanovich.net) +ask.py - jenni's Ask Module, randomly select from a given list or provide a yes/no response + +Copyright 2014-2016, Josh Begleiter (jbegleiter.com) +Copyright 2011-2016, Michael Yanovich (yanovich.net) Licensed under the Eiffel Forum License 2. More info: @@ -9,7 +11,8 @@ * Phenny: http://inamidst.com/phenny/ ''' -import random, time +import random.choice +import time random.seed() @@ -18,24 +21,35 @@ def ask(jenni, input): choices = input.group(2) - if choices == None: + if choices is None: jenni.reply('There is no spoon! Please try a valid question.') - elif choices.lower() == 'what is the answer to life, the universe, and everything?': + return + + lower_case_choices = choices.lower() + if lower_case_choices == 'what is the answer to life, the universe, and everything?': ## cf. https://is.gd/2KYchV jenni.reply('42') else: - list_choices = choices.lower().split(' or ') + list_choices = [] + + # If we think the separator is parallel pipes instead of 'or' + if ' || ' in lower_case_choices: + list_choices = lower_case_choices.split(' || ') + else: + list_choices = lower_case_choices.split(' or ') + if len(list_choices) == 1: ## if multiple things aren't listed ## default to yes/no - jenni.reply(random.choice(['yes', 'no'])) + jenni.reply(choice(['yes', 'no'])) else: ## randomly pick an item if multiple things ## are listed - jenni.reply((random.choice(list_choices)).encode('utf-8')) + jenni.reply((choice(list_choices)).encode('utf-8')) ask.commands = ['ask'] ask.priority = 'low' -ask.example = '.ask today or tomorrow or next week' +ask.example = '.ask today || tomorrow || next week' if __name__ == '__main__': print __doc__.strip() +