class Lita::Commands::DeletionCandidates
Constants
- MAX_WEEKS_SUSPENDED
Public Instance Methods
name()
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 7 def name 'deletion-candidates' end
run(robot, target, gateway, opts = {})
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 11 def run(robot, target, gateway, opts = {}) msg = build_msg(gateway) robot.send_message(target, msg) if msg robot.send_message(target, "No users found") if msg.nil? && opts[:negative_ack] end
Private Instance Methods
build_msg(gateway)
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 19 def build_msg(gateway) users = long_term_suspended_users(gateway) if users.any? msg = "The following users are suspended, and have not logged in for #{MAX_WEEKS_SUSPENDED} weeks. " msg += "If appropriate, consider deleting their accounts:\n" msg += users.map { |user| "- #{user.path}" }.sort.join("\n") end end
long_term_suspended_users(gateway)
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 30 def long_term_suspended_users(gateway) timestamp = max_weeks_suspended_ago gateway.users.select { |user| user.suspended? }.select { |user| user.last_login_at < timestamp } end
max_weeks_suspended_ago()
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 40 def max_weeks_suspended_ago (Time.now.utc - weeks_in_seconds(MAX_WEEKS_SUSPENDED)).to_datetime end
weeks_in_seconds(weeks)
click to toggle source
# File lib/lita/commands/deletion_candidates.rb, line 44 def weeks_in_seconds(weeks) 60 * 60 * 24 * 7 * weeks.to_i end