nonebot-plugin-l4d2-server 1.0.9__py3-none-any.whl → 1.1.0__py3-none-any.whl

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.
@@ -42,7 +42,7 @@ from .l4_request import (
42
42
  )
43
43
  from .utils.api.request import L4API
44
44
  from .utils.api.utils import out_msg_out
45
- from .utils.utils import split_maohao
45
+ from .utils.utils import log_and_send, read_config, split_maohao, write_config
46
46
 
47
47
  if TYPE_CHECKING:
48
48
  from .utils.api.models import OutServer
@@ -131,6 +131,8 @@ async def _(
131
131
  ):
132
132
  # 以后有时间补img格式
133
133
  msg: str = args.extract_plain_text().strip()
134
+ if not msg:
135
+ return UniMessage.text("请在指令后添加要找的昵称哦")
134
136
  tag_list: List[str] = msg.split(" ", maxsplit=1)
135
137
  if len(tag_list) == 1:
136
138
  await UniMessage.text("未设置组,正在全服查找,时间较长").send()
@@ -202,29 +204,15 @@ l4_add_ban = on_command("l4addban", aliases={"l4添加ban"})
202
204
  @l4_add_ban.handle()
203
205
  async def _(args: Message = CommandArg()):
204
206
  arg = args.extract_plain_text().strip().split(" ")
205
-
206
207
  if len(arg) != 2:
207
208
  await UniMessage.text("请在命令后增加响应指令名和网址").finish()
208
209
 
209
- if not config_path.is_file():
210
- config_data = {}
211
- else:
212
- try:
213
- with config_path.open("r") as f:
214
- config_data = json.load(f)
215
- except (json.JSONDecodeError, FileNotFoundError):
216
- config_data = {}
217
-
210
+ config_data = read_config(config_path)
218
211
  config_data.update({arg[0]: arg[1]})
219
-
220
- try:
221
- with config_path.open("w") as f:
222
- json.dump(config_data, f, ensure_ascii=False, indent=4)
223
- except IOError as e:
224
- await UniMessage.text(f"文件写入失败: {e}").finish()
212
+ write_config(config_path, config_data)
225
213
 
226
214
  await L4API.get_sourceban(arg[0], arg[1])
227
- await out_msg_out(f"添加成功\n组名: {arg[0]}\n网址: {arg[1]}")
215
+ await log_and_send(l4_add_ban, f"添加成功\n组名: {arg[0]}\n网址: {arg[1]}")
228
216
 
229
217
 
230
218
  l4_del_ban = on_command("l4delban", aliases={"l4删除ban", "l4移除ban"})
@@ -10,7 +10,7 @@ from ..l4_image.convert import core_font
10
10
  from ..l4_image.model import PluginHelp
11
11
  from .draw import get_help
12
12
 
13
- __version__ = "1.0.9"
13
+ __version__ = "1.1.0"
14
14
  TEXT_PATH = Path(__file__).parent / "texture2d"
15
15
  HELP_DATA = Path(__file__).parent / "Help.json"
16
16
 
@@ -119,7 +119,8 @@ async def get_group_detail(
119
119
  command: str,
120
120
  ):
121
121
  server_json = _get_server_json(command, ALLHOST)
122
- logger.debug(server_json)
122
+ # logger.debug(f"获取组服务器信息: {server_json}")
123
+ logger.info(server_json)
123
124
  if server_json is None:
124
125
  logger.warning("未找到这个组")
125
126
  return None
@@ -212,12 +213,16 @@ async def tj_request(command: str = "云", tj="tj"):
212
213
 
213
214
 
214
215
  async def server_find(
215
- command: str = "",
216
+ command: str = "",
216
217
  _id: Optional[str] = None,
217
218
  is_img: bool = True,
218
219
  ):
219
- server_json = _get_server_json(command, ALLHOST)
220
- logger.debug(server_json)
220
+ all_command = get_all_json_filenames()
221
+ server_json = []
222
+ for one_command in all_command:
223
+ server_j = _get_server_json(one_command, ALLHOST)
224
+ server_json.extend(server_j)
225
+ logger.info(server_json)
221
226
  if server_json is None:
222
227
  logger.warning("未找到这个组")
223
228
  return None
@@ -239,3 +244,19 @@ async def server_find(
239
244
  if isinstance(out_msg, str):
240
245
  return UniMessage.text(out_msg)
241
246
  return None
247
+
248
+
249
+ def get_all_json_filenames():
250
+ """
251
+ 获取 server_all_path 路径下所有 json 文件的文件名(不带扩展名)的列表。
252
+ """
253
+ json_files = []
254
+ for item in server_all_path.iterdir():
255
+ if item.is_file() and item.suffix == ".json":
256
+ json_files.append(item.stem)
257
+ return json_files
258
+
259
+
260
+ # 使用示例
261
+
262
+ # all_json_names 现在是一个包含所有 json 文件名(不带扩展名)的 list
@@ -53,24 +53,7 @@ async def draw_one_ip(host: str, port: int, is_img: bool = config.l4_image):
53
53
  完整的服务器信息字符串
54
54
  """
55
55
 
56
- # 处理服务器类型显示
57
- type_map = {
58
- "d": "Dedicated",
59
- "l": "Listen",
60
- }
61
- platform_map = {
62
- "w": "Windows",
63
- "l": "Linux",
64
- }
65
- # 解析原始数据 (例如 "d(w)" -> type='d', platform='w')
66
- server_type = server.server_type[0] if server.server_type else "d"
67
- platform = server.platform[0] if server.platform else "w"
68
-
69
- # 处理VAC状态显示
70
56
  vac_status = "启用" if server.vac_enabled else "禁用"
71
- # 处理密码状态显示
72
- pw_status = "是" if server.password_protected else "否"
73
-
74
57
  msg = f"""-{server.server_name}-
75
58
  游戏: {server.folder}
76
59
  地图: {server.map_name}
@@ -78,9 +61,7 @@ async def draw_one_ip(host: str, port: int, is_img: bool = config.l4_image):
78
61
  if server.ping is not None:
79
62
  msg += f"""
80
63
  延迟: {server.ping * 1000:.0f} ms
81
- 类型: {type_map.get(server_type, '未知')} ({platform_map.get(platform, '未知')})
82
- VAC : {vac_status}
83
- 密码: {pw_status}\n
64
+ VAC : {vac_status}\n
84
65
  {player_info}"""
85
66
  if config.l4_show_ip:
86
67
  msg += f"""
@@ -22,11 +22,13 @@ def _get_server_json(
22
22
  Returns:
23
23
  Optional[list]: 服务器JSON列表,未找到组时返回None
24
24
  """
25
+ logger.debug(f"获取服务器组 {allhost} 的信息")
25
26
  if command:
26
27
  return allhost.get(command)
27
28
  server_json = []
28
29
  for servers in allhost.values():
29
30
  server_json.extend(servers)
31
+ logger.debug(f"获取到的服务器组信息: {server_json}")
30
32
  return server_json
31
33
 
32
34
 
@@ -13,6 +13,29 @@ from nonebot.log import logger
13
13
  from nonebot_plugin_alconna import UniMessage
14
14
 
15
15
 
16
+ async def log_and_send(matcher, message: str, level="info"):
17
+ getattr(logger, level)(message)
18
+ await matcher.finish(UniMessage.text(message))
19
+
20
+
21
+ def read_config(config_path: Path) -> dict:
22
+ if not config_path.is_file():
23
+ return {}
24
+ try:
25
+ with config_path.open("r", encoding="utf-8") as f:
26
+ return json.load(f)
27
+ except (json.JSONDecodeError, FileNotFoundError):
28
+ return {}
29
+
30
+
31
+ def write_config(config_path: Path, data: dict) -> None:
32
+ try:
33
+ with config_path.open("w", encoding="utf-8") as f:
34
+ json.dump(data, f, ensure_ascii=False, indent=4)
35
+ except IOError as e:
36
+ raise RuntimeError(f"配置写入失败: {e}") from e
37
+
38
+
16
39
  async def get_file(url: str, down_file: Path):
17
40
  """
18
41
  下载指定Url到指定位置
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-l4d2-server
3
- Version: 1.0.9
3
+ Version: 1.1.0
4
4
  Summary: L4D2 server related operations plugin for NoneBot2
5
5
  Keywords: steam,game,l4d2,nonebot2,plugin
6
6
  Author-Email: Agnes_Digital <Z735803792@163.com>
@@ -1,13 +1,13 @@
1
- nonebot_plugin_l4d2_server-1.0.9.dist-info/METADATA,sha256=ctmdb9rfE5_n965rELNjZ1l-KWaXoKndwjj0Ewh2Ye0,6759
2
- nonebot_plugin_l4d2_server-1.0.9.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- nonebot_plugin_l4d2_server-1.0.9.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- nonebot_plugin_l4d2_server-1.0.9.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
1
+ nonebot_plugin_l4d2_server-1.1.0.dist-info/METADATA,sha256=0_5GoxERyaHRpJ_EGFVGROojGUvr8TqWkdZYNrQ0bs0,6759
2
+ nonebot_plugin_l4d2_server-1.1.0.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ nonebot_plugin_l4d2_server-1.1.0.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ nonebot_plugin_l4d2_server-1.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
5
  nonebot_plugin_l4d2_server/__init__.py,sha256=xzhXyprPmoTTjpfyqYlMweC4umuLsm8MERA1ZTqCyYc,1661
6
- nonebot_plugin_l4d2_server/__main__.py,sha256=Ysx4PkR3kIuSsKM6h9kmPBuylxXsuLjtrOdT1LbQT9A,10511
6
+ nonebot_plugin_l4d2_server/__main__.py,sha256=-m1tH_4T-9AP66V3Drb1t8CZXZMc0eAUXZsBY3LEBuI,10271
7
7
  nonebot_plugin_l4d2_server/config.py,sha256=t4BYygrrLTcsl9oBnyce0-tDhMCCkMrkEPs4DX2t4KI,2682
8
8
  nonebot_plugin_l4d2_server/data/font/loli.ttf,sha256=Yrh-RPoCrn1-NG94DR0x20ASXYUt8g3Ep6BCt3CdOFk,11125812
9
9
  nonebot_plugin_l4d2_server/l4_help/Help.json,sha256=D0YmZYGW-imC7nVebkQ0_eODiqevQhL9aKj-cyBaqDY,1704
10
- nonebot_plugin_l4d2_server/l4_help/__init__.py,sha256=_e2uAaiECMGhbunurdN3dImu00l5j1uDCLBMxPlqolM,1479
10
+ nonebot_plugin_l4d2_server/l4_help/__init__.py,sha256=4TODWKsj4a_VMCFAJBVwtzb3p8LQszzoRMmmF8DmSpQ,1479
11
11
  nonebot_plugin_l4d2_server/l4_help/draw.py,sha256=y6yDPUnoZFvwly8cf7g9HRpT1JXTxyA9DC1TuvUinTM,6448
12
12
  nonebot_plugin_l4d2_server/l4_help/icon/介绍.png,sha256=3QC6A38QC-7gDBxmtQSQdbsz7hsefU5LL-oZmJ41zTk,3806
13
13
  nonebot_plugin_l4d2_server/l4_help/icon/任务.png,sha256=nyZ4_kM21ZO95nwanCFnUfCGX-PkmJXYQf9OrJVKomY,3782
@@ -85,13 +85,13 @@ nonebot_plugin_l4d2_server/l4_image/model.py,sha256=FGsCvf_BKbRNJUVy6I5BKnArMY-3
85
85
  nonebot_plugin_l4d2_server/l4_image/vtfs.py,sha256=He_7zzEIOip8MXP55TS7aWPbzo6ac0wPf602nN3GWZM,1461
86
86
  nonebot_plugin_l4d2_server/l4_local/__init__.py,sha256=gNNUNXGKHA8UXQaDKomND4VEutGpAghpYE4Va13gb5I,4736
87
87
  nonebot_plugin_l4d2_server/l4_local/file.py,sha256=hew1Y8kV3uSZvUGplmi09EGKC89-sUJWsWV7SCEstI8,3067
88
- nonebot_plugin_l4d2_server/l4_request/__init__.py,sha256=p8ndsNC4QCJ97K9fZwCQ2y6jOa5-QU14soQ3dIZzIKg,7544
89
- nonebot_plugin_l4d2_server/l4_request/draw_msg.py,sha256=2HvUpVdge4lHG3y7LpB1Babi7jTkpoVP325V3MTvgBA,12151
90
- nonebot_plugin_l4d2_server/l4_request/utils.py,sha256=UyRceC5FOS_GeUNKJtL1OpXwq-f5QiVxSpy6rgj52p8,5102
88
+ nonebot_plugin_l4d2_server/l4_request/__init__.py,sha256=6fSaWFUC-dgU5DWzdDxxcAV4-LwxSaIZbTn7UXE_H3g,8179
89
+ nonebot_plugin_l4d2_server/l4_request/draw_msg.py,sha256=5zMPPSUAUarInOugBUvZVNZjxTVNrg6kO3FOtSzVpKs,11482
90
+ nonebot_plugin_l4d2_server/l4_request/utils.py,sha256=VInMCBduIL0I3zLQ60Sq29gwZ3hbU4tRyOT94mJD-vo,5229
91
91
  nonebot_plugin_l4d2_server/utils/api/api.py,sha256=auvDicCEKwvnm6EJYeCxCtugFby61K-zAmmaRWWEwtM,296
92
92
  nonebot_plugin_l4d2_server/utils/api/models.py,sha256=p-hoxPHwadTaMRb2hqwfbaQ3pvJySrV8VbBmhA0Oi-M,2391
93
93
  nonebot_plugin_l4d2_server/utils/api/request.py,sha256=JGAhMgPgmy2Z2w7w3GVlUGKBmxlaTTDD3bq1T2dhHIE,13567
94
94
  nonebot_plugin_l4d2_server/utils/api/utils.py,sha256=rdrFK3VKP59KfNX-C8v0Q_IV3tBLm02Wo9axLTQQ87Y,762
95
95
  nonebot_plugin_l4d2_server/utils/database/models.py,sha256=SLdcgwsn39r_ZkcBoqf4MLX1EfpCOjGBwWcR16u9Bqo,454
96
- nonebot_plugin_l4d2_server/utils/utils.py,sha256=TD3cUCxmmj2GPmK1sQwP7NtkIXNO2FpuXjymaUqBDYo,6141
97
- nonebot_plugin_l4d2_server-1.0.9.dist-info/RECORD,,
96
+ nonebot_plugin_l4d2_server/utils/utils.py,sha256=KHfnTO3a-rGpjhXTsXypC0xb61ijpON631zqjIAW2vo,6836
97
+ nonebot_plugin_l4d2_server-1.1.0.dist-info/RECORD,,