From 47cd2611bf4dc5f9fa14e5c82c032912a9b8cab8 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sun, 13 Oct 2019 20:14:54 -0500 Subject: (optionally) announce the success of werewolf transformations --- app/workers/scheduler/werewolf_scheduler.rb | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/workers/scheduler/werewolf_scheduler.rb (limited to 'app/workers') diff --git a/app/workers/scheduler/werewolf_scheduler.rb b/app/workers/scheduler/werewolf_scheduler.rb new file mode 100644 index 000000000..6b5764887 --- /dev/null +++ b/app/workers/scheduler/werewolf_scheduler.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class Scheduler::WerewolfScheduler + include Sidekiq::Worker + include Redisable + + STATUS = ENV.fetch('WEREWOLF_STATUS', 'Werewolves successful.') + FOOTER = ENV.fetch('WEREWOLF_FOOTER', ':werewolf: werewolf-status') + + sidekiq_options unique: :until_executed + + def perform + return if redis.exists('werewolf-status') + return unless Setting.werewolf_status + + moon_fraction = SunCalc.moon_illumination(Time.now.utc)[:fraction] + + return unless moon_fraction >= 0.998 + + redis.setex('werewolf-status', 1.day, 1) + + announcer = find_announcer_acct + return if announcer.nil? + + s = PostStatusService.new.call( + announcer, + visibility: :public, + text: STATUS, + footer: FOOTER, + content_type: 'text/console', + ) + + DistributionWorker.perform_async(s.id) + ActivityPub::DistributionWorker.perform_async(s) + end + + private + + def find_announcer_acct + announcer = ENV['ANNOUNCEMENTS_USER'].to_i + return if announcer == 0 + Account.find_by(id: announcer) + end +end -- cgit