#11 完了?
このコミットが含まれているのは:
@@ -1,7 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
import atproto
|
import atproto
|
||||||
@@ -10,7 +12,7 @@ from atproto_client.models.app.bsky.feed.get_timeline import Response
|
|||||||
from atproto_client.models.com.atproto.repo.strong_ref import Main
|
from atproto_client.models.com.atproto.repo.strong_ref import Main
|
||||||
|
|
||||||
import account
|
import account
|
||||||
from nizika_ai.consts import QueryType
|
from nizika_ai.consts import Character, GPTModel, Platform, QueryType
|
||||||
from nizika_ai.models import Answer, AnsweredFlag, Query, User
|
from nizika_ai.models import Answer, AnsweredFlag, Query, User
|
||||||
|
|
||||||
TARGET_WORDS = ['deerjika', 'ニジカ', 'ぼっち', '虹夏', '郁代', 'バーカ',
|
TARGET_WORDS = ['deerjika', 'ニジカ', 'ぼっち', '虹夏', '郁代', 'バーカ',
|
||||||
@@ -35,15 +37,17 @@ async def main (
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
await asyncio.gather (like_posts (),
|
await asyncio.gather (like_posts (),
|
||||||
reply (),
|
|
||||||
check_mentions ())
|
check_mentions ())
|
||||||
|
|
||||||
|
|
||||||
async def like_posts (
|
async def like_posts (
|
||||||
) -> None:
|
) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
for post in fetch_target_posts ():
|
for post in fetch_target_posts ():
|
||||||
client.like (**post)
|
client.like (**post)
|
||||||
|
except Exception as e:
|
||||||
|
print (f"[like_posts] { type (e).__name__ }: { e }")
|
||||||
|
|
||||||
await asyncio.sleep (60)
|
await asyncio.sleep (60)
|
||||||
|
|
||||||
@@ -51,6 +55,7 @@ async def like_posts (
|
|||||||
async def check_mentions (
|
async def check_mentions (
|
||||||
) -> None:
|
) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
for uri in check_notifications ():
|
for uri in check_notifications ():
|
||||||
records = fetch_thread_contents (uri, 20)
|
records = fetch_thread_contents (uri, 20)
|
||||||
if records:
|
if records:
|
||||||
@@ -63,6 +68,8 @@ async def check_mentions (
|
|||||||
f"/{ record['embed'].images[0].image.ref.link }")
|
f"/{ record['embed'].images[0].image.ref.link }")
|
||||||
user = _fetch_user (record['did'], record['name'])
|
user = _fetch_user (record['did'], record['name'])
|
||||||
_add_query (user, record['text'], image_url)
|
_add_query (user, record['text'], image_url)
|
||||||
|
except Exception as e:
|
||||||
|
print (f"[check_mentions] { type (e).__name__ }: { e }")
|
||||||
|
|
||||||
await asyncio.sleep (60)
|
await asyncio.sleep (60)
|
||||||
|
|
||||||
@@ -100,11 +107,11 @@ def fetch_thread_contents (
|
|||||||
while res:
|
while res:
|
||||||
records.append ({ 'strong_ref': atproto.models.create_strong_ref (res.post),
|
records.append ({ 'strong_ref': atproto.models.create_strong_ref (res.post),
|
||||||
'did': res.post.author.did,
|
'did': res.post.author.did,
|
||||||
'handle': response.post.author.handle,
|
'handle': res.post.author.handle,
|
||||||
'name': response.post.author.display_name,
|
'name': res.post.author.display_name,
|
||||||
'datetime': response.post.record.created_at,
|
'datetime': res.post.record.created_at,
|
||||||
'text': response.post.record.text,
|
'text': res.post.record.text,
|
||||||
'embed': response.post.record.embed })
|
'embed': res.post.record.embed })
|
||||||
res = res.parent
|
res = res.parent
|
||||||
|
|
||||||
return records
|
return records
|
||||||
@@ -118,7 +125,7 @@ def fetch_target_posts (
|
|||||||
for feed in timeline.feed:
|
for feed in timeline.feed:
|
||||||
if (feed.post.author.did != client.me.did
|
if (feed.post.author.did != client.me.did
|
||||||
and (feed.post.viewer.like is None)
|
and (feed.post.viewer.like is None)
|
||||||
and any (target_word in feed.post.record.text.lower ()
|
and any (target_word in (feed.post.record.text or '').casefold ()
|
||||||
for target_word in TARGET_WORDS)):
|
for target_word in TARGET_WORDS)):
|
||||||
posts.append (LikeParams ({ 'uri': feed.post.uri, 'cid': feed.post.cid }))
|
posts.append (LikeParams ({ 'uri': feed.post.uri, 'cid': feed.post.cid }))
|
||||||
|
|
||||||
@@ -147,10 +154,10 @@ def _fetch_user (
|
|||||||
did: str,
|
did: str,
|
||||||
name: str,
|
name: str,
|
||||||
) -> User:
|
) -> User:
|
||||||
user = User.where ('platform', Platform.BLUESKY).where ('code', did).first ()
|
user = User.where ('platform', Platform.BLUESKY.value).where ('code', did).first ()
|
||||||
if user is None:
|
if user is None:
|
||||||
user = User ()
|
user = User ()
|
||||||
user.platform = Platfrom.BLUESKY
|
user.platform = Platform.BLUESKY.value
|
||||||
user.code = did
|
user.code = did
|
||||||
user.name = name
|
user.name = name
|
||||||
user.save ()
|
user.save ()
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする