hello.py 949 B

123456789101112131415161718192021222324252627282930313233
  1. from event import Event
  2. from random import choice
  3. class Hello:
  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.retorts = ['hello', 'sup', 'hi', 'good to see you', 'loldicks']
  10. hello = Event("__hello__")
  11. nick = self.bot.conf.getNick(self.bot.network)
  12. hello.define(msg_definition="^([H|h]ello|[H|h]i|[H|h]owdy) " + nick)
  13. hello.subscribe(self)
  14. # register ourself to our new hello event
  15. self.bot.register_event(hello, self)
  16. self.help = None
  17. # register ourself for any events that we're interested in that exist already
  18. for event in events:
  19. if event._type in self.interests:
  20. event.subscribe(self)
  21. def handle(self, event):
  22. try:
  23. self.bot.brain.say(event.channel, choice(self.retorts) + " " + event.user + '\n')
  24. except Exception,e:
  25. print e