みてるぞ 1 week ago
parent
commit
6cec86ddbd
1 changed files with 7 additions and 4 deletions
  1. +7
    -4
      backend/lib/tasks/sync_nico.rake

+ 7
- 4
backend/lib/tasks/sync_nico.rake View File

@@ -44,13 +44,16 @@ namespace :nico do
new_tags = datum['tags'].map { |tag| "nico:#{ tag }" }.sort
if current_tags != new_tags
post.tags.destroy(post.tags.where(name: current_tags))
tags_to_add = []
new_tags.each do |name|
post.tags << Tag.find_or_initialize_by(name:) do |tag|
tag.category = 'nico'
tag = Tag.find_or_initialize_by(name:) do |t|
t.category = 'nico'
end
tags_to_add.concat([tag] + tag.linked_tags)
end
post.tags << Tag.tagme if post.tags.size < 20 && post.tags.none?(Tag.tagme)
post.tags << Tag.bot if post.tags.none?(Tag.bot)
tags_to_add << Tag.tagme if post.tags.size < 20
tags_to_add << Tag.bot
post.tags.concat(tags_to_add).uniq!
end
end
end


Loading…
Cancel
Save