diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-09 17:05:15 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-09 17:05:15 +0100 |
commit | 39cf220fcd2955faae798623164efc48a10b8417 (patch) | |
tree | 2128acd6141dee68e7247299c86ce481da0dadb2 /lib | |
parent | 8d60bca4c43e386f74e44206fa6eb369e5fe5aae (diff) | |
parent | 196b337a02f959a431a4bb7c443ed116e4e291f3 (diff) |
merge
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mauve/alert_changed.rb | 2 | ||||
-rw-r--r-- | lib/mauve/notification.rb | 15 | ||||
-rw-r--r-- | lib/mauve/notifiers/xmpp.rb | 39 | ||||
-rw-r--r-- | lib/mauve/people_list.rb | 5 | ||||
-rw-r--r-- | lib/mauve/web_interface.rb | 2 |
5 files changed, 45 insertions, 18 deletions
diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb index 0e0d257..2e3ac7d 100644 --- a/lib/mauve/alert_changed.rb +++ b/lib/mauve/alert_changed.rb @@ -71,7 +71,7 @@ module Mauve def remind unless alert.is_a?(Alert) logger.info "#{self.inspect} lost alert #{alert_id}. Killing self." - destroy! + destroy return false end diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb index 82da2e8..57d82d2 100644 --- a/lib/mauve/notification.rb +++ b/lib/mauve/notification.rb @@ -115,16 +115,23 @@ module Mauve protected - # Test to see if a people_list is empty. + # Test to see if a people_list is empty. NB this is just evaluated at the + # time that the DuringRunner is set up with. # # @param [String] people_list People list to query # @return [Boolean] # def no_one_in(people_list) return true unless Configuration.current.people[people_list].respond_to?(:people) + + # + # Cache the results to prevent hitting the calendar too many times. + # + @no_one_in_cache ||= Hash.new - @test_time = @time if @test_time.nil? - return Configuration.current.people[people_list].people(@test_time).empty? + return @no_one_in_cache[people_list] if @no_one_in_cache.has_key?(people_list) + + @no_one_in_cache[people_list] = Configuration.current.people[people_list].people(@time).empty? end # Returns true if the current hour is in the list of hours given. @@ -347,6 +354,4 @@ module Mauve end - class NotificationDummy < Struct.new(:during, :every) ; end - end diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb index 323f89d..f2c5503 100644 --- a/lib/mauve/notifiers/xmpp.rb +++ b/lib/mauve/notifiers/xmpp.rb @@ -474,8 +474,10 @@ module Mauve do_parse_show(msg) when /ack/i do_parse_ack(msg) + when /clear/i + do_parse_clear(msg) when /destroy\s?/i - do_parse_destroy(msg) + "Sorry -- destroy has been disabled. Try \"clear\" instead." else File.executable?('/usr/games/fortune') ? `/usr/games/fortune -s -n 60`.chomp : "I'd love to stay and chat, but I'm really quite busy" end @@ -577,7 +579,7 @@ EOF def do_parse_ack(msg) return "Sorry -- I don't understand your acknowledge command." unless - msg.body =~ /ack(?:nowledge)?\s+([\d\D]+)\s+for\s+(\d+(?:\.\d+)?)\s+(work(?:ing)?|day(?:time)?|wall(?:-?clock)?)?\s*(day|hour|min(?:ute)?|sec(?:ond))s?(?:\s+because\s+(.*))?/i + msg.body =~ /ack(?:nowledge)?\s+([\d\D]+)\s+for\s+(\d+(?:\.\d+)?)\s+(work(?:ing)?|day(?:time)?|wall(?:-?clock)?)?\s*(day|hour|min(?:ute)?|sec(?:ond))s?(?:\s+(?:cos|cause|as|because)?\s*(.*))?/i alerts, n_hours, type_hours, dhms, note = [$1,$2, $3, $4, $5] @@ -654,35 +656,50 @@ EOF return msg.join("\n") end - def do_parse_destroy(msg) - return "Sorry -- I don't understand your destroy command." unless - msg.body =~ /destroy\s+([\d\D]+)$/i + def do_parse_clear(msg) + return "Sorry -- I don't understand your clear command." unless + msg.body =~ /clear\s+([\d\D]+)(?:\s+(?:coz|cause|cos|because|as)?\s*(.*))?/i alerts = $1.split(/\D+/) + note = $2 username = get_username_for(msg.from) if is_muc?(Configuration.current.people[username].xmpp) - return "I'm sorry -- if you want to destroy alerts, please do it from a private chat" + return "I'm sorry -- if you want to clear alerts, please do it from a private chat" end msg = [] - msg << "Results of your destruction:" if alerts.length > 1 + msg << "Clearing results:" if alerts.length > 1 alerts.each do |alert_id| alert = Alert.get(alert_id) if alert.nil? - msg << "#{alert_id}: alert not found" + msg << "#{alert_id}: alert not found." next end - if alert.destroy! - msg << "#{alert.to_s} destroyed" + if alert.cleared? + msg << "#{alert_id}: alert already cleared." + next + end + + if alert.clear! + msg << "#{alert.to_s} cleared." else - msg << "#{alert.to_s}: destruction failed." + msg << "#{alert.to_s}: clearing failed." end end + + # + # Add the note. + # + unless note.to_s.empty? + note = Alert.remove_html(note) + h = History.new(:alerts => succeeded, :type => "note", :event => note.to_s, :user => username) + logger.debug h.errors unless h.save + end return msg.join("\n") end diff --git a/lib/mauve/people_list.rb b/lib/mauve/people_list.rb index 8178635..7124241 100644 --- a/lib/mauve/people_list.rb +++ b/lib/mauve/people_list.rb @@ -25,6 +25,11 @@ module Mauve alias username label + # + # A dummy XMPP method. + # + def xmpp; nil ; end + # Append an Array or String to a list # # @param [Array or String] arr diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index 9a46403..b5c0442 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -409,7 +409,7 @@ EOF post '/alert/:id/destroy' do alert = Alert.get(params[:id]) - alert.destroy! + alert.destroy flash['notice'] = "Successfully destroyed alert #{alert.alert_id} from source #{alert.source}." redirect "/" end |