Choose   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 32
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A post_init() 0 11 3
A handle() 0 19 3
1
from event import Event
2
import random
3
import string
4
5
try:
6
  from basemodule import BaseModule
7
except ImportError:
8
  from modules.basemodule import BaseModule
9
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