Revision 06f77931
Added by Marc Dequènes over 13 years ago
- ID 06f77931318bb489eca93b67514ccc34db6f788e
lib/cyborghood/cyborg.rb | ||
---|---|---|
include I18nTranslation
|
||
bindtextdomain("cyborghood", {:path => Config::L10N_DIR, :charset => "UTF-8"})
|
||
|
||
attr_reader :name, :system_notification, :user_notification
|
||
attr_reader :name
|
||
|
||
def initialize
|
||
@name = self.class.name.split("::").last
|
||
... | ... | |
end
|
||
end
|
||
|
||
@channels = {}
|
||
|
||
setup
|
||
|
||
logger.info "Bot '#{self.human_name}' loaded"
|
||
end
|
||
|
||
def setup
|
||
@system_notification = EventMachine::Channel.new
|
||
@user_notification = EventMachine::Channel.new
|
||
# #^.*/system$# categories are reserved
|
||
# but you may enhance or break the system as you wish
|
||
def get_channel(name)
|
||
return @channels[name] if @channels.has_key? name
|
||
@channels[name] = EventMachine::Channel.new
|
||
end
|
||
|
||
def drop_channel(name)
|
||
@channels.delete(name)
|
||
end
|
||
|
||
def setup
|
||
@system_notification_name = 'global/system'
|
||
@system_notification = get_channel(@system_notification_name)
|
||
@system_notification_processing = @system_notification.subscribe do |msg|
|
||
process_system_notification(msg)
|
||
end
|
||
... | ... | |
|
||
def try_stop
|
||
if ready_to_stop?
|
||
@system_notification.unsubscribe(@system_notification_processing)
|
||
@system_notification_processing = nil
|
||
drop_channel(@system_notification_name)
|
||
|
||
EventMachine.stop_event_loop
|
||
else
|
||
EventMachine.next_tick { try_stop }
|
Also available in: Unified diff
[evol] reworked notification system a bit (global registration)