|
1 | 1 | from asyncio import gather |
2 | 2 | from collections import defaultdict |
3 | 3 | from contextlib import asynccontextmanager |
| 4 | +from functools import reduce |
| 5 | +from itertools import repeat |
| 6 | +from operator import or_ |
4 | 7 | from queue import PriorityQueue |
5 | 8 | from typing import Any, AsyncGenerator |
6 | 9 |
|
@@ -146,24 +149,49 @@ async def get_dynamics(page: int = 1) -> Dynamics: |
146 | 149 |
|
147 | 150 |
|
148 | 151 | 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 | + |
149 | 175 | screenshot, url = await gather( |
150 | 176 | render_screenshot(dynamic), |
151 | 177 | get_share_click(dynamic["id_str"], "dynamic", "dt.dt-detail.0.0.pv"), |
152 | 178 | ) |
| 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 | + |
153 | 187 | await gather( |
154 | | - *[ |
| 188 | + *( |
155 | 189 | send_message( |
156 | 190 | 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, |
164 | 192 | ) |
165 | | - for sub in dynamic_subs[str(dynamic["modules"]["module_author"]["mid"])] |
166 | | - ] |
| 193 | + for sub in subs |
| 194 | + ) |
167 | 195 | ) |
168 | 196 |
|
169 | 197 |
|
|
0 commit comments