mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
🐛 优化功能开关管理 (#1679)
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
from asyncio.exceptions import TimeoutError
|
||||
|
||||
import nonebot
|
||||
import aiofiles
|
||||
import ujson as json
|
||||
from nonebot.drivers import Driver
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
|
||||
from zhenxun.configs.path_config import TEXT_PATH
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.configs.path_config import TEXT_PATH
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
|
||||
driver: Driver = nonebot.get_driver()
|
||||
|
||||
@@ -19,8 +21,8 @@ async def update_city():
|
||||
这里直接更新,避免插件内代码重复
|
||||
"""
|
||||
china_city = TEXT_PATH / "china_city.json"
|
||||
data = {}
|
||||
if not china_city.exists():
|
||||
data = {}
|
||||
try:
|
||||
logger.debug("开始更新城市列表...")
|
||||
res = await AsyncHttpx.get(
|
||||
@@ -38,7 +40,7 @@ async def update_city():
|
||||
city_data = json.loads(res.text)
|
||||
for city in city_data.keys():
|
||||
data[provinces_data[province]].append(city_data[city])
|
||||
with open(china_city, "w", encoding="utf8") as f:
|
||||
async with aiofiles.open(china_city, "w", encoding="utf8") as f:
|
||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||
logger.info("自动更新城市列表完成.....")
|
||||
except TimeoutError as e:
|
||||
@@ -46,7 +48,7 @@ async def update_city():
|
||||
except ValueError as e:
|
||||
logger.warning("自动城市列表失败.....", e=e)
|
||||
except Exception as e:
|
||||
logger.error(f"自动城市列表未知错误", e=e)
|
||||
logger.error("自动城市列表未知错误", e=e)
|
||||
|
||||
|
||||
# 自动更新城市列表
|
||||
@@ -57,3 +59,27 @@ async def update_city():
|
||||
)
|
||||
async def _():
|
||||
await update_city()
|
||||
|
||||
|
||||
@driver.on_startup
|
||||
async def _():
|
||||
"""开启/禁用插件格式修改"""
|
||||
_, is_create = await GroupConsole.get_or_create(group_id=133133133)
|
||||
"""标记"""
|
||||
if is_create:
|
||||
data_list = []
|
||||
for group in await GroupConsole.all():
|
||||
if group.block_plugin:
|
||||
if modules := group.block_plugin.split(",")[:-1]:
|
||||
if block_plugin := [
|
||||
f"<{module}" for module in modules if not module.startswith("<")
|
||||
]:
|
||||
group.block_plugin = ",".join(block_plugin) + ","
|
||||
if group.block_task:
|
||||
if modules := group.block_task.split(",")[:-1]:
|
||||
if block_task := [
|
||||
f"<{module}" for module in modules if not module.startswith("<")
|
||||
]:
|
||||
group.block_task = ",".join(block_task) + ","
|
||||
data_list.append(group)
|
||||
await GroupConsole.bulk_update(data_list, ["block_plugin", "block_task"], 10)
|
||||
|
||||
Reference in New Issue
Block a user