class Lita::Updates::Schedule
Attributes
redis[R]
robot[R]
Public Class Methods
call(robot, redis)
click to toggle source
# File lib/lita/updates/schedule.rb, line 4 def self.call(robot, redis) new(robot, redis).call end
new(robot, redis)
click to toggle source
# File lib/lita/updates/schedule.rb, line 8 def initialize(robot, redis) @robot = robot @redis = redis end
Public Instance Methods
call()
click to toggle source
# File lib/lita/updates/schedule.rb, line 13 def call schedule.each do |username, hash| user = Lita::User.fuzzy_find username next unless user Lita::Timing::Scheduled.new( "standup-#{user.mention_name}", redis ).daily_at( time_for(user, hash["time"]), hash["days"].collect(&:to_sym) ) do puts "Starting standup with #{user.mention_name}" Lita::Updates::Conversation.new(robot, redis, user).call end end end
Private Instance Methods
extended_user_for(user)
click to toggle source
# File lib/lita/updates/schedule.rb, line 54 def extended_user_for(user) case Lita.config.robot.adapter when :slack Lita::Adapters::Slack::SlackUser.from_data robot.chat_service.api.send( :call_api, "users.info", :user => user.id )["user"] else user end rescue => error puts "Error finding user #{username}" user end
schedule()
click to toggle source
# File lib/lita/updates/schedule.rb, line 33 def schedule @schedule ||= JSON.load schedule_raw end
schedule_raw()
click to toggle source
# File lib/lita/updates/schedule.rb, line 37 def schedule_raw raw = redis.get("lita-updates:schedule") return "{}" if raw.nil? || raw.empty? raw end
time_for(user, time)
click to toggle source
# File lib/lita/updates/schedule.rb, line 44 def time_for(user, time) user = extended_user_for user now = Time.now offset = user.metadata["tz_offset"] || now.utc_offset hours, minutes = time.split(":").collect(&:to_i) Time.new(now.year, now.month, now.day, hours, minutes, 0, offset).utc. strftime("%k:%M").strip end