nonebot-plugin-bililive 2.1.3__tar.gz → 2.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/PKG-INFO +1 -1
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/database/db.py +52 -13
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/utils/__init__.py +3 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/version.py +1 -1
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/pyproject.toml +1 -1
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/LICENSE +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/README.md +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/__main__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/bilibili_api.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/cli/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/cli/bot.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/cli/utils.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/config.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/database/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/database/models.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/card.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/desc.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/display.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/user_profile.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/libs/dynamic/web.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/at/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/at/at_off.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/at/at_on.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/auto_agree.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/auto_delete.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/dynamic/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/dynamic/dynamic_off.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/dynamic/dynamic_on.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/help.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/live/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/live/live_now.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/live/live_off.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/live/live_on.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/permission/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/permission/permission_off.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/permission/permission_on.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/pusher/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/pusher/dynamic_pusher.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/pusher/live_pusher.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/sub/__init__.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/sub/add_sub.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/sub/delete_sub.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/plugins/sub/sub_list.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/utils/browser.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/utils/captcha_solver.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/utils/fonts_provider.py +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/utils/mobile.js +0 -0
- {nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/tests/test_maintenance.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nonebot-plugin-bililive
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.5
|
|
4
4
|
Summary: Push bilibili dynamics and live notifications to QQ with NoneBot2.
|
|
5
5
|
Keywords: nonebot,nonebot2,nonebot-plugin,bilibili,onebot,onebot-v11
|
|
6
6
|
Author-Email: Akiyy_Lab <2806578374@qq.com>
|
|
@@ -5,7 +5,6 @@ from pathlib import Path
|
|
|
5
5
|
from nonebot import get_driver, logger
|
|
6
6
|
from packaging.version import Version as version_parser
|
|
7
7
|
from tortoise import Tortoise
|
|
8
|
-
from tortoise.connection import connections
|
|
9
8
|
|
|
10
9
|
from ..utils import get_path
|
|
11
10
|
from ..version import VERSION as APP_VERSION
|
|
@@ -14,6 +13,8 @@ from .models import Group, Sub, User, Version
|
|
|
14
13
|
uid_list = {"live": {"list": [], "index": 0}, "dynamic": {"list": [], "index": 0}}
|
|
15
14
|
dynamic_offset = {}
|
|
16
15
|
|
|
16
|
+
_db_init_lock = asyncio.Lock()
|
|
17
|
+
|
|
17
18
|
|
|
18
19
|
class DB:
|
|
19
20
|
"""数据库交互类,与增删改查无关的部分不应该在这里面实现"""
|
|
@@ -25,15 +26,18 @@ class DB:
|
|
|
25
26
|
return Path(get_path("dynamic_offset.json"))
|
|
26
27
|
|
|
27
28
|
@classmethod
|
|
28
|
-
|
|
29
|
-
"""
|
|
29
|
+
def _orm_context_ok(cls) -> bool:
|
|
30
|
+
"""_ready 与 Tortoise 1.x 全局上下文需同时成立,否则会出现 No TortoiseContext。"""
|
|
31
|
+
from tortoise.context import get_current_context
|
|
32
|
+
|
|
33
|
+
return cls._ready and get_current_context() is not None
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
async def _do_init(cls) -> None:
|
|
37
|
+
"""在持有 _db_init_lock 时执行完整初始化。"""
|
|
30
38
|
cls._ready = False
|
|
31
39
|
config = {
|
|
32
40
|
"connections": {
|
|
33
|
-
# "bililive": {
|
|
34
|
-
# "engine": "tortoise.backends.sqlite",
|
|
35
|
-
# "credentials": {"file_path": get_path("data.sqlite3")},
|
|
36
|
-
# },
|
|
37
41
|
"bililive": f"sqlite://{get_path('data.sqlite3')}"
|
|
38
42
|
},
|
|
39
43
|
"apps": {
|
|
@@ -53,26 +57,61 @@ class DB:
|
|
|
53
57
|
await cls.save_dynamic_offsets()
|
|
54
58
|
cls._ready = True
|
|
55
59
|
|
|
60
|
+
@classmethod
|
|
61
|
+
async def init(cls):
|
|
62
|
+
"""初始化数据库"""
|
|
63
|
+
async with _db_init_lock:
|
|
64
|
+
await cls._do_init()
|
|
65
|
+
|
|
56
66
|
@classmethod
|
|
57
67
|
async def close(cls):
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
async with _db_init_lock:
|
|
69
|
+
cls._ready = False
|
|
70
|
+
await cls.save_dynamic_offsets()
|
|
71
|
+
await Tortoise.close_connections()
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
async def _recover_stale_orm(cls) -> None:
|
|
75
|
+
"""_ready 仍为 True 但 Tortoise 上下文已丢失时,关闭并重新初始化。"""
|
|
76
|
+
async with _db_init_lock:
|
|
77
|
+
from tortoise.context import get_current_context
|
|
78
|
+
|
|
79
|
+
if get_current_context() is not None:
|
|
80
|
+
return
|
|
81
|
+
if not cls._ready:
|
|
82
|
+
return
|
|
83
|
+
logger.warning(
|
|
84
|
+
"Tortoise ORM 上下文已失效(可能被其他代码关闭连接),"
|
|
85
|
+
"正在重新初始化数据库"
|
|
86
|
+
)
|
|
87
|
+
try:
|
|
88
|
+
await Tortoise.close_connections()
|
|
89
|
+
except Exception:
|
|
90
|
+
logger.exception("关闭 Tortoise 连接时出错,仍将尝试重新初始化")
|
|
91
|
+
cls._ready = False
|
|
92
|
+
await cls._do_init()
|
|
61
93
|
|
|
62
94
|
@classmethod
|
|
63
95
|
async def wait_until_ready(cls, timeout: float = 30) -> bool:
|
|
64
|
-
if cls.
|
|
96
|
+
if cls._orm_context_ok():
|
|
65
97
|
return True
|
|
66
98
|
|
|
67
99
|
waited = 0.0
|
|
68
100
|
interval = 0.1
|
|
69
101
|
while waited < timeout:
|
|
70
|
-
if cls.
|
|
102
|
+
if cls._orm_context_ok():
|
|
71
103
|
return True
|
|
104
|
+
if cls._ready:
|
|
105
|
+
from tortoise.context import get_current_context
|
|
106
|
+
|
|
107
|
+
if get_current_context() is None:
|
|
108
|
+
await cls._recover_stale_orm()
|
|
109
|
+
if cls._orm_context_ok():
|
|
110
|
+
return True
|
|
72
111
|
await asyncio.sleep(interval)
|
|
73
112
|
waited += interval
|
|
74
113
|
|
|
75
|
-
return cls.
|
|
114
|
+
return cls._orm_context_ok()
|
|
76
115
|
|
|
77
116
|
@classmethod
|
|
78
117
|
async def load_dynamic_offsets(cls):
|
|
@@ -164,6 +164,9 @@ async def permission_check(
|
|
|
164
164
|
raise FinishedException
|
|
165
165
|
return
|
|
166
166
|
if isinstance(event, GroupMessageEvent):
|
|
167
|
+
if not await db.wait_until_ready():
|
|
168
|
+
await bot.send(event, "数据库尚未初始化完成,请稍后再试")
|
|
169
|
+
raise FinishedException
|
|
167
170
|
if not await db.get_group_admin(event.group_id):
|
|
168
171
|
return
|
|
169
172
|
if await (GROUP_ADMIN | GROUP_OWNER | SUPERUSER)(bot, event):
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/__init__.py
RENAMED
|
File without changes
|
{nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/__main__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/cli/bot.py
RENAMED
|
File without changes
|
{nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/cli/utils.py
RENAMED
|
File without changes
|
{nonebot_plugin_bililive-2.1.3 → nonebot_plugin_bililive-2.1.5}/nonebot_plugin_bililive/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|