Skip to content

Commit 909033f

Browse files
committed
feat(bilibili): dynamic at propagation
1 parent 5eff051 commit 909033f

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/plugins/bilibili/plugins/dynamic/__init__.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,43 @@ async def get_dynamics(page: int = 1) -> Dynamics:
146146

147147

148148
async def broadcast(dynamic: Dynamic):
149+
uids = {str(dynamic["modules"]["module_author"]["mid"])}
150+
151+
if dynamic["type"] in (
152+
"DYNAMIC_TYPE_DRAW",
153+
"DYNAMIC_TYPE_WORD",
154+
"DYNAMIC_TYPE_FORWARD",
155+
):
156+
if dynamic["type"] == "DYNAMIC_TYPE_FORWARD":
157+
nodes = dynamic["modules"]["module_dynamic"]["desc"]["rich_text_nodes"]
158+
else:
159+
nodes = dynamic["modules"]["module_dynamic"]["major"]["opus"]["summary"][
160+
"rich_text_nodes"
161+
]
162+
163+
for node in nodes:
164+
if node["type"] == "RICH_TEXT_NODE_TYPE_AT":
165+
uids.add(node["rid"])
166+
167+
sessions = {sub.session for uid in uids for sub in dynamic_subs.get(uid, ())}
168+
169+
if not sessions:
170+
return
171+
149172
screenshot, url = await gather(
150173
render_screenshot(dynamic),
151174
get_share_click(dynamic["id_str"], "dynamic", "dt.dt-detail.0.0.pv"),
152175
)
153-
await gather(
154-
*[
155-
send_message(
156-
sub.session.session,
157-
plugin_config.template.format(
158-
name=dynamic["modules"]["module_author"]["name"],
159-
action=dynamic["modules"]["module_author"]["pub_action"]
160-
or plugin_config.types[dynamic["type"]],
161-
screenshot=Image(raw=screenshot),
162-
url=url,
163-
),
164-
)
165-
for sub in dynamic_subs[str(dynamic["modules"]["module_author"]["mid"])]
166-
]
176+
message = plugin_config.template.format(
177+
name=dynamic["modules"]["module_author"]["name"],
178+
action=dynamic["modules"]["module_author"]["pub_action"]
179+
or plugin_config.types[dynamic["type"]],
180+
screenshot=Image(raw=screenshot),
181+
url=url,
167182
)
168183

184+
await gather(*(send_message(sess.session, message) for sess in sessions))
185+
169186

170187
@backoff.on_exception(backoff.constant, TimeoutError, max_tries=3)
171188
async def render_screenshot(dynamic: Dynamic) -> bytes:

src/plugins/bilibili/plugins/dynamic/models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import Any, TypedDict
22

33
from nonebot_plugin_orm import Model
44
from nonebot_plugin_session_orm import SessionModel
@@ -12,9 +12,17 @@ class ModuleAuthor(TypedDict):
1212
pub_action: str
1313

1414

15+
type ModuleDynamic = dict[str, Any]
16+
17+
18+
class Modules(TypedDict):
19+
module_author: ModuleAuthor
20+
module_dynamic: ModuleDynamic
21+
22+
1523
class Dynamic(TypedDict):
1624
id_str: str
17-
modules: dict[{"module_author": ModuleAuthor}]
25+
modules: Modules
1826
type: str
1927

2028

0 commit comments

Comments
 (0)