feat: 포스트를 만들 때 날씨각 캐릭터(해님·구름·달님) 댓글 1~2개 — '날씨각' 표시, 신고·차단 메뉴 없음, 이미 만든 날은 scripts/fill_bot_comments.py

This commit is contained in:
minaChoi committed 2026-10-27 13:14:30 +09:00
1 parent d32e24a5ab
commit 98b5c0cbe3
19 files changed
+864 -4

No files matched your search

+18 -2
View File
@@ -1,11 +1,11 @@
from datetime import date
from typing import Optional
from sqlalchemy import select
from sqlalchemy import exists, select, update
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.asyncio import AsyncSession
from common.database.model.models import Post
from common.database.model.models import Comment, Post
class FeedCRUD:
@@ -21,6 +21,22 @@ class FeedCRUD:
if rows:
await s.execute(insert(Post).values(rows).on_conflict_do_nothing())
async def without_bot(self, s: AsyncSession, day: date) -> list[Post]:
"""그날 포스트 중 캐릭터 댓글이 아직 없는 것."""
has_bot = exists().where(Comment.post_id == Post.post_id, Comment.bot.is_not(None))
return list((await s.scalars(select(Post).where(Post.feed_date == day, Post.deleted.is_(False), ~has_bot))).all())
async def add_bot_comments(self, s: AsyncSession, lines: dict[int, list[tuple[str, str]]]) -> None:
"""캐릭터 댓글을 넣고 포스트 댓글 수를 늘린다. 같은 포스트·캐릭터는 한 번만 (동시에 불려도 겹치지 않게)."""
rows = [{"post_id": post_id, "bot": bot, "body": body} for post_id, x in lines.items() for bot, body in x]
if not rows:
return
added = (await s.execute(insert(Comment).values(rows).on_conflict_do_nothing().returning(Comment.post_id))).scalars().all()
for n in (1, 2):
ids = [post_id for post_id in set(added) if added.count(post_id) == n]
if ids:
await s.execute(update(Post).where(Post.post_id.in_(ids)).values(comment_count=Post.comment_count + n))
async def get(self, s: AsyncSession, post_id: int) -> Optional[Post]:
post = await s.get(Post, post_id)
return post if post is not None and not post.deleted else None