lib/flapjack/jabber.rb in flapjack-0.6.23 vs lib/flapjack/jabber.rb in flapjack-0.6.24

- old
+ new

@@ -83,18 +83,20 @@ def on_ready(stanza) return if should_quit? @redis_handler ||= build_redis_connection_pool @connected_at = Time.now.to_i logger.info("Jabber Connected") - @config['rooms'].each do |room| - logger.info("Joining room #{room}") - presence = Blather::Stanza::Presence.new - presence.from = @flapjack_jid - presence.to = Blather::JID.new("#{room}/#{@config['alias']}") - presence << "<x xmlns='http://jabber.org/protocol/muc'/>" - write presence - say(room, "flapjack jabber gateway started at #{Time.now}, hello!", :groupchat) + if @config['rooms'] && @config['rooms'].length > 0 + @config['rooms'].each do |room| + logger.info("Joining room #{room}") + presence = Blather::Stanza::Presence.new + presence.from = @flapjack_jid + presence.to = Blather::JID.new("#{room}/#{@config['alias']}") + presence << "<x xmlns='http://jabber.org/protocol/muc'/>" + write presence + say(room, "flapjack jabber gateway started at #{Time.now}, hello!", :groupchat) + end end end def interpreter(command) @@ -127,10 +129,14 @@ else entity_check = Flapjack::Data::EntityCheck.for_event_id(event_id, :redis => @redis_handler) error = "unknown entity" if entity_check.nil? end + if entity_check && entity_check.in_unscheduled_maintenance? + error = "#{event_id} is already acknowledged" + end + if error msg = "ERROR - couldn't ACK #{ackid} - #{error}" else msg = "ACKing #{entity_check.check} on #{entity_check.entity_name} (#{ackid})" action = Proc.new { @@ -183,11 +189,17 @@ def on_chat(stanza) return if should_quit? logger.debug("chat message received: #{stanza.inspect}") - results = interpreter(stanza.body) + if stanza.body =~ /^flapjack:\s+(.*)/ + command = $1 + else + command = stanza.body + end + + results = interpreter(command) msg = results[:msg] action = results[:action] if msg || action say(stanza.from.stripped, msg, :chat) @@ -272,10 +284,10 @@ "is #{state.upcase}" msg = "#{type.upcase} #{ack_str}::: \"#{check}\" on #{entity} #{maint_str} ::: #{summary}" chat_type = :chat - chat_type = :groupchat if @config['rooms'].include?(address) + chat_type = :groupchat if @config['rooms'] && @config['rooms'].include?(address) EM.next_tick do say(Blather::JID.new(address), msg, chat_type) end end else