Skip to content

Commit 84bb592

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

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from asyncio import gather
22
from collections import defaultdict
33
from contextlib import asynccontextmanager
4+
from functools import reduce
5+
from itertools import repeat
6+
from operator import or_
47
from queue import PriorityQueue
58
from typing import Any, AsyncGenerator
69

@@ -146,24 +149,49 @@ async def get_dynamics(page: int = 1) -> Dynamics:
146149

147150

148151
async def broadcast(dynamic: Dynamic):
152+
uids = {str(dynamic["modules"]["module_author"]["mid"])}
153+
154+
if dynamic["type"] in (
155+
"DYNAMIC_TYPE_DRAW",
156+
"DYNAMIC_TYPE_WORD",
157+
"DYNAMIC_TYPE_FORWARD",
158+
):
159+
if dynamic["type"] == "DYNAMIC_TYPE_FORWARD":
160+
nodes = dynamic["modules"]["module_dynamic"]["desc"]["rich_text_nodes"]
161+
else:
162+
nodes = dynamic["modules"]["module_dynamic"]["major"]["opus"]["summary"][
163+
"rich_text_nodes"
164+
]
165+
166+
for node in nodes:
167+
if node["type"] == "RICH_TEXT_NODE_TYPE_AT":
168+
uids.add(node["rid"])
169+
170+
subs = reduce(or_, map(dynamic_subs.get, uids, repeat(set())))
171+
172+
if not subs:
173+
return
174+
149175
screenshot, url = await gather(
150176
render_screenshot(dynamic),
151177
get_share_click(dynamic["id_str"], "dynamic", "dt.dt-detail.0.0.pv"),
152178
)
179+
message = plugin_config.template.format(
180+
name=dynamic["modules"]["module_author"]["name"],
181+
action=dynamic["modules"]["module_author"]["pub_action"]
182+
or plugin_config.types[dynamic["type"]],
183+
screenshot=Image(raw=screenshot),
184+
url=url,
185+
)
186+
153187
await gather(
154-
*[
188+
*(
155189
send_message(
156190
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-
),
191+
message,
164192
)
165-
for sub in dynamic_subs[str(dynamic["modules"]["module_author"]["mid"])]
166-
]
193+
for sub in subs
194+
)
167195
)
168196

169197

0 commit comments

Comments
 (0)