Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve spam logic in post livecomments #21

Merged
merged 1 commit into from Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions webapp/ruby/app.rb
Expand Up @@ -598,20 +598,11 @@ def batch_fill_user_response(tx, user_models)
end

# スパム判定
tx.xquery('SELECT id, user_id, livestream_id, word FROM ng_words WHERE user_id = ? AND livestream_id = ?', livestream_model.fetch(:user_id), livestream_model.fetch(:id)).each do |ng_word|
query = <<~SQL
SELECT COUNT(*)
FROM
(SELECT ? AS text) AS texts
INNER JOIN
(SELECT CONCAT('%', ?, '%') AS pattern) AS patterns
ON texts.text LIKE patterns.pattern
SQL
hit_spam = tx.xquery(query, req.comment, ng_word.fetch(:word), as: :array).first[0]
logger.info("[hit_spam=#{hit_spam}] comment = #{req.comment}")
if hit_spam >= 1
raise HttpError.new(400, 'このコメントがスパム判定されました')
end
ng_words = tx.xquery('SELECT word FROM ng_words WHERE user_id = ? AND livestream_id = ?', livestream_model.fetch(:user_id), livestream_model.fetch(:id))
hit_spam = ng_words.count { |ng_word| req.comment.include?(ng_word.fetch(:word)) }
logger.info("[hit_spam=#{hit_spam}] comment = #{req.comment}")
if hit_spam >= 1
raise HttpError.new(400, 'このコメントがスパム判定されました')
end

now = Time.now.to_i
Expand Down