welcome.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from event import Event
  2. from random import choice
  3. class Welcome:
  4. def __init__(self, events=None, printer_handle=None, bot=None, say=None):
  5. self.events = events
  6. self.printer = printer_handle
  7. self.interests = []
  8. self.bot = bot
  9. self.response = ['np', 'you\'re welcome', 'no problem']
  10. nick = self.bot.conf.getNick(self.bot.network)
  11. thanks = Event("__thanks__")
  12. thankyou = Event("__thankyou__")
  13. ty = Event("__ty__")
  14. thanks.define(msg_definition="^([T|t]hanks) " + nick)
  15. thankyou.define(msg_definition="^([T|t]hank you) " + nick)
  16. ty.define(msg_definition="^ty " + nick)
  17. thanks.subscribe(self)
  18. thankyou.subscribe(self)
  19. ty.subscribe(self)
  20. # register ourself to our new hello event
  21. self.bot.register_event(thanks, self)
  22. self.bot.register_event(thankyou, self)
  23. self.bot.register_event(ty, self)
  24. self.help = None
  25. # register ourself for any events that we're interested in that exist already
  26. for event in events:
  27. if event._type in self.interests:
  28. event.subscribe(self)
  29. def handle(self, event):
  30. try:
  31. self.bot.brain.say(event.channel, choice(self.response) + " " + event.user + '\n')
  32. except Exception,e:
  33. print e