about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-02-17 19:41:56 -0600
committermultiple creatures <dev@multiple-creature.party>2020-02-17 19:42:04 -0600
commitb068a9466c33b464a2215051ce4b1ca980f4f4eb (patch)
treef35b7252beec4f21fce20c49c3c47468550e418b /app/workers/scheduler
parent4c1705e58dbdc47a90b9bc6d989d1a90ebd8287c (diff)
implement our fork of @mykola@weirder.earth's ambassador bot (@ambassador@monsterpit.net) within monsterfork itself
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/ambassador_scheduler.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/workers/scheduler/ambassador_scheduler.rb b/app/workers/scheduler/ambassador_scheduler.rb
new file mode 100644
index 000000000..bedf0f08a
--- /dev/null
+++ b/app/workers/scheduler/ambassador_scheduler.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+class Scheduler::AmbassadorScheduler
+  include Sidekiq::Worker
+
+  def perform
+    @ambassador = find_ambassador_acct
+    return if @ambassador.nil?
+
+    status = next_boost
+    return if status.nil?
+
+    ReblogStatusWorker.perform_async(@ambassador.id, status.id)
+  end
+
+  private
+
+  def find_ambassador_acct
+    ambassador = ENV['AMBASSADOR_USER'].to_i
+    return if ambassador.zero?
+    Account.find_by(id: ambassador)
+  end
+
+  def next_boost
+    ambassador_boost_candidates.first
+  end
+
+  def ambassador_boost_candidates
+    ambassador_boostable.joins(:status_stat).where('favourites_count + reblogs_count > 4')
+  end
+
+  def ambassador_boostable
+    query = ambassador_unboosted.excluding_silenced_accounts.not_excluded_by_account(@ambassador)
+
+    unless !@ambassador.user.filters_enabled || @ambassador.custom_filters.enabled.blank?
+      if @ambassador.user.invert_filters
+        query = query.search_filtered_by_account(@ambassador.id)
+      else
+        query = query.search_not_filtered_by_account(@ambassador.id)
+      end
+    end
+
+    query
+  end
+
+  def ambassador_unboosted
+    locally_boostable.where.not(id: ambassador_boosts)
+  end
+
+  def ambassador_boosts
+    @ambassador.statuses.reblogs.reorder(nil).select(:reblog_of_id)
+  end
+
+  def locally_boostable
+    Status.local.without_reblogs.without_replies.public_local_visibility
+  end
+end