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