Project

General

Profile

« Previous | Next » 

Revision 7d493229

Added by Marc Dequènes over 13 years ago

  • ID 7d4932290d4420bd471ed3d11e8b875568e3f418

[evol] add system/user notif to bot level and detecte when a conversation is idle, to close it after used in connect_peer() with block

View differences:

lib/cyborghood/cyborg.rb
include I18nTranslation
bindtextdomain("cyborghood", {:path => Config::L10N_DIR, :charset => "UTF-8"})
attr_reader :name
attr_reader :name, :system_notification, :user_notification
def initialize
@name = self.class.name.split("::").last
......
end
def setup
@system_notification = EventMachine::Channel.new
@user_notification = EventMachine::Channel.new
@system_notification_processing = @system_notification.subscribe do |msg|
process_system_notification(msg)
end
end
def run
......
protected
def process_system_notification(msg)
end
def try_stop
if ready_to_stop?
EventMachine.stop_event_loop
lib/cyborghood/cyborg/botnet.rb
"unix_socket"
end
def setup
super
@pending_conversation_close = []
end
def peer_socket(peer)
File.join(Config::RUN_DIR, peer.downcase + ".sock")
end
......
if @comm_list.has_key? peer
block.call @comm_list[peer]
else
callback = proc do |conversation|
block.call conversation
@pending_conversation_close << conversation.peer_id
end
begin
EventMachine.connect_unix_domain(peer_socket(peer), Conversation, self, block)
rescue
......
def unregister_communication(peer)
@comm_list.delete(peer)
@pending_conversation_close.delete(peer)
end
def ask_to_stop
......
protected
def process_system_notification(msg)
if msg[:topic] == 'CONVERSATION IDLE'
peer = @comm_list[msg[:peer]]
return if peer.nil?
peer.bye
else
super
end
end
def ready_to_stop?
@comm_list.empty?
end
lib/cyborghood/cyborg/conversation.rb
return unless @conv_threads.has_key? name
@conv_threads[name].close
# if only the system thread remains, notify idleness
if @conv_threads.size == 1
@bot.system_notification << { :topic => 'CONVERSATION IDLE', :peer => peer_name }
end
end
def delete_thread(th)

Also available in: Unified diff