From 2e994c2eb1da4cccf955c075b740e5eb0a35e67d Mon Sep 17 00:00:00 2001 From: Agnes Digital Date: Wed, 6 Dec 2023 09:33:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80v0.6.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_l4d2_server/__init__.py | 3 +- .../l4d2_file/__init__.py | 4 +-- .../l4d2_push/__init__.py | 35 +++++++++++-------- pyproject.toml | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/nonebot_plugin_l4d2_server/__init__.py b/nonebot_plugin_l4d2_server/__init__.py index 8fcd91c..ed264df 100644 --- a/nonebot_plugin_l4d2_server/__init__.py +++ b/nonebot_plugin_l4d2_server/__init__.py @@ -34,6 +34,7 @@ # from .l4d2_file.input_json import * from .l4d2_image.steam import url_to_byte_name +from .l4d2_push import scheduler # noqa: F401 from .l4d2_utils.command import help_, search_api from .l4d2_utils.config import l4_config from .l4d2_utils.utils import upload_file @@ -41,7 +42,7 @@ driver = get_driver() -__version__ = "0.6.4" +__version__ = "0.6.5" __plugin_meta__ = PluginMetadata( name="求生之路小助手", description="可用于管理求生之路查服和本地管理", diff --git a/nonebot_plugin_l4d2_server/l4d2_file/__init__.py b/nonebot_plugin_l4d2_server/l4d2_file/__init__.py index 7bd85e8..363dd12 100644 --- a/nonebot_plugin_l4d2_server/l4d2_file/__init__.py +++ b/nonebot_plugin_l4d2_server/l4d2_file/__init__.py @@ -2,13 +2,13 @@ from pathlib import Path from typing import Tuple -from nonebot import on_command, on_notice, on_regex +from nonebot import on_command, on_regex from nonebot.adapters.onebot.v11 import Event, Message, NoticeEvent from nonebot.log import logger from nonebot.matcher import Matcher from nonebot.params import ArgPlainText, CommandArg, RegexGroup -from nonebot.typing import T_State +# from nonebot.typing import T_State from ..l4d2_utils.config import MASTER, config_manager, file_format, l4_config, vpk_path from ..l4d2_utils.rule import wenjian from ..l4d2_utils.txt_to_img import mode_txt_to_img diff --git a/nonebot_plugin_l4d2_server/l4d2_push/__init__.py b/nonebot_plugin_l4d2_server/l4d2_push/__init__.py index b7de491..7ee3ad5 100644 --- a/nonebot_plugin_l4d2_server/l4d2_push/__init__.py +++ b/nonebot_plugin_l4d2_server/l4d2_push/__init__.py @@ -15,6 +15,7 @@ from nonebot.matcher import Matcher from nonebot.params import CommandArg from nonebot.permission import SUPERUSER +from nonebot_plugin_saa import MessageFactory from ..l4d2_queries import get_ip_to_mes from ..l4d2_queries.utils import json_server_to_tag_dict @@ -22,8 +23,10 @@ from ..l4d2_utils.utils import extract_last_digit, split_maohao require("nonebot_plugin_apscheduler") -# from nonebot_plugin_apscheduler import scheduler - +try: + scheduler = require("nonebot_plugin_apscheduler").scheduler +except Exception: + scheduler = None driver = get_driver() sch_json = Path("data/L4D2/scheduler.json") if not sch_json.exists(): @@ -58,12 +61,13 @@ async def _(event: GroupMessageEvent, matcher: Matcher, args: Message = CommandA await matcher.finish("无响应的服务器,请检查") else: return_msg = await add_or_update_data(group_id, msg) - if isinstance(push_msg, bytes): - await matcher.finish(MessageSegment.image(push_msg)) - elif isinstance(push_msg, Union[Message, MessageSegment]): - await matcher.finish(push_msg) - else: - await matcher.send(push_msg) + await MessageFactory(push_msg).send() + # if isinstance(push_msg, bytes): + # await matcher.finish(MessageSegment.image(push_msg)) + # elif isinstance(push_msg, Union[Message, MessageSegment]): + # await matcher.finish(push_msg) + # else: + # await matcher.send(push_msg) if return_msg == "add": await matcher.send(f"已添加群定时任务【{msg}】{l4_config.l4_push_times}次") elif return_msg in ["update", "change"]: @@ -209,11 +213,14 @@ async def send_message( async def server_is_change(): """检测服务器是否发生变化""" + ... -# @driver.on_bot_connect -# async def _(): -# logger.success("已成功启动求生定时推送") -# scheduler.add_job( -# rss_ip, "interval", minutes=l4_config.l4_push_interval, id="rss_ip" -# ) +if scheduler: + logger.success("已成功启动求生定时推送") + scheduler.add_job( + rss_ip, + "interval", + minutes=l4_config.l4_push_interval, + id="rss_ip", + ) diff --git a/pyproject.toml b/pyproject.toml index b9cc16f..d0f8538 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-plugin-l4d2-server" -version = "0.6.4-post3" +version = "0.6.5" description = "L4D2 server related operations plugin for NoneBot2" authors = [ { name = "Agnes_Digital", email = "Z735803792@163.com" }