Skip to content

Commit a5dae16

Browse files
committed
fix(bilibili): live broadcast on lagrange
1 parent b6f8576 commit a5dae16

File tree

10 files changed

+783
-944
lines changed

10 files changed

+783
-944
lines changed

Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
FROM python:slim
22
WORKDIR /app
3-
ENV PATH=.venv/bin:${PATH} \
4-
PLAYWRIGHT_BROWSERS_PATH=downloads/ms-playwright
3+
ENV PATH=.venv/bin:${PATH}
54

6-
RUN pip install pdm && pip cache purge
5+
RUN pip install pdm; pip cache purge
76
COPY pyproject.toml pdm.lock ./
8-
RUN pdm sync -G docker --prod --no-editable && \
9-
pdm cache clear && \
7+
RUN pdm sync -G docker --prod --no-editable; \
8+
pdm cache clear; \
109
\
11-
pip freeze | xargs pip uninstall -y && \
10+
pip freeze | xargs pip uninstall -y; \
1211
\
13-
playwright install chromium --with-deps && \
14-
apt clean && \
12+
playwright install chromium --with-deps; \
13+
apt clean; \
1514
rm -rf /var/lib/apt/lists/*
1615
COPY . .
1716

18-
CMD nb orm upgrade && nb run
17+
CMD nb orm upgrade; nb run

migrations/versions/bilibili/dynamic/9a8b6ae112db_initial_revision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
创建时间: 2023-12-23 16:39:26.978084
66
77
"""
8+
89
from __future__ import annotations
910

1011
from collections.abc import Sequence

migrations/versions/bilibili/live/770b97dd5299_initial_revision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
创建时间: 2023-11-18 04:43:41.481381
66
77
"""
8+
89
from __future__ import annotations
910

1011
from collections.abc import Sequence

pdm.lock

Lines changed: 737 additions & 908 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ name = ""
33
version = "0.1.0"
44
description = "Twelve"
55
readme = "README.md"
6-
requires-python = "~=3.11"
6+
requires-python = "~=3.12"
77
dependencies = [
88
"backoff~=2.2",
9-
"cachetools~=5.3",
10-
"nonebot2[fastapi,httpx,websockets]~=2.2",
11-
"nonebot-adapter-onebot~=2.3",
12-
"nonebot-plugin-alconna~=0.36,<0.37",
13-
"nonebot-plugin-apscheduler~=0.3",
14-
"nonebot-plugin-guild-patch~=0.2",
15-
"nonebot-plugin-htmlrender~=0.2",
9+
"cachetools~=5.5",
10+
"nonebot2[fastapi,httpx,websockets]~=2.3",
11+
"nonebot-adapter-onebot~=2.4",
12+
"nonebot-plugin-alconna~=0.52",
13+
"nonebot-plugin-apscheduler~=0.5",
14+
"nonebot-plugin-htmlrender~=0.3",
1615
"nonebot-plugin-orm[default]~=0.7",
17-
"nonebot-plugin-sentry~=1.0",
18-
"nonebot-plugin-session~=0.2",
19-
"nonebot-plugin-session-orm~=0.1",
20-
"pydantic~=1.10",
16+
"nonebot-plugin-sentry~=2.0",
17+
"nonebot-plugin-session~=0.3",
18+
"nonebot-plugin-session-orm~=0.2",
19+
"pydantic==2.9.2",
2120
]
2221

2322
[project.optional-dependencies]
@@ -30,7 +29,6 @@ adapters = [
3029
plugins = [
3130
"nonebot_plugin_alconna",
3231
"nonebot_plugin_apscheduler",
33-
"nonebot_plugin_guild_patch",
3432
"nonebot_plugin_htmlrender",
3533
"nonebot_plugin_orm",
3634
"nonebot_plugin_sentry",
@@ -41,9 +39,13 @@ plugin_dirs = ["src/plugins"]
4139
builtin_plugins = []
4240

4341
[tool.pdm.dev-dependencies]
44-
dev = ["black~=23.11", "isort~=5.12", "nonebot-plugin-orm[sqlite]~=0.7"]
42+
dev = [
43+
"black~=24.8",
44+
"isort~=5.13",
45+
"nonebot-plugin-orm[sqlite]~=0.7",
46+
]
4547

4648
[tool.pyright]
4749
enableExperimentalFeatures = true
48-
pythonVersion = "3.11"
50+
pythonVersion = "3.12"
4951
pythonPlatform = "Linux"

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from asyncio import gather
2-
from collections import defaultdict, deque
2+
from collections import defaultdict
33
from contextlib import asynccontextmanager
44
from queue import PriorityQueue
55
from typing import Any, AsyncGenerator
66

77
import backoff
88
from arclet.alconna import Arg
9-
from cachetools import FIFOCache
109
from httpx import AsyncClient
1110
from nonebot import get_driver, get_plugin_config, logger
1211
from nonebot.plugin import PluginMetadata
@@ -278,4 +277,6 @@ async def _(db: async_scoped_session, sess: EventSession):
278277
if not subs:
279278
return await UniMessage(f"没有订阅动态").send()
280279

281-
await UniMessage("已订阅动态:\n" + "\n".join(f"UID:{sub.uid}" for sub in subs)).send()
280+
await UniMessage(
281+
"已订阅动态:\n" + "\n".join(f"UID:{sub.uid}" for sub in subs)
282+
).send()

src/plugins/bilibili/plugins/live/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ async def broadcast(uids: list[str]) -> None:
9797
url = await get_share_click(
9898
info["room_id"], "vertical-three-point", "live.live-room-detail.0.0.pv"
9999
)
100+
cover = (await client.get(info["cover_from_user"] or info["face"])).content
101+
100102
for sub in room_subs[uid]:
101103
tasks.append(
102104
send_message(
103105
sub.session.session,
104-
plugin_config.live_template.format(url=url, **info),
106+
plugin_config.live_template.format(
107+
url=url,
108+
**info,
109+
),
105110
)
106111
)
112+
tasks.append(
113+
send_message(sub.session.session, UniMessage.image(raw=cover))
114+
)
107115
else:
108116
for sub in room_subs[uid]:
109117
tasks.append(

src/plugins/bilibili/plugins/live/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Config(BaseModel):
99
interval: int = 1
1010
live_template: UniMessageTemplate = UniMessage.template(
11-
"{:AtAll()} {uname} 正在直播 {title}{:Image(url=cover_from_user)}{url}"
11+
"{:AtAll()} {uname} 正在直播 {title}\n{url}"
1212
)
1313
preparing_template: UniMessageTemplate = UniMessage.template("{uname} 下锅了")
1414

src/plugins/bilibili/plugins/live/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class RoomInfo(TypedDict):
1313
live_time: int
1414
live_status: int
1515
uname: str
16+
face: str
1617
cover_from_user: str
1718

1819

src/utils.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def send_message(sess: Session, msg: UniMessage) -> Receipt:
7070
target = session_to_target(sess)
7171

7272
if isinstance(bot, OneBot11Bot) and not target.private and AtAll in msg:
73-
remain = await bot.get_group_at_all_remain(group_id=target.parent_id)
73+
remain = await bot.get_group_at_all_remain(group_id=int(target.parent_id))
7474
if not all(
7575
itemgetter(
7676
"can_at_all",
@@ -103,20 +103,17 @@ def _regex_str_dependency(
103103

104104

105105
@overload
106-
def RegexStr(__group: Literal[0] = 0) -> str:
107-
...
106+
def RegexStr(__group: Literal[0] = 0) -> str: ...
108107

109108

110109
@overload
111-
def RegexStr(__group: str | int) -> str | Any:
112-
...
110+
def RegexStr(__group: str | int) -> str | Any: ...
113111

114112

115113
@overload
116114
def RegexStr(
117115
__group1: str | int, __group2: str | int, *groups: str | int
118-
) -> tuple[str | Any, ...]:
119-
...
116+
) -> tuple[str | Any, ...]: ...
120117

121118

122119
def RegexStr(*groups: str | int) -> str | tuple[str | Any, ...] | Any:

0 commit comments

Comments
 (0)