choose.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from event import Event
  2. import random
  3. import string
  4. try:
  5. from basemodule import BaseModule
  6. except ImportError:
  7. from modules.basemodule import BaseModule
  8. class Choose(BaseModule):
  9. def post_init(self):
  10. choose = Event("__.choose__")
  11. choose.define(msg_definition="^\.choose")
  12. choose.subscribe(self)
  13. self.bot.register_event(choose, self)
  14. self.cmd = ".choose"
  15. self.help = ".choose <option1>|<option2[|<option_n>]"
  16. for event in self.events:
  17. if event._type in self.interests:
  18. event.subscribe(self)
  19. def handle(self, event):
  20. try:
  21. flavortext = ["Always go with ",
  22. "I don't always choose, but when I do, I choose ",
  23. "Wisdom says you should pick ",
  24. "The wise one selects ",
  25. "The spinner selects ",
  26. "My gut says to go with ",
  27. "Easy. I choose ",
  28. "I choose "]
  29. choices = event.msg.split(None, 1)[1].split("|")
  30. if len(choices) == 1:
  31. self.say(event.channel, "If you only have one option, the choice is easy. Go with " + choices[0].strip())
  32. return
  33. self.say(event.channel, random.choice(flavortext) + random.choice(choices).strip())
  34. except Exception as e:
  35. self.say(event.channel, "I couldn't decide")
  36. self.bot.debug_print("Error making decision in choice module")
  37. self.bot.debug_print(str(e))