Told.get_told_status()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 53
rs 9.5797
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from event import Event
2
import random 
3
4
class Told:
5
    def __init__(self, events=None, printer_handle=None, bot=None, say=None):
6
        self.events = events
7
        self.printer = printer_handle
8
        self.interests = ['__.told__']
9
        self.bot = bot
10
        self.say = say
11
12
        told = Event("__.told__")
13
        told.define(msg_definition="^\.told")
14
        told.subscribe(self)
15
        self.bot.register_event(told, self)
16
17
        self.help = ".told <nick>" 
18
19
    def get_told_status(self, target):
20
        """Randomly selects and returns a string with a "told" status."""
21
        status = ["FUCKING TOLD",
22
                  "CASH4TOLD.COM",
23
                  "KNIGHTS OF THE TOLD REPUBLIC",
24
                  "STONE TOLD STEVE AUSTIN",
25
                  "CURE FOR THE COMMON TOLD",
26
                  "BEN TOLDS FIVE",
27
                  "THE 40 YEAR TOLD VIRGIN",
28
                  "TOLDENEYE 007",
29
                  "TEXAS TOLD'EM",
30
                  "AUSTIN POWERS IN TOLDMEMBER",
31
                  "PTERODACTOLD",
32
                  "NO COUNTRY FOR TOLD MEN",
33
                  "24 CARAT TOLD RING",
34
                  "ONLY SHOOTING STARS BREAK THE TOLD",
35
                  "GOING ONCE...GOING TWICE...TOLD!",
36
                  "GARY TOLDMAN",
37
                  "TOLD SPICE",
38
                  "TOLD STONE CREAMERY",
39
                  "BABY IT'S TOLD OUTSIDE",
40
                  "POKEMON TOLD AND SILVER",
41
                  "TOLD YELLER",
42
                  "EL DORADO: THE LOST CITY OF TOLD",
43
                  "TOLDPLAY",
44
                  "BATMAN: THE BRAVE AND THE TOLD",
45
                  "DANNY DEVITOLD",
46
                  "FOR WHOM THE BELL TOLDS",
47
                  "CAN'T TEACH A TOLD DOG NEW TRICKS",
48
                  "I AIN'T SAYING SHE A TOLD DIGGER",
49
                  "THE TOLDEN COMPASS",
50
                  "TOLDIER OF FORTUNE",
51
                  "TOLDING CHAIR",
52
                  "TOLDEN AXE",
53
                  "TOLD MACDONALD HAD A FARM",
54
                  "TOLDEN TOLDIES: HITS FROM THE 50'S, 60'S, AND 70'S",
55
                  "BATTLETOLDS",
56
                  "YE TOLDE PUB",
57
                  "TOLDEN CAULFIELD",
58
                  "THE TOLD MAN AND THE SEA",
59
                  "TOLD MEDAL WINNER IN THE WINTER OLYMPICS",
60
                  "POT OF TOLD AT THE END OF THE RAINBOW",
61
                  "J.R.R. TOLDKIEN",
62
                  "CALIFORNIA TOLD RUSH",
63
                  "THERE'S TOLD IN THEM THAR HILLS"
64
                  ]
65
        exclamation = ["Damn!",
66
                       "Damn, son!",
67
                       "Snap!",
68
                       "Sheeeiiiiittttt.",
69
                       "Ouch!"
70
                      ]
71
        return random.choice(exclamation) + " %s\'s told status: [X] " % target + random.choice(status)
72
73
    def handle(self, event):
74
        _z = event.msg.split(None, 1)
75
        try:
76
            self.say(event.channel, self.get_told_status(_z[1]))
77
        except IndexError:
78
            self.say(event.channel, "You didn\'t say who got told!")
79
            self.say(event.channel, self.get_told_status(event.user))
80