linoleum-club/update_status_job.rb

31 lines
901 B
Ruby

require "active_job"
# The number of puzzles we think we have "ready" in the backlog
$backlock_cached_count = 0
class UpdateStatusJob < ActiveJob::Base
queue_as :defualt
def perform
new_count = Puzzle.ready.count
if new_count != $backlock_cached_count
if new_count == 0
# "Watching for a new puzzle"
$bot.update_status "online", "for a new puzzle!", nil, 0, false, 3
else
# status, activity, url, since = 0, afk = false, activity_type = 0
# "Playing 4 backlogged puzzles"
$bot.update_status "online", "#{new_count} backlogged #{"puzzle".pluralize new_count}", nil, 0, false, 0
end
$backlock_cached_count = new_count
end
self.class.enqueue
end
def self.enqueue
self.set(wait: 1.minute).perform_later
end
end