about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-10-13 20:14:54 -0500
committermultiple creatures <dev@multiple-creature.party>2019-10-13 20:14:54 -0500
commit47cd2611bf4dc5f9fa14e5c82c032912a9b8cab8 (patch)
tree7fc6a21e3cd550145e1bc469a441f8b8b1502603 /app
parent592790418d37483f247696f81b24ad62e3448842 (diff)
(optionally) announce the success of werewolf transformations
Diffstat (limited to 'app')
-rw-r--r--app/models/form/admin_settings.rb2
-rw-r--r--app/views/admin/settings/edit.html.haml5
-rw-r--r--app/workers/scheduler/werewolf_scheduler.rb44
3 files changed, 51 insertions, 0 deletions
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
index a2ea2489b..8eea46b18 100644
--- a/app/models/form/admin_settings.rb
+++ b/app/models/form/admin_settings.rb
@@ -36,6 +36,7 @@ class Form::AdminSettings
     show_replies_in_public_timelines
     auto_reject_unknown
     auto_mark_known
+    werewolf_status
   ).freeze
 
   BOOLEAN_KEYS = %i(
@@ -53,6 +54,7 @@ class Form::AdminSettings
     show_replies_in_public_timelines
     auto_reject_unknown
     auto_mark_known
+    werewolf_status
   ).freeze
 
   UPLOAD_KEYS = %i(
diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml
index 80f76c3c5..60d6c51f4 100644
--- a/app/views/admin/settings/edit.html.haml
+++ b/app/views/admin/settings/edit.html.haml
@@ -87,6 +87,11 @@
   %hr.spacer/
 
   .fields-group
+    = f.input :werewolf_status, as: :boolean, wrapper: :with_label, label: t('admin.settings.werewolf_status.title'), hint: t('admin.settings.werewolf_status.desc_html')
+
+  %hr.spacer/
+
+  .fields-group
     = f.input :min_invite_role, wrapper: :with_label, collection: %i(disabled user moderator admin), label: t('admin.settings.registrations.min_invite_role.title'), label_method: lambda { |role| role == :disabled ? t('admin.settings.registrations.min_invite_role.disabled') : t("admin.accounts.roles.#{role}") }, include_blank: false, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
 
   .fields-group
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