Skip to content

Commit 028db71

Browse files
authored
Merge pull request #42 from Agnes4m/dev-main
v0.6.5
2 parents 3dbee72 + 2e994c2 commit 028db71

File tree

8 files changed

+66
-94
lines changed

8 files changed

+66
-94
lines changed

nonebot_plugin_l4d2_server/__init__.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434

3535
# from .l4d2_file.input_json import *
3636
from .l4d2_image.steam import url_to_byte_name
37+
from .l4d2_push import scheduler # noqa: F401
3738
from .l4d2_utils.command import help_, search_api
3839
from .l4d2_utils.config import l4_config
3940
from .l4d2_utils.utils import upload_file
4041
from .l4d2_web import web, webUI # noqa: F401
4142

4243
driver = get_driver()
4344

44-
__version__ = "0.6.4"
45+
__version__ = "0.6.5"
4546
__plugin_meta__ = PluginMetadata(
4647
name="求生之路小助手",
4748
description="可用于管理求生之路查服和本地管理",
@@ -59,18 +60,6 @@
5960
"""相当于启动就检查数据库"""
6061

6162

62-
# @search_api.handle()
63-
# async def _(matcher:Matcher,state:T_State,event:GroupMessageEvent,args:Message = CommandArg()): # noqa: E501
64-
# msg:str = args.extract_plain_text()
65-
# # if msg.startswith('代码'):
66-
# # 建图代码返回三方图信息
67-
# data = await seach_map(msg,l4_config.l4_master[0],l4_config.l4_key)
68-
# # else:
69-
# if type(data) == str:
70-
# await matcher.finish(data)
71-
# else:
72-
# state['maps'] = data
73-
# await matcher.send(await map_dict_to_str(data))
7463
@help_.handle()
7564
async def _(matcher: Matcher):
7665
msg = """=====求生机器人帮助=====
@@ -80,7 +69,10 @@ async def _(matcher: Matcher):
8069
4、创意工坊下载【创意工坊下载[物品id/链接]】
8170
5、指定ip查询【求生ip[ip]】(可以是域名)
8271
6、求生喷漆制作【求生喷漆】
83-
7、本地服务器操作(略,详情看项目地址)
72+
7、本地服务器相关【l4地图上传】【l4地图改名】【l4地图删除】【l4路径】【l4插件】
73+
8、ip导入(私聊发送json文件,格式参考下方链接中readme)
74+
9、内置ip更新【l4公益服更新】【求生更新anne】
75+
项目地址:https://github.com/Agnes4m/nonebot_plugin_l4d2_server
8476
"""
8577
await matcher.finish(msg)
8678

nonebot_plugin_l4d2_server/l4d2_file/__init__.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,70 @@
22
from pathlib import Path
33
from typing import Tuple
44

5-
from nonebot import on_command, on_notice, on_regex
6-
from nonebot.adapters.onebot.v11 import Message, NoticeEvent
5+
from nonebot import on_command, on_regex
6+
from nonebot.adapters.onebot.v11 import Event, Message, NoticeEvent
77
from nonebot.log import logger
88
from nonebot.matcher import Matcher
99
from nonebot.params import ArgPlainText, CommandArg, RegexGroup
1010

11+
# from nonebot.typing import T_State
1112
from ..l4d2_utils.config import MASTER, config_manager, file_format, l4_config, vpk_path
1213
from ..l4d2_utils.rule import wenjian
1314
from ..l4d2_utils.txt_to_img import mode_txt_to_img
1415
from ..l4d2_utils.utils import del_map, get_vpk, mes_list, rename_map
1516
from .input_json import upload # noqa: F401
1617
from .utils import updown_l4d2_vpk
1718

18-
up = on_notice(rule=wenjian)
19+
up = on_command(
20+
"l4_upload",
21+
aliases={"l4地图上传"},
22+
priority=20,
23+
block=True,
24+
)
1925

2026

2127
rename_vpk = on_regex(
22-
r"^求生地图\s*(\S+.*?)\s*(改|改名)?\s*(\S+.*?)\s*$",
28+
r"^l4地图\s*(\S+.*?)\s*(改|改名)?\s*(\S+.*?)\s*$",
2329
flags=re.S,
2430
block=True,
2531
priority=20,
2632
permission=MASTER,
2733
)
2834

29-
find_vpk = on_command("l4_map", aliases={"求生地图"}, priority=25, block=True)
35+
find_vpk = on_command("l4_map", aliases={"l4地图"}, priority=25, block=True)
3036
del_vpk = on_command(
3137
"l4_del_map",
32-
aliases={"求生地图删除", "地图删除"},
38+
aliases={"l4地图删除", "地图删除"},
3339
priority=20,
3440
permission=MASTER,
3541
)
3642

3743

3844
check_path = on_command(
3945
"l4_check",
40-
aliases={"求生路径"},
46+
aliases={"l4路径"},
4147
priority=20,
4248
block=True,
4349
permission=MASTER,
4450
)
4551
smx_file = on_command(
4652
"l4_smx",
47-
aliases={"求生插件"},
53+
aliases={"l4插件"},
4854
priority=20,
4955
block=True,
5056
permission=MASTER,
5157
)
5258

5359

5460
@up.handle()
55-
async def _(matcher: Matcher, event: NoticeEvent):
56-
if not l4_config.l4_group_upload:
61+
async def _():
62+
...
63+
64+
65+
@up.got("map_url", prompt="图来")
66+
async def _(matcher: Matcher, event: Event):
67+
if not isinstance(event, NoticeEvent) or not wenjian(event):
68+
await matcher.finish("未检测到地图")
5769
return
5870
args = event.dict()
5971
if args["notice_type"] != "offline_file":

nonebot_plugin_l4d2_server/l4d2_push/__init__.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
from nonebot.matcher import Matcher
1616
from nonebot.params import CommandArg
1717
from nonebot.permission import SUPERUSER
18+
from nonebot_plugin_saa import MessageFactory
1819

1920
from ..l4d2_queries import get_ip_to_mes
2021
from ..l4d2_queries.utils import json_server_to_tag_dict
2122
from ..l4d2_utils.config import l4_config
2223
from ..l4d2_utils.utils import extract_last_digit, split_maohao
2324

2425
require("nonebot_plugin_apscheduler")
25-
# from nonebot_plugin_apscheduler import scheduler
26-
26+
try:
27+
scheduler = require("nonebot_plugin_apscheduler").scheduler
28+
except Exception:
29+
scheduler = None
2730
driver = get_driver()
2831
sch_json = Path("data/L4D2/scheduler.json")
2932
if not sch_json.exists():
@@ -58,12 +61,13 @@ async def _(event: GroupMessageEvent, matcher: Matcher, args: Message = CommandA
5861
await matcher.finish("无响应的服务器,请检查")
5962
else:
6063
return_msg = await add_or_update_data(group_id, msg)
61-
if isinstance(push_msg, bytes):
62-
await matcher.finish(MessageSegment.image(push_msg))
63-
elif isinstance(push_msg, Union[Message, MessageSegment]):
64-
await matcher.finish(push_msg)
65-
else:
66-
await matcher.send(push_msg)
64+
await MessageFactory(push_msg).send()
65+
# if isinstance(push_msg, bytes):
66+
# await matcher.finish(MessageSegment.image(push_msg))
67+
# elif isinstance(push_msg, Union[Message, MessageSegment]):
68+
# await matcher.finish(push_msg)
69+
# else:
70+
# await matcher.send(push_msg)
6771
if return_msg == "add":
6872
await matcher.send(f"已添加群定时任务【{msg}{l4_config.l4_push_times}次")
6973
elif return_msg in ["update", "change"]:
@@ -209,11 +213,14 @@ async def send_message(
209213

210214
async def server_is_change():
211215
"""检测服务器是否发生变化"""
216+
...
212217

213218

214-
# @driver.on_bot_connect
215-
# async def _():
216-
# logger.success("已成功启动求生定时推送")
217-
# scheduler.add_job(
218-
# rss_ip, "interval", minutes=l4_config.l4_push_interval, id="rss_ip"
219-
# )
219+
if scheduler:
220+
logger.success("已成功启动求生定时推送")
221+
scheduler.add_job(
222+
rss_ip,
223+
"interval",
224+
minutes=l4_config.l4_push_interval,
225+
id="rss_ip",
226+
)

nonebot_plugin_l4d2_server/l4d2_queries/__init__.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from nonebot.log import logger
99
from nonebot.matcher import Matcher
1010
from nonebot.params import ArgPlainText, CommandArg, CommandStart, Keyword, RawCommand
11-
from nonebot_plugin_saa import Image, MessageFactory, Text
11+
from nonebot_plugin_saa import Image, MessageFactory
1212

13-
from ..l4d2_anne.server import updata_anne_server
1413
from ..l4d2_image import server_group_ip_pic
1514
from ..l4d2_queries.qqgroup import add_ip, del_ip, get_number_url, show_ip
1615
from ..l4d2_queries.utils import queries_server
@@ -162,23 +161,7 @@ async def _(
162161
if push_msg is None:
163162
return
164163

165-
if isinstance(push_msg, bytes):
166-
logger.info("直接发送图片")
167-
await MessageFactory([Image(push_msg)]).finish()
168-
return
169-
if msg and isinstance(push_msg, list):
170-
logger.info("更加构造函数")
171-
await MessageFactory([Image(push_msg[0]), Text(push_msg[-1])]).finish()
172-
return
173-
if msg and isinstance(push_msg, str):
174-
send_msg = push_msg
175-
else:
176-
logger.info("出错了")
177-
return
178-
logger.info(type(send_msg))
179-
if not send_msg:
180-
logger.warning("没有")
181-
await matcher.finish(send_msg)
164+
await MessageFactory(push_msg).send()
182165

183166

184167
# tests = on_command("测试1")
@@ -279,29 +262,6 @@ async def _():
279262
await init()
280263

281264

282-
updata = on_command(
283-
"updata_anne",
284-
aliases={"求生更新anne"},
285-
priority=20,
286-
block=True,
287-
permission=MASTER,
288-
)
289-
290-
291-
@updata.handle()
292-
async def _(matcher: Matcher, args: Message = CommandArg()):
293-
"""更新"""
294-
if args:
295-
# 占位先,除了电信服还有再加
296-
...
297-
anne_ip_dict = await updata_anne_server()
298-
if anne_ip_dict is None:
299-
await matcher.finish("网络开小差了捏")
300-
return
301-
server_number = len(anne_ip_dict["云"])
302-
await matcher.finish(f"更新成功\n一共更新了{server_number}个电信anne服ip")
303-
304-
305265
@add2_queries.handle()
306266
async def _(matcher: Matcher, arg: Message = CommandArg()):
307267
arg_list = arg.extract_plain_text().split(" ")

nonebot_plugin_l4d2_server/l4d2_queries/send_msg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Dict, List, Optional, Tuple
33

44
from nonebot.log import logger
5+
from nonebot_plugin_saa import Image, Text
56

67
from ..l4d2_queries.local_ip import ALL_HOST
78
from ..l4d2_queries.qqgroup import qq_ip_queries_pic
@@ -29,7 +30,7 @@ async def get_ip_to_mes(msg: str, command: str = ""):
2930
msg_tuple = (one_ip["id"], host, port)
3031
ip_list.append(msg_tuple)
3132
img = await qq_ip_queries_pic(ip_list, igr)
32-
return img if img else None
33+
return [Image(img)] if img else None
3334

3435
if not msg[0].isdigit():
3536
# if any(mode in msg for mode in gamemode_list):
@@ -46,10 +47,10 @@ async def get_ip_to_mes(msg: str, command: str = ""):
4647
try:
4748
msg_send: Optional[str] = await get_anne_server_ip(ip)
4849
if msg_send is not None:
49-
return msg_send
50+
return [Text(msg_send)]
5051

5152
except (OSError, asyncio.exceptions.TimeoutError):
52-
return "服务器无响应"
53+
return [Text("服务器无响应")]
5354

5455

5556
# async def get_read_group_ip():

nonebot_plugin_l4d2_server/l4d2_utils/config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ class L4d2Config(BaseModel):
8686
"49c294d32f69b732ef6447c18379451ce1738922a75cd1d4812ef150318a2ed0",
8787
alias="后台管理token密钥",
8888
)
89-
l4_master: List[str] = Field(["114514919"], alias="求生地图全局管理员qq")
89+
l4_master: List[str] = Field(default=["114514919"], alias="求生地图全局管理员qq")
9090
# l4_ip:bool = Field(False, alias='查询地图是否显示ip')
91-
l4_font: str = Field("simsun.ttc", alias="字体")
92-
l4_only: bool = Field(False, alias="下载地图是是否阻碍其他指令")
93-
l4_push_interval: int = Field(3, alias="定时任务间隔")
94-
l4_push_times: int = Field(10, alias="定时任务次数")
95-
l4_connect: bool = Field(True, alias="是否在查服命令后加入connect ip")
96-
l4_group_upload: bool = Field(False, alias="是否在群里传地图的时候,提示上传服务器")
97-
group_config: Dict[int, L4d2GroupConfig] = Field({}, alias="分群配置")
91+
l4_font: str = Field(default="simsun.ttc", alias="字体")
92+
l4_only: bool = Field(default=False, alias="下载地图是是否阻碍其他指令")
93+
l4_push_interval: int = Field(default=3, alias="定时任务间隔")
94+
l4_push_times: int = Field(default=10, alias="定时任务次数")
95+
l4_connect: bool = Field(default=True, alias="是否在查服命令后加入connect ip")
96+
l4_group_upload: bool = Field(default=False, alias="是否在群里传地图的时候,提示上传服务器")
97+
group_config: Dict[int, L4d2GroupConfig] = Field(default_factory=dict, alias="分群配置")
9898

9999
def update(self, **kwargs):
100100
for key, value in kwargs.items():

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nonebot-plugin-l4d2-server"
3-
version = "0.6.4-post1"
3+
version = "0.6.5"
44
description = "L4D2 server related operations plugin for NoneBot2"
55
authors = [
66
{ name = "Agnes_Digital", email = "[email protected]" }
@@ -9,7 +9,7 @@ requires-python = ">=3.9,<4.0"
99
keywords = ["steam", "game", "l4d2", "nonebot2", "plugin"]
1010
dependencies = [
1111
"nonebot2>=2.0.0",
12-
"nonebot-plugin-htmlrender==0.2.0.3",
12+
"nonebot-plugin-htmlrender==0.2.2",
1313
"nonebot_plugin_txt2img>=0.3.0",
1414
"nonebot-plugin-apscheduler>=0.2.0",
1515
"nonebot-adapter-onebot>=2.2.3",
@@ -21,7 +21,7 @@ dependencies = [
2121
"bs4==0.0.1",
2222
"httpx>=0.22.0",
2323
"rcon==2.1.0",
24-
"pillow>=9.4.0",
24+
"pillow<10.0.0",
2525
"pyunpack>=0.3.0",
2626
"ruamel.yaml>=0.17.21",
2727
"rarfile>=4.0",

requirements.txt

-918 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)