mirror of
https://ghfast.top/https://github.com/discourse/discourse-akismet.git
synced 2026-07-15 11:36:24 +08:00
* FEATURE: Implement Akismet flag and review system for PostVotingComments * polished bugs and completed reviewables implementation * adding test plugin dependecies * rubocop fix * syntax tree fix * deleted comments * added requested changes * linter fixes * refactored #before_check in post voting bouncer
32 lines
1 KiB
Ruby
32 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class CheckForSpamPosts < ::Jobs::Scheduled
|
|
every SiteSetting.spam_check_interval_mins.minutes
|
|
|
|
def execute(args)
|
|
return unless SiteSetting.akismet_enabled?
|
|
return if DiscourseAkismet::AntiSpamService.api_secret_blank?
|
|
|
|
bouncer = DiscourseAkismet::PostsBouncer.new
|
|
client = DiscourseAkismet::AntiSpamService.client
|
|
spam_count = 0
|
|
|
|
DiscourseAkismet::PostsBouncer
|
|
.to_check
|
|
.where(user_deleted: false)
|
|
.find_each do |post|
|
|
DistributedMutex.synchronize("akismet_post_#{post.id}") do
|
|
if post.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE] ==
|
|
DiscourseAkismet::Bouncer::PENDING_STATE
|
|
spam_count += 1 if bouncer.perform_check(client, post)
|
|
end
|
|
end
|
|
end
|
|
|
|
# Trigger an event that akismet found spam. This allows people to
|
|
# notify chat rooms or whatnot
|
|
DiscourseEvent.trigger(:akismet_found_spam, spam_count) if spam_count > 0
|
|
end
|
|
end
|
|
end
|