example.py 905 B

1234567891011121314151617181920212223242526272829
  1. from event import Event
  2. class Example:
  3. def __init__(self, events=None, printer_handle=None, bot=None, say=None):
  4. self.events = events
  5. self.printer = printer_handle
  6. self.interests = ['__custom__']
  7. self.bot = bot
  8. self.say = say
  9. # IMPORTANT: you must subscribe to events before you add your own below, or you'll subscribe twice.
  10. # register ourself for any events that we're interested in that exist already
  11. for event in events:
  12. if event._type in self.interests:
  13. event.subscribe(self)
  14. custom = Event("__custom__")
  15. custom.define("some_regex_here")
  16. custom.subscribe(self)
  17. # register ourself to our new custom event
  18. self.bot.register_event(custom, self)
  19. self.help = None
  20. def handle(self, event):
  21. self.say(event.channel, "welcome, " + event.user)
  22. #self.printer("PRIVMSG " + event.channel + " :welcome, " + event.user + '\n')