Skip to content

Commit c2c0502

Browse files
committed
:update 1.2.0
1 parent a35213d commit c2c0502

File tree

9 files changed

+136
-101
lines changed

9 files changed

+136
-101
lines changed

data/L4D2/l4d2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/L4D2/l4d2/l4d2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/L4D2/sb_pages.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

nonebot_plugin_l4d2_server/__main__.py

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from pathlib import Path
1919
from typing import List, Optional, cast
2020

21-
import aiofiles
2221
import ujson as json
2322
from nonebot import get_driver
2423
from nonebot.adapters import Message
@@ -50,7 +49,7 @@
5049
from .utils.api.utils import out_msg_out
5150
from .utils.group_store import set_group
5251
from .utils.sb_sources import load_pages
53-
from .utils.utils import read_config, split_maohao, write_config
52+
from .utils.utils import split_maohao
5453

5554
driver = get_driver()
5655

@@ -143,7 +142,7 @@ async def _(
143142
6. 调用 get_server_detail 函数获取服务器详情,并根据返回结果发送相应的消息。
144143
7. 如果 get_server_detail 返回 None,则发送 "服务器无响应" 的文本消息。
145144
"""
146-
145+
logger.info(f"[l4]开始执行请求]:{command}")
147146
if start:
148147
command = command.replace(start, "")
149148
if command == "anne":
@@ -275,67 +274,67 @@ async def _(args: Message = CommandArg()):
275274
await out_msg_out("重载ip完成")
276275

277276

278-
l4_add_ban = on_command("l4addban", aliases={"l4添加ban"})
279-
280-
281-
@l4_add_ban.handle()
282-
async def _(args: Message = CommandArg()):
283-
arg = args.extract_plain_text().strip().split(" ")
284-
if len(arg) != 2:
285-
await UniMessage.text("请在命令后增加响应指令名和网址").finish()
286-
287-
config_data = read_config(config_path)
288-
config_data.update({arg[0]: arg[1]})
289-
write_config(config_path, config_data)
290-
291-
await L4API.get_sourceban(arg[0], arg[1])
292-
reload_ip()
293-
refresh_server_command_rule(l4_request)
294-
await UniMessage.text("添加成功\n组名: {arg[0]}\n网址: {arg[1]}").send()
295-
296-
297-
l4_del_ban = on_command("l4delban", aliases={"l4删除ban", "l4移除ban"})
298-
299-
300-
@l4_del_ban.handle()
301-
async def _(args: Message = CommandArg()):
302-
arg = args.extract_plain_text().strip().split(" ")
303-
if len(arg) not in [1, 2]:
304-
await UniMessage.text("请在命令后增加响应指令名或者带响应网址").finish()
305-
elif len(arg) == 1:
306-
if not Path(Path(config.l4_path) / "config.json").is_file():
307-
await UniMessage.text("没有添加过组名").finish()
308-
else:
309-
with (Path(config.l4_path) / "config.json").open(
310-
"r",
311-
encoding="utf-8",
312-
) as f:
313-
content = f.read().strip()
314-
config_data = json.loads(content)
315-
if arg[0] not in config_data:
316-
await UniMessage.text("没有添加过这个组").finish()
317-
else:
318-
del config_data[arg[0]]
319-
async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
320-
json.dump(config_data, f, ensure_ascii=False, indent=4)
321-
await out_msg_out(f"删除成功,组名:{arg[0]}")
322-
elif len(arg) == 2:
323-
if not Path(Path(config.l4_path) / "config.json").is_file():
324-
await UniMessage.text("没有添加过组名").finish()
325-
else:
326-
with (Path(config.l4_path) / "config.json").open(
327-
"r",
328-
encoding="utf-8",
329-
) as f:
330-
content = f.read().strip()
331-
config_datas = json.loads(content)
332-
if arg[0] not in config_datas:
333-
await UniMessage.text("没有添加过这个组").finish()
334-
else:
335-
config_datas[arg[0]] = arg[1]
336-
async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
337-
json.dump(config_datas, f, ensure_ascii=False, indent=4)
338-
await out_msg_out(f"修改成功,组名:{arg[0]},网址:{arg[1]}")
277+
# l4_add_ban = on_command("l4addban", aliases={"l4添加ban"})
278+
279+
280+
# @l4_add_ban.handle()
281+
# async def _(args: Message = CommandArg()):
282+
# arg = args.extract_plain_text().strip().split(" ")
283+
# if len(arg) != 2:
284+
# await UniMessage.text("请在命令后增加响应指令名和网址").finish()
285+
286+
# config_data = read_config(config_path)
287+
# config_data.update({arg[0]: arg[1]})
288+
# write_config(config_path, config_data)
289+
290+
# await L4API.get_sourceban(arg[0], arg[1])
291+
# reload_ip()
292+
# refresh_server_command_rule(l4_request)
293+
# await UniMessage.text("添加成功\n组名: {arg[0]}\n网址: {arg[1]}").send()
294+
295+
296+
# l4_del_ban = on_command("l4delban", aliases={"l4删除ban", "l4移除ban"})
297+
298+
299+
# @l4_del_ban.handle()
300+
# async def _(args: Message = CommandArg()):
301+
# arg = args.extract_plain_text().strip().split(" ")
302+
# if len(arg) not in [1, 2]:
303+
# await UniMessage.text("请在命令后增加响应指令名或者带响应网址").finish()
304+
# elif len(arg) == 1:
305+
# if not Path(Path(config.l4_path) / "config.json").is_file():
306+
# await UniMessage.text("没有添加过组名").finish()
307+
# else:
308+
# with (Path(config.l4_path) / "config.json").open(
309+
# "r",
310+
# encoding="utf-8",
311+
# ) as f:
312+
# content = f.read().strip()
313+
# config_data = json.loads(content)
314+
# if arg[0] not in config_data:
315+
# await UniMessage.text("没有添加过这个组").finish()
316+
# else:
317+
# del config_data[arg[0]]
318+
# async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
319+
# json.dump(config_data, f, ensure_ascii=False, indent=4)
320+
# await out_msg_out(f"删除成功,组名:{arg[0]}")
321+
# elif len(arg) == 2:
322+
# if not Path(Path(config.l4_path) / "config.json").is_file():
323+
# await UniMessage.text("没有添加过组名").finish()
324+
# else:
325+
# with (Path(config.l4_path) / "config.json").open(
326+
# "r",
327+
# encoding="utf-8",
328+
# ) as f:
329+
# content = f.read().strip()
330+
# config_datas = json.loads(content)
331+
# if arg[0] not in config_datas:
332+
# await UniMessage.text("没有添加过这个组").finish()
333+
# else:
334+
# config_datas[arg[0]] = arg[1]
335+
# async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
336+
# json.dump(config_datas, f, ensure_ascii=False, indent=4)
337+
# await out_msg_out(f"修改成功,组名:{arg[0]},网址:{arg[1]}")
339338

340339

341340
if "云" in COMMAND:

nonebot_plugin_l4d2_server/l4_ban/__init__.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ async def _delete_group_and_page(tag: str) -> tuple[bool, bool]:
3131

3232

3333
# l4addban <组名> [SourceBans服务器页URL]
34-
l4_add_ban = on_command("l4addban", aliases={"l4添加服务器组"})
34+
l4_add_ban = on_command("l4addban", aliases={"l4添加组"})
35+
# 批量刷新:遍历 sb_pages.json 中所有组
36+
l4_reload_sb = on_command("l4reloadsb", aliases={"l4刷新组"})
37+
# 列出所有组及数量
38+
l4_list_groups = on_command("l4listgroup", aliases={"l4listgroups", "l4列组"})
39+
# 删除服务器组(即删除 data/L4D2/l4d2/<tag>.json)
40+
l4_del_group = on_command("l4delgroup", aliases={"l4删除组"})
41+
# 删除 sb_pages.json 里的 URL 映射(仅删 URL)
42+
l4_del_page = on_command("l4delpage", aliases={"l4删除页"})
43+
# 导出指定组的 JSON 片段(直接读取 data/L4D2/l4d2/<tag>.json)
44+
l4_export_group = on_command("l4exportgroup", aliases={"l4导出组"})
45+
# 导出全部组(仅用于查看,组合成一个对象返回,不写入任何聚合文件)
46+
l4_export_groups = on_command("l4exportgroups", aliases={"l4导出全部组"})
3547

3648

3749
@l4_add_ban.handle()
@@ -55,21 +67,17 @@ async def _(args: Message = CommandArg()):
5567
).finish()
5668

5769
api = L4D2Api()
58-
try:
59-
server_list = await api.get_sourceban(tag, page)
60-
except Exception as e:
61-
await UniMessage.text(f"抓取失败:{e}").finish()
70+
# try:
71+
server_list = await api.get_sourceban(tag, page)
72+
# except Exception as e:
73+
# await UniMessage.text(f"抓取失败:{e}").finish()
6274

6375
path = await set_group(tag, server_list)
6476
await UniMessage.text(
6577
f"✅ 已更新:{path.name}(共 {len(server_list)} 台)",
6678
).finish()
6779

6880

69-
# 批量刷新:遍历 sb_pages.json 中所有组
70-
l4_reload_sb = on_command("l4reloadsb", aliases={"l4刷新服务器组"})
71-
72-
7381
@l4_reload_sb.handle()
7482
async def _():
7583
pages = await load_pages()
@@ -96,10 +104,6 @@ async def _():
96104
refresh_server_command_rule(l4_request)
97105

98106

99-
# 列出所有组及数量
100-
l4_list_groups = on_command("l4listgroup", aliases={"l4listgroups", "l4列服务器组"})
101-
102-
103107
@l4_list_groups.handle()
104108
async def _():
105109
names = await list_groups()
@@ -112,10 +116,6 @@ async def _():
112116
await UniMessage.text("现有服务器组:\n" + "\n".join(lines)).finish()
113117

114118

115-
# 删除服务器组(即删除 data/L4D2/l4d2/<tag>.json)
116-
l4_del_group = on_command("l4delgroup", aliases={"l4删除服务器组"})
117-
118-
119119
@l4_del_group.handle()
120120
async def _(args: Message = CommandArg()):
121121
tag = args.extract_plain_text().strip()
@@ -137,10 +137,6 @@ async def _(args: Message = CommandArg()):
137137
refresh_server_command_rule(l4_request)
138138

139139

140-
# 删除 sb_pages.json 里的 URL 映射(仅删 URL)
141-
l4_del_page = on_command("l4delpage", aliases={"l4删除服务器页"})
142-
143-
144140
@l4_del_page.handle()
145141
async def _(args: Message = CommandArg()):
146142
tag = args.extract_plain_text().strip()
@@ -150,10 +146,6 @@ async def _(args: Message = CommandArg()):
150146
await UniMessage.text("✅ 已删除" if ok else "未找到该组的 URL").finish()
151147

152148

153-
# 导出指定组的 JSON 片段(直接读取 data/L4D2/l4d2/<tag>.json)
154-
l4_export_group = on_command("l4exportgroup", aliases={"l4导出服务器组"})
155-
156-
157149
@l4_export_group.handle()
158150
async def _(args: Message = CommandArg()):
159151
tag = args.extract_plain_text().strip()
@@ -166,10 +158,6 @@ async def _(args: Message = CommandArg()):
166158
await UniMessage.text(json.dumps(data, ensure_ascii=False, indent=4)).finish()
167159

168160

169-
# 导出全部组(仅用于查看,组合成一个对象返回,不写入任何聚合文件)
170-
l4_export_groups = on_command("l4exportgroups", aliases={"l4导出全部服务器组"})
171-
172-
173161
@l4_export_groups.handle()
174162
async def _():
175163
data = await export_all()

nonebot_plugin_l4d2_server/l4_help/Help.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,58 @@
7373
}
7474
]
7575
},
76+
"SourceBan服务": {
77+
"desc": "通过网页抓取服务器信息",
78+
"data": [
79+
{
80+
"name": "l4添加组",
81+
"desc": "添加sb组网址",
82+
"eg": "l4添加组 云 123.com",
83+
"need_ck": false,
84+
"need_sk": false,
85+
"need_admin": false
86+
},
87+
{
88+
"name": "l4刷新组",
89+
"desc": "刷新sb组网址",
90+
"eg": "l4刷新组",
91+
"need_ck": false,
92+
"need_sk": false,
93+
"need_admin": false
94+
},
95+
{
96+
"name": "l4列组",
97+
"desc": "列出所有sb组网址",
98+
"eg": "l4列组",
99+
"need_ck": false,
100+
"need_sk": false,
101+
"need_admin": false
102+
},
103+
{
104+
"name": "l4删除组",
105+
"desc": "删除sb组网址",
106+
"eg": "l4列组 云",
107+
"need_ck": false,
108+
"need_sk": false,
109+
"need_admin": false
110+
},
111+
{
112+
"name": "l4删除页",
113+
"desc": "删除sb组网址",
114+
"eg": "",
115+
"need_ck": false,
116+
"need_sk": false,
117+
"need_admin": false
118+
},
119+
{
120+
"name": "l4导出组",
121+
"desc": "导出sb组网址",
122+
"eg": "",
123+
"need_ck": false,
124+
"need_sk": false,
125+
"need_admin": false
126+
}
127+
],
76128
"其他服务": {
77129
"desc": "一些杂项服务",
78130
"data": [

nonebot_plugin_l4d2_server/l4_help/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..l4_image.model import PluginHelp
1111
from .draw import get_help
1212

13-
__version__ = "1.1.6"
13+
__version__ = "1.2.0"
1414
TEXT_PATH = Path(__file__).parent / "texture2d"
1515
HELP_DATA = Path(__file__).parent / "help.json"
1616

nonebot_plugin_l4d2_server/utils/api/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async def get_sourceban(self, tag: str = "云", url: str = anne_ban):
320320
new_dict["id"] = int(server.index) + 1
321321
new_dict["ip"] = server.host + ":" + str(server.port)
322322
up_data.update(new_dict)
323-
json.dump(up_data, f, ensure_ascii=False, indent=4)
323+
await f.write(json.dumps(up_data, ensure_ascii=False, indent=4))
324324
return server_list
325325

326326
async def get_anne_steamid(self, name: str):

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dependencies = [
2424
"rarfile>=4.2",
2525
"pyunpack>=0.3",
2626
"aiofiles>=24.1.0",
27-
"bs4==0.0.2"
27+
"bs4==0.0.2",
28+
"lxml>=6.0.2",
2829
]
2930
classifiers = [
3031
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",

0 commit comments

Comments
 (0)