1 # synarere -- a highly modular and stable IRC bot.
2 # Copyright (C) 2010 Michael Rodriguez.
3 # Rights to this code are documented in docs/LICENSE.
5 '''Event system for non-IRC events.'''
7 # Import required core module.
13 def dispatch(name
, *args
):
14 '''Dispatch the event.'''
18 # Call every function attached to 'name'.
20 for func
in events
[name
]['funcs']:
25 def attach(event
, func
):
26 '''Add a function to an event.'''
33 events
[event
] = { 'funcs' : [] }
35 if func
in events
[event
]['funcs']:
38 events
[event
]['funcs'].append(func
)
41 logger
.debug('attach(): attached event %s to %s' % (event
, func
))
43 def detach(event
, func
):
44 '''Remove a function from an event.'''
48 if func
not in events
[event
]['funcs']:
51 events
[event
]['funcs'].remove(func
)
53 logger
.debug('detach(): detached event %s from %s' % (event
, func
))