nonebot-plugin-l4d2-server 1.1.6__tar.gz → 1.2.0__tar.gz

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.
Files changed (104) hide show
  1. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/PKG-INFO +2 -1
  2. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/__main__.py +137 -75
  3. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/commands/__init__.py +1 -0
  4. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/config.py +10 -7
  5. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/data/L4D2/l4d2/l4d2.json +1 -0
  6. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/data/L4D2/l4d2.json +1 -0
  7. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/l4_ban/__init__.py +166 -0
  8. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/l4_ban/utils.py +11 -0
  9. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/Help.json +52 -0
  10. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/__init__.py +1 -1
  11. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_request/__init__.py +12 -8
  12. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_request/tj.py +7 -4
  13. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_request/utils.py +24 -12
  14. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/message.py +1 -0
  15. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/api/request.py +38 -14
  16. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/api/utils.py +3 -1
  17. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/utils/group_store.py +93 -0
  18. nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/utils/sb_sources.py +57 -0
  19. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/utils.py +2 -2
  20. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/pyproject.toml +2 -1
  21. nonebot_plugin_l4d2_server-1.2.0/tests/__init__.py +0 -0
  22. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/LICENSE +0 -0
  23. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/README.md +0 -0
  24. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/__init__.py +0 -0
  25. /nonebot_plugin_l4d2_server-1.1.6/tests/__init__.py → /nonebot_plugin_l4d2_server-1.2.0/nonebot_plugin_l4d2_server/commands/server_groups.py +0 -0
  26. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/data/font/loli.ttf +0 -0
  27. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/draw.py +0 -0
  28. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//344/273/213/347/273/215.png" +0 -0
  29. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//344/273/273/345/212/241.png" +0 -0
  30. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//344/277/241/346/201/257.png" +0 -0
  31. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/205/254/345/221/212.png" +0 -0
  32. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/210/200/345/211/221.png" +0 -0
  33. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/210/207/346/215/242.png" +0 -0
  34. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/210/240/351/231/244.png" +0 -0
  35. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/210/267/346/226/260.png" +0 -0
  36. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/215/241/347/273/204.png" +0 -0
  37. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/223/252/351/207/214.png" +0 -0
  38. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/234/260/345/233/276.png" +0 -0
  39. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/205/245.png" +0 -0
  40. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/207/272.png" +0 -0
  41. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//345/275/261.png" +0 -0
  42. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/213/274/345/233/276.png" +0 -0
  43. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/216/242/347/264/242.png" +0 -0
  44. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/216/250/351/200/201.png" +0 -0
  45. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/224/266/351/233/206.png" +0 -0
  46. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/224/273/347/225/245.png" +0 -0
  47. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/233/264/346/226/260.png" +0 -0
  48. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/235/220/346/226/231.png" +0 -0
  49. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/237/245/350/257/242.png" +0 -0
  50. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/240/241/351/252/214.png" +0 -0
  51. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/257/217/346/234/210.png" +0 -0
  52. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/267/261/346/270/212.png" +0 -0
  53. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/267/273/345/212/240.png" +0 -0
  54. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//346/270/205/351/231/244.png" +0 -0
  55. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//347/212/266/346/200/201.png" +0 -0
  56. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//347/255/276/345/210/260.png" +0 -0
  57. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//347/273/221/345/256/232.png" +0 -0
  58. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//350/241/250.png" +0 -0
  59. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//350/241/250/346/203/205.png" +0 -0
  60. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//350/247/222/350/211/262.png" +0 -0
  61. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//350/256/260/345/275/225.png" +0 -0
  62. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//351/205/215/347/275/256.png" +0 -0
  63. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/icon//351/207/215/345/220/257.png" +0 -0
  64. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/texture2d/badge.png +0 -0
  65. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/texture2d/banner.png +0 -0
  66. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/texture2d/bg.jpg +0 -0
  67. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/texture2d/button.png +0 -0
  68. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_help/texture2d/icon.png +0 -0
  69. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/__init__.py +0 -0
  70. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/convert.py +0 -0
  71. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/html_img.py +0 -0
  72. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/image_tools.py +0 -0
  73. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/anne/anne.html +0 -0
  74. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/anne/back.png +0 -0
  75. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/anne/group_ip.html +0 -0
  76. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/anne/ip.html +0 -0
  77. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/back_img/background.jpg +0 -0
  78. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/head/head.png +0 -0
  79. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/header/logo.png +0 -0
  80. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/header/player1.jpg +0 -0
  81. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/github.svg +0 -0
  82. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/l.svg +0 -0
  83. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/m.svg +0 -0
  84. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/normal.html +0 -0
  85. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/normal_old.html +0 -0
  86. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/style.css +0 -0
  87. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/vac.png +0 -0
  88. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/vac_white.png +0 -0
  89. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/vue.css +0 -0
  90. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/w.svg +0 -0
  91. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/img/template/workshop.html +0 -0
  92. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_image/model.py +0 -0
  93. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_local/__init__.py +0 -0
  94. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_local/download.py +0 -0
  95. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_local/file.py +0 -0
  96. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_local/utils.py +0 -0
  97. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_request/draw_msg.py +0 -0
  98. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/l4_request/typing.py +0 -0
  99. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/api/api.py +0 -0
  100. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/api/models.py +0 -0
  101. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/nonebot_plugin_l4d2_server/utils/database/models.py +0 -0
  102. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/tests/conftest.py +0 -0
  103. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/tests/help.py +0 -0
  104. {nonebot_plugin_l4d2_server-1.1.6 → nonebot_plugin_l4d2_server-1.2.0}/tests/todo.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-l4d2-server
3
- Version: 1.1.6
3
+ Version: 1.2.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>
@@ -34,6 +34,7 @@ Requires-Dist: rarfile>=4.2
34
34
  Requires-Dist: pyunpack>=0.3
35
35
  Requires-Dist: aiofiles>=24.1.0
36
36
  Requires-Dist: bs4==0.0.2
37
+ Requires-Dist: lxml>=6.0.2
37
38
  Description-Content-Type: text/markdown
38
39
 
39
40
  <!-- markdownlint-disable MD026 MD031 MD033 MD036 MD041 MD046 MD051 -->
@@ -16,10 +16,10 @@
16
16
  """
17
17
 
18
18
  from pathlib import Path
19
- from typing import List, Optional
19
+ from typing import List, Optional, cast
20
20
 
21
- import aiofiles
22
21
  import ujson as json
22
+ from nonebot import get_driver
23
23
  from nonebot.adapters import Message
24
24
  from nonebot.log import logger
25
25
  from nonebot.matcher import Matcher
@@ -29,6 +29,8 @@ from nonebot.plugin import on_command
29
29
  from nonebot_plugin_alconna import UniMessage
30
30
 
31
31
  from .config import config, config_manager
32
+ from .l4_ban import l4_request
33
+ from .l4_ban.utils import refresh_server_command_rule
32
34
  from .l4_help import get_l4d2_core_help
33
35
  from .l4_local import * # noqa: F403
34
36
  from .l4_request import (
@@ -42,14 +44,19 @@ from .l4_request import (
42
44
  )
43
45
  from .message import Gm, Sm
44
46
  from .utils.api.models import OutServer
45
- from .utils.api.request import L4API
47
+ from .utils.api.request import L4API, L4D2Api
46
48
  from .utils.api.utils import out_msg_out
47
- from .utils.utils import read_config, split_maohao, write_config
49
+ from .utils.group_store import set_group
50
+ from .utils.sb_sources import load_pages
51
+ from .utils.utils import split_maohao
52
+
53
+ driver = get_driver()
48
54
 
49
55
  reload_ip()
50
56
 
57
+
51
58
  l4_help = on_command("l4help", aliases={"l4d2帮助"})
52
- l4_request = on_command("anne", aliases=COMMAND, priority=10)
59
+
53
60
  l4_reload = on_command("l4reload", aliases={"l4刷新,l4重载"})
54
61
  l4_all = on_command("l4all", aliases={"l4全服"})
55
62
  l4_connect = on_command("connect", aliases={"l4连接"})
@@ -57,6 +64,41 @@ l4_find_player = on_command("l4find", aliases={"l4查找"})
57
64
 
58
65
 
59
66
  config_path = Path(config.l4_path) / "config.json"
67
+ refresh_server_command_rule(l4_request)
68
+
69
+
70
+ async def sync_sb_pages_groups() -> None:
71
+ """根据 sb_pages.json 内容刷新所有服务器组"""
72
+ pages = await load_pages()
73
+ if not pages:
74
+ logger.info("sb_pages.json 为空,跳过启动时刷新")
75
+ reload_ip()
76
+ refresh_server_command_rule(l4_request)
77
+ return
78
+
79
+ api = L4D2Api()
80
+ ok = 0
81
+ failed: List[str] = []
82
+ for tag, page in pages.items():
83
+ try:
84
+ servers = await api.get_sourceban(tag, page)
85
+ await set_group(tag, servers)
86
+ ok += 1
87
+ except Exception as exc:
88
+ failed.append(f"{tag}: {exc}")
89
+
90
+ reload_ip()
91
+ refresh_server_command_rule(l4_request)
92
+
93
+ if ok:
94
+ logger.success(f"启动时已刷新 {ok} 个服务器组")
95
+ if failed:
96
+ logger.warning("以下服务器组刷新失败:" + "; ".join(failed))
97
+
98
+
99
+ @driver.on_startup
100
+ async def _sync_groups_on_startup() -> None:
101
+ await sync_sb_pages_groups()
60
102
 
61
103
 
62
104
  @l4_help.handle()
@@ -99,7 +141,7 @@ async def _(
99
141
  6. 调用 get_server_detail 函数获取服务器详情,并根据返回结果发送相应的消息。
100
142
  7. 如果 get_server_detail 返回 None,则发送 "服务器无响应" 的文本消息。
101
143
  """
102
-
144
+ logger.info(f"[l4]开始执行请求]:{command}")
103
145
  if start:
104
146
  command = command.replace(start, "")
105
147
  if command == "anne":
@@ -112,7 +154,6 @@ async def _(
112
154
 
113
155
  if not _id:
114
156
  _id = None
115
- logger.info(Gm.no_id)
116
157
  else:
117
158
  logger.info(f"ID: {_id}")
118
159
 
@@ -153,15 +194,24 @@ async def _(
153
194
  logger.info(type(out_msg))
154
195
  if config.l4_connect and isinstance(out_msg, bytes):
155
196
  logger.info(f"connect {one['host']}:{one['port']}")
156
- out_msg = UniMessage.image(raw=out_msg) + UniMessage.text(
197
+ out_msgs = UniMessage.image(raw=out_msg) + UniMessage.text(
198
+ f"\nconnect {one['host']}:{one['port']}",
199
+ )
200
+ elif config.l4_connect and isinstance(out_msg, str):
201
+ logger.info(f"connect {one['host']}:{one['port']}")
202
+ out_msgs = UniMessage.text(out_msg) + UniMessage.text(
157
203
  f"\nconnect {one['host']}:{one['port']}",
158
204
  )
205
+ elif isinstance(out_msg, str):
206
+ out_msgs = UniMessage.text(out_msg)
159
207
  else:
160
- out_msg = UniMessage.text(out_msg)
208
+ out_msgs = UniMessage.image(raw=out_msg)
209
+ return await out_msg_out(out_msgs)
210
+ return None
161
211
  if len(tag_list) == 2:
162
212
  group, name = tag_list
163
213
  await UniMessage.text(f"正在查询{group}组").send()
164
- out: List[OutServer] = await server_find(command=group, is_img=True)
214
+ out = cast(List[OutServer], await server_find(command=group, is_img=True))
165
215
  out_msg = Gm.no_player
166
216
  for one in out:
167
217
  for player in one["player"]:
@@ -171,13 +221,22 @@ async def _(
171
221
  logger.info(type(out_msg))
172
222
  if config.l4_connect and isinstance(out_msg, bytes):
173
223
  logger.info(f"connect {one['host']}:{one['port']}")
174
- out_msg = UniMessage.image(raw=out_msg) + UniMessage.text(
224
+ out_msgs = UniMessage.image(raw=out_msg) + UniMessage.text(
175
225
  f"\nconnect {one['host']}:{one['port']}",
176
226
  )
227
+ elif config.l4_connect and isinstance(out_msg, str):
228
+ logger.info(f"connect {one['host']}:{one['port']}")
229
+ out_msgs = UniMessage.text(out_msg) + UniMessage.text(
230
+ f"\nconnect {one['host']}:{one['port']}",
231
+ )
232
+ elif isinstance(out_msg, str):
233
+ out_msgs = UniMessage.text(out_msg)
177
234
  else:
178
- out_msg = UniMessage.text(out_msg)
235
+ out_msgs = UniMessage.image(raw=out_msg)
179
236
 
180
- return await out_msg_out(out_msg)
237
+ return await out_msg_out(out_msgs)
238
+ return None
239
+ return None
181
240
 
182
241
 
183
242
  @l4_all.handle()
@@ -194,7 +253,7 @@ async def _(args: Message = CommandArg()):
194
253
  await get_ip_server(ip),
195
254
  is_connect=config.l4_connect,
196
255
  host=host,
197
- port=port,
256
+ port=str(port),
198
257
  )
199
258
 
200
259
 
@@ -202,76 +261,79 @@ async def _(args: Message = CommandArg()):
202
261
  async def _(args: Message = CommandArg()):
203
262
  arg = args.extract_plain_text().strip()
204
263
  if not arg:
205
- reload_ip()
206
- logger.success("重载ip完成")
207
264
  with (Path(config.l4_path) / "l4d2.json").open("r", encoding="utf-8") as f:
208
265
  content = f.read().strip()
209
266
  ip_json = json.loads(content)
210
267
  for tag, url in ip_json.items():
211
268
  logger.info(f"重载{tag}的ip")
212
269
  await L4API.get_sourceban(tag, url)
270
+ reload_ip()
271
+ refresh_server_command_rule(l4_request)
272
+ logger.success("重载ip完成")
213
273
  await out_msg_out("重载ip完成")
214
274
 
215
275
 
216
- l4_add_ban = on_command("l4addban", aliases={"l4添加ban"})
217
-
218
-
219
- @l4_add_ban.handle()
220
- async def _(args: Message = CommandArg()):
221
- arg = args.extract_plain_text().strip().split(" ")
222
- if len(arg) != 2:
223
- await UniMessage.text("请在命令后增加响应指令名和网址").finish()
224
-
225
- config_data = read_config(config_path)
226
- config_data.update({arg[0]: arg[1]})
227
- write_config(config_path, config_data)
228
-
229
- await L4API.get_sourceban(arg[0], arg[1])
230
- await UniMessage.text("添加成功\n组名: {arg[0]}\n网址: {arg[1]}").send()
231
-
232
-
233
- l4_del_ban = on_command("l4delban", aliases={"l4删除ban", "l4移除ban"})
234
-
235
-
236
- @l4_del_ban.handle()
237
- async def _(args: Message = CommandArg()):
238
- arg = args.extract_plain_text().strip().split(" ")
239
- if len(arg) not in [1, 2]:
240
- await UniMessage.text("请在命令后增加响应指令名或者带响应网址").finish()
241
- elif len(arg) == 1:
242
- if not Path(Path(config.l4_path) / "config.json").is_file():
243
- await UniMessage.text("没有添加过组名").finish()
244
- else:
245
- with (Path(config.l4_path) / "config.json").open(
246
- "r",
247
- encoding="utf-8",
248
- ) as f:
249
- content = f.read().strip()
250
- config_data = json.loads(content)
251
- if arg[0] not in config_data:
252
- await UniMessage.text("没有添加过这个组").finish()
253
- else:
254
- del config_data[arg[0]]
255
- async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
256
- json.dump(config_data, f, ensure_ascii=False, indent=4)
257
- await out_msg_out(f"删除成功,组名:{arg[0]}")
258
- elif len(arg) == 2:
259
- if not Path(Path(config.l4_path) / "config.json").is_file():
260
- await UniMessage.text("没有添加过组名").finish()
261
- else:
262
- with (Path(config.l4_path) / "config.json").open(
263
- "r",
264
- encoding="utf-8",
265
- ) as f:
266
- content = f.read().strip()
267
- config_datas = json.loads(content)
268
- if arg[0] not in config_datas:
269
- await UniMessage.text("没有添加过这个组").finish()
270
- else:
271
- config_datas[arg[0]] = arg[1]
272
- async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
273
- json.dump(config_datas, f, ensure_ascii=False, indent=4)
274
- await out_msg_out(f"修改成功,组名:{arg[0]},网址:{arg[1]}")
276
+ # l4_add_ban = on_command("l4addban", aliases={"l4添加ban"})
277
+
278
+
279
+ # @l4_add_ban.handle()
280
+ # async def _(args: Message = CommandArg()):
281
+ # arg = args.extract_plain_text().strip().split(" ")
282
+ # if len(arg) != 2:
283
+ # await UniMessage.text("请在命令后增加响应指令名和网址").finish()
284
+
285
+ # config_data = read_config(config_path)
286
+ # config_data.update({arg[0]: arg[1]})
287
+ # write_config(config_path, config_data)
288
+
289
+ # await L4API.get_sourceban(arg[0], arg[1])
290
+ # reload_ip()
291
+ # refresh_server_command_rule(l4_request)
292
+ # await UniMessage.text("添加成功\n组名: {arg[0]}\n网址: {arg[1]}").send()
293
+
294
+
295
+ # l4_del_ban = on_command("l4delban", aliases={"l4删除ban", "l4移除ban"})
296
+
297
+
298
+ # @l4_del_ban.handle()
299
+ # async def _(args: Message = CommandArg()):
300
+ # arg = args.extract_plain_text().strip().split(" ")
301
+ # if len(arg) not in [1, 2]:
302
+ # await UniMessage.text("请在命令后增加响应指令名或者带响应网址").finish()
303
+ # elif len(arg) == 1:
304
+ # if not Path(Path(config.l4_path) / "config.json").is_file():
305
+ # await UniMessage.text("没有添加过组名").finish()
306
+ # else:
307
+ # with (Path(config.l4_path) / "config.json").open(
308
+ # "r",
309
+ # encoding="utf-8",
310
+ # ) as f:
311
+ # content = f.read().strip()
312
+ # config_data = json.loads(content)
313
+ # if arg[0] not in config_data:
314
+ # await UniMessage.text("没有添加过这个组").finish()
315
+ # else:
316
+ # del config_data[arg[0]]
317
+ # async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
318
+ # json.dump(config_data, f, ensure_ascii=False, indent=4)
319
+ # await out_msg_out(f"删除成功,组名:{arg[0]}")
320
+ # elif len(arg) == 2:
321
+ # if not Path(Path(config.l4_path) / "config.json").is_file():
322
+ # await UniMessage.text("没有添加过组名").finish()
323
+ # else:
324
+ # with (Path(config.l4_path) / "config.json").open(
325
+ # "r",
326
+ # encoding="utf-8",
327
+ # ) as f:
328
+ # content = f.read().strip()
329
+ # config_datas = json.loads(content)
330
+ # if arg[0] not in config_datas:
331
+ # await UniMessage.text("没有添加过这个组").finish()
332
+ # else:
333
+ # config_datas[arg[0]] = arg[1]
334
+ # async with aiofiles.open(config_path, "w", encoding="utf-8") as f:
335
+ # json.dump(config_datas, f, ensure_ascii=False, indent=4)
336
+ # await out_msg_out(f"修改成功,组名:{arg[0]},网址:{arg[1]}")
275
337
 
276
338
 
277
339
  if "云" in COMMAND:
@@ -0,0 +1 @@
1
+ """Command utilities for L4D2 server plugin."""
@@ -1,10 +1,10 @@
1
1
  from pathlib import Path
2
- from typing import List, Set
2
+ from typing import List
3
3
 
4
4
  from nonebot import get_plugin_config
5
5
  from nonebot.adapters.onebot.v11 import GROUP_ADMIN, GROUP_MEMBER, GROUP_OWNER
6
6
  from nonebot.log import logger
7
- from nonebot.permission import SUPERUSER
7
+ from nonebot.permission import SUPERUSER, Permission
8
8
  from pydantic import BaseModel, Field, field_validator
9
9
 
10
10
  # 常量定义
@@ -27,7 +27,6 @@ def init_data_directory(data_dir: Path) -> None:
27
27
  # 初始化目录结构
28
28
  DATAOUT = Path(DEFAULT_DATA_DIR)
29
29
  init_data_directory(DATAOUT)
30
- init_data_directory(DATAOUT / "l4d2")
31
30
  server_all_path = DATAOUT / "l4d2"
32
31
  server_all_path.mkdir(parents=True, exist_ok=True)
33
32
 
@@ -82,10 +81,10 @@ class ConfigModel(BaseModel):
82
81
  """更新地图索引配置"""
83
82
  if index < 0:
84
83
  raise ValueError("地图索引不能小于0")
85
- self._config.map_index = index
84
+ self.map_index = index
86
85
 
87
86
  @property
88
- def l4_permission_set(self) -> Set[int]:
87
+ def l4_permission_set(self) -> Permission:
89
88
  permissions = {
90
89
  1: SUPERUSER,
91
90
  2: SUPERUSER | GROUP_OWNER,
@@ -140,7 +139,11 @@ class ConfigManager:
140
139
  if key not in valid_keys:
141
140
  raise ValueError(f"无效的配置项: {key}")
142
141
 
143
- field_type = ConfigModel[key].type_
142
+ field_info = ConfigModel.model_fields[key]
143
+ field_type = field_info.annotation
144
+ if not field_type:
145
+ continue
146
+
144
147
  if not isinstance(value, field_type):
145
148
  raise TypeError(f"{key} 必须是 {field_type.__name__} 类型")
146
149
 
@@ -148,7 +151,7 @@ class ConfigManager:
148
151
 
149
152
  # 验证更新后的配置
150
153
  try:
151
- self._config = ConfigModel(**self._config.dict())
154
+ self._config = ConfigModel(**self._config.model_dump())
152
155
  except ValueError as e:
153
156
  logger.error(f"配置更新失败: {e!s}")
154
157
 
@@ -0,0 +1,166 @@
1
+ # nonebot_plugin_l4d2_server/commands/server_groups.py
2
+ from __future__ import annotations
3
+
4
+ import ujson as json
5
+ from nonebot import on_command
6
+ from nonebot.adapters.onebot.v11 import Message
7
+ from nonebot.params import CommandArg
8
+ from nonebot_plugin_alconna import UniMessage
9
+
10
+ from ..l4_request import reload_ip
11
+ from ..utils.api.request import L4D2Api
12
+ from ..utils.group_store import (
13
+ export_all,
14
+ get_group,
15
+ list_groups,
16
+ remove_group,
17
+ set_group,
18
+ )
19
+ from ..utils.sb_sources import del_page, get_page, load_pages, set_page
20
+ from .utils import refresh_server_command_rule
21
+
22
+ l4_request = on_command("anne", priority=10)
23
+ refresh_server_command_rule(l4_request)
24
+
25
+
26
+ async def _delete_group_and_page(tag: str) -> tuple[bool, bool]:
27
+ """删除服务器组文件及对应的 URL 配置"""
28
+ group_deleted = await remove_group(tag)
29
+ page_deleted = await del_page(tag)
30
+ return group_deleted, page_deleted
31
+
32
+
33
+ # l4addban <组名> [SourceBans服务器页URL]
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导出全部组"})
47
+
48
+
49
+ @l4_add_ban.handle()
50
+ async def _(args: Message = CommandArg()):
51
+ text = args.extract_plain_text().strip()
52
+ if not text:
53
+ await UniMessage.text("用法:l4addban <组名> [SourceBans服务器页URL]").finish()
54
+
55
+ parts = text.split(None, 1)
56
+ tag = parts[0]
57
+ url = parts[1] if len(parts) > 1 else None
58
+
59
+ # 如果本次传了 URL,则记入 data/L4D2/sb_pages.json
60
+ if url:
61
+ await set_page(tag, url)
62
+
63
+ page = url or await get_page(tag)
64
+ if not page:
65
+ await UniMessage.text(
66
+ f"未在 data/L4D2/sb_pages.json 找到组“{tag}”的 URL;请执行:l4addban {tag} <URL>",
67
+ ).finish()
68
+
69
+ api = L4D2Api()
70
+ # try:
71
+ server_list = await api.get_sourceban(tag, page)
72
+ # except Exception as e:
73
+ # await UniMessage.text(f"抓取失败:{e}").finish()
74
+
75
+ path = await set_group(tag, server_list)
76
+ await UniMessage.text(
77
+ f"✅ 已更新:{path.name}(共 {len(server_list)} 台)",
78
+ ).finish()
79
+
80
+
81
+ @l4_reload_sb.handle()
82
+ async def _():
83
+ pages = await load_pages()
84
+ if not pages:
85
+ await UniMessage.text(
86
+ "data/L4D2/sb_pages.json 为空,先用:l4addban <组名> <URL>",
87
+ ).finish()
88
+
89
+ api = L4D2Api()
90
+ ok, fail = 0, []
91
+ for tag, page in pages.items():
92
+ try:
93
+ servers = await api.get_sourceban(tag, page)
94
+ await set_group(tag, servers)
95
+ ok += 1
96
+ except Exception as e:
97
+ fail.append(f"{tag}: {e}")
98
+
99
+ msg = [f"✅ 刷新完成:成功 {ok} 个组。"]
100
+ if fail:
101
+ msg.append("❌ 失败:\n" + "\n".join(fail))
102
+ await UniMessage.text("\n".join(msg)).send()
103
+ reload_ip()
104
+ refresh_server_command_rule(l4_request)
105
+
106
+
107
+ @l4_list_groups.handle()
108
+ async def _():
109
+ names = await list_groups()
110
+ if not names:
111
+ await UniMessage.text("暂无服务器组。").finish()
112
+ lines = []
113
+ for name in names:
114
+ items = await get_group(name)
115
+ lines.append(f"{name}({len(items)})")
116
+ await UniMessage.text("现有服务器组:\n" + "\n".join(lines)).finish()
117
+
118
+
119
+ @l4_del_group.handle()
120
+ async def _(args: Message = CommandArg()):
121
+ tag = args.extract_plain_text().strip()
122
+ if not tag:
123
+ await UniMessage.text("用法:l4delgroup <组名>").finish()
124
+ group_deleted, page_deleted = await _delete_group_and_page(tag)
125
+
126
+ if not group_deleted and not page_deleted:
127
+ await UniMessage.text("未找到该组文件或 URL 记录").finish()
128
+ return
129
+
130
+ msg_parts = []
131
+ if group_deleted:
132
+ msg_parts.append("服务器组文件")
133
+ if page_deleted:
134
+ msg_parts.append("SourceBans URL")
135
+ await UniMessage.text("✅ 已删除 " + "、".join(msg_parts)).send()
136
+ reload_ip()
137
+ refresh_server_command_rule(l4_request)
138
+
139
+
140
+ @l4_del_page.handle()
141
+ async def _(args: Message = CommandArg()):
142
+ tag = args.extract_plain_text().strip()
143
+ if not tag:
144
+ await UniMessage.text("用法:l4delpage <组名>").finish()
145
+ ok = await del_page(tag)
146
+ await UniMessage.text("✅ 已删除" if ok else "未找到该组的 URL").finish()
147
+
148
+
149
+ @l4_export_group.handle()
150
+ async def _(args: Message = CommandArg()):
151
+ tag = args.extract_plain_text().strip()
152
+ if not tag:
153
+ await UniMessage.text("用法:l4exportgroup <组名>").finish()
154
+ items = await get_group(tag)
155
+ if not items:
156
+ await UniMessage.text("未找到该组。").finish()
157
+ data = {tag: items}
158
+ await UniMessage.text(json.dumps(data, ensure_ascii=False, indent=4)).finish()
159
+
160
+
161
+ @l4_export_groups.handle()
162
+ async def _():
163
+ data = await export_all()
164
+ if not data:
165
+ await UniMessage.text("暂无服务器组。").finish()
166
+ await UniMessage.text(json.dumps(data, ensure_ascii=False, indent=4)).finish()
@@ -0,0 +1,11 @@
1
+ from nonebot.matcher import Matcher
2
+ from nonebot.rule import command as command_rule
3
+
4
+ from ..l4_request import COMMAND
5
+
6
+
7
+ def refresh_server_command_rule(l4_request: type[Matcher]) -> None:
8
+ """根据最新的服务器组刷新命令别名"""
9
+ commands = {"anne"}
10
+ commands.update(COMMAND)
11
+ l4_request.rule = command_rule(*commands)
@@ -73,6 +73,58 @@
73
73
  }
74
74
  ]
75
75
  },
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
+ ],
76
128
  "其他服务": {
77
129
  "desc": "一些杂项服务",
78
130
  "data": [
@@ -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.1.6"
13
+ __version__ = "1.2.0"
14
14
  TEXT_PATH = Path(__file__).parent / "texture2d"
15
15
  HELP_DATA = Path(__file__).parent / "help.json"
16
16