From b068a9466c33b464a2215051ce4b1ca980f4f4eb Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Mon, 17 Feb 2020 19:41:56 -0600 Subject: implement our fork of @mykola@weirder.earth's ambassador bot (@ambassador@monsterpit.net) within monsterfork itself --- app/workers/scheduler/ambassador_scheduler.rb | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/workers/scheduler/ambassador_scheduler.rb (limited to 'app/workers') 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 -- cgit