choose.py 1.8 KB

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