Tell   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 14 3
C handle() 0 23 7
1
# utility class for Tell
2
class Notice:
3
  def __init__(self, subj, obj, message):
4
    self.subject = subj
5
    self.obj = obj
6
    #self.message = u' '
7
    #for word in message:
8
    #  self.message = word.encode('utf-8','ignore')
9
# we no longer need to worry about encoding it, because the bot is receiving and decoding everything for us now
10
    self.message = message
11
12
class Tell:
13
  def __init__(self, events=None, printer_handle=None, bot=None, say=None):
14
    self.events = events
15
    self.printer = printer_handle
16
    self.bot = bot
17
    self.say = say
18
    self.interests = ['__privmsg__']
19
    self.say = say
20
21
    self.cmd = ".tell"
22
    self.help = ".tell <nick> <thing to tell when they're back>"
23
24
    for event in events:
25
      if event._type in self.interests:
26
        event.subscribe(self)
27
28
  def handle(self, event):
29
    if event.msg.startswith(".tell"):
30
      target = event.msg.split()[1]
31
      if target.lower() == self.bot.conf.getNick(self.bot.network).lower():
32
        self.say(event.channel, "I can't tell myself; gtfo")
33
        return
34
      thing = event.msg.split()[2:] # all the way to the end
35
      n = Notice(event.user, target, thing)
36
37
      if not "tell" in self.bot.mem_store:
38
        self.bot.mem_store["tell"] = list()
39
40
      # add it to the list of things to tell people
41
      self.bot.mem_store["tell"].append(n)
42
      self.say(event.channel, "I'll let " + n.obj + " know when they're back.")
43
      
44
    else:
45
      if "tell" in self.bot.mem_store:
46
        for n in self.bot.mem_store["tell"]:
47
          if event.user.lower() == n.obj.lower():
48
            self.say(event.channel, "Hey " + n.obj + ", " + n.subject + " says \""+ u" ".join(n.message)+"\"")
49
            # we've said it, now delete it.
50
            self.bot.mem_store["tell"].remove(n)
51