tell.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. class Tell:
  12. def __init__(self, events=None, printer_handle=None, bot=None, say=None):
  13. self.events = events
  14. self.printer = printer_handle
  15. self.bot = bot
  16. self.say = say
  17. self.interests = ['__privmsg__']
  18. self.say = say
  19. self.cmd = ".tell"
  20. self.help = ".tell <nick> <thing to tell when they're back>"
  21. for event in events:
  22. if event._type in self.interests:
  23. event.subscribe(self)
  24. def handle(self, event):
  25. if event.msg.startswith(".tell"):
  26. target = event.msg.split()[1]
  27. if target == self.bot.conf.getNick(self.bot.network):
  28. self.say(event.channel, "I can't tell myself; gtfo")
  29. return
  30. thing = event.msg.split()[2:] # all the way to the end
  31. n = Notice(event.user, target, thing)
  32. if not "tell" in self.bot.mem_store:
  33. self.bot.mem_store["tell"] = list()
  34. # add it to the list of things to tell people
  35. self.bot.mem_store["tell"].append(n)
  36. self.say(event.channel, "I'll let " + n.obj + " know when they're back.")
  37. else:
  38. if "tell" in self.bot.mem_store:
  39. for n in self.bot.mem_store["tell"]:
  40. if event.user.lower() == n.obj.lower():
  41. self.say(event.channel, "Hey " + n.obj + ", " + n.subject + " says \""+ u" ".join(n.message)+"\"")
  42. # we've said it, now delete it.
  43. if n in self.bot.mem_store["tell"]: self.bot.mem_store["tell"].remove(n)