nonebot-plugin-l4d2-server 1.3.5__tar.gz → 1.4.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 (117) hide show
  1. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/PKG-INFO +151 -7
  2. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/README.md +147 -5
  3. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/__init__.py +128 -0
  4. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/api/l4d2.py +164 -40
  5. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/__init__.py +31 -0
  6. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/commands/admin.py +11 -2
  7. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/favorite.py +119 -0
  8. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/fuzzy_search.py +151 -0
  9. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/history.py +117 -0
  10. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/local.py +296 -0
  11. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/server_control.py +263 -0
  12. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/commands/server_mgmt.py +156 -0
  13. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/config.py +39 -6
  14. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/consts.py +4 -2
  15. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/http_helpers.py +37 -5
  16. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/messages.py +6 -0
  17. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/registry.py +304 -0
  18. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/background.py +11 -6
  19. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help.py +0 -1
  20. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/server_list.py +39 -9
  21. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/normal.html +11 -2
  22. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/style.css +30 -0
  23. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/__init__.py +16 -2
  24. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/services/errors.py +69 -0
  25. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/services/favorite.py +442 -0
  26. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/services/history.py +177 -0
  27. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/services/path_resolver.py +84 -0
  28. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/server_query.py +64 -8
  29. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/sourceban.py +23 -10
  30. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/services/workshop.py +184 -0
  31. nonebot_plugin_l4d2_server-1.4.0/nonebot_plugin_l4d2_server/store/groups.py +330 -0
  32. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/store/pages.py +3 -5
  33. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/version.py +1 -1
  34. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server.egg-info/PKG-INFO +151 -7
  35. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server.egg-info/SOURCES.txt +10 -0
  36. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server.egg-info/requires.txt +2 -0
  37. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/pyproject.toml +3 -1
  38. nonebot_plugin_l4d2_server-1.4.0/tests/test_a2s_cache.py +248 -0
  39. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/__init__.py +0 -68
  40. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/commands/__init__.py +0 -9
  41. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/commands/local.py +0 -210
  42. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/registry.py +0 -199
  43. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/services/workshop.py +0 -66
  44. nonebot_plugin_l4d2_server-1.3.5/nonebot_plugin_l4d2_server/store/groups.py +0 -104
  45. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/LICENSE +0 -0
  46. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/api/__init__.py +0 -0
  47. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/api/models.py +0 -0
  48. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/api/sources.py +0 -0
  49. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/commands/ban.py +0 -0
  50. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/commands/query.py +0 -0
  51. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/__init__.py +0 -0
  52. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/backgrounds/background.jpg +0 -0
  53. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/fonts/loli.ttf +0 -0
  54. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/fonts.py +0 -0
  55. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/Help.json +0 -0
  56. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//344/273/213/347/273/215.png" +0 -0
  57. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//344/273/273/345/212/241.png" +0 -0
  58. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//344/277/241/346/201/257.png" +0 -0
  59. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/205/254/345/221/212.png" +0 -0
  60. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/210/200/345/211/221.png" +0 -0
  61. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/210/207/346/215/242.png" +0 -0
  62. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/210/240/351/231/244.png" +0 -0
  63. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/210/267/346/226/260.png" +0 -0
  64. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/215/241/347/273/204.png" +0 -0
  65. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/223/252/351/207/214.png" +0 -0
  66. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/234/260/345/233/276.png" +0 -0
  67. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/257/274/345/205/245.png" +0 -0
  68. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/257/274/345/207/272.png" +0 -0
  69. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//345/275/261.png" +0 -0
  70. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/213/274/345/233/276.png" +0 -0
  71. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/216/242/347/264/242.png" +0 -0
  72. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/216/250/351/200/201.png" +0 -0
  73. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/224/266/351/233/206.png" +0 -0
  74. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/224/273/347/225/245.png" +0 -0
  75. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/233/264/346/226/260.png" +0 -0
  76. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/235/220/346/226/231.png" +0 -0
  77. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/237/245/350/257/242.png" +0 -0
  78. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/240/241/351/252/214.png" +0 -0
  79. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/257/217/346/234/210.png" +0 -0
  80. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/267/261/346/270/212.png" +0 -0
  81. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/267/273/345/212/240.png" +0 -0
  82. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//346/270/205/351/231/244.png" +0 -0
  83. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//347/212/266/346/200/201.png" +0 -0
  84. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//347/255/276/345/210/260.png" +0 -0
  85. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//347/273/221/345/256/232.png" +0 -0
  86. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//350/241/250.png" +0 -0
  87. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//350/241/250/346/203/205.png" +0 -0
  88. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//350/247/222/350/211/262.png" +0 -0
  89. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//350/256/260/345/275/225.png" +0 -0
  90. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//351/205/215/347/275/256.png" +0 -0
  91. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/icons//351/207/215/345/220/257.png" +0 -0
  92. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/textures/badge.png +0 -0
  93. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/textures/banner.png +0 -0
  94. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/textures/bg.jpg +0 -0
  95. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/textures/button.png +0 -0
  96. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/help/textures/icon.png +0 -0
  97. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/images.py +0 -0
  98. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/server_card.py +0 -0
  99. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/github.svg +0 -0
  100. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/l.svg +0 -0
  101. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/m.svg +0 -0
  102. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/normal_old.html +0 -0
  103. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/vac.png +0 -0
  104. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/vac_white.png +0 -0
  105. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/vue.css +0 -0
  106. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/w.svg +0 -0
  107. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/templates/workshop.html +0 -0
  108. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/render/workshop.py +0 -0
  109. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/filter.py +0 -0
  110. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/local_server.py +0 -0
  111. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/services/migrate.py +0 -0
  112. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server/store/__init__.py +0 -0
  113. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server.egg-info/dependency_links.txt +0 -0
  114. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/nonebot_plugin_l4d2_server.egg-info/top_level.txt +0 -0
  115. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/setup.cfg +0 -0
  116. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/tests/test_migrate.py +0 -0
  117. {nonebot_plugin_l4d2_server-1.3.5 → nonebot_plugin_l4d2_server-1.4.0}/tests/test_registry.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-l4d2-server
3
- Version: 1.3.5
3
+ Version: 1.4.0
4
4
  Summary: L4D2 server related operations plugin for NoneBot2
5
5
  Author-email: Agnes_Digital <Z735803792@163.com>
6
6
  License: GPLv3
7
7
  Project-URL: homepage, https://github.com/Agnes4m/nonebot_plugin_l4d2_server
8
- Keywords: steam,game,l4d2,nonebot2,plugin
8
+ Keywords: steam,game,l4d2,nonebot2,plugin,favorites,subscription
9
9
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
10
  Classifier: Programming Language :: Python
11
11
  Classifier: Programming Language :: Python :: 3
@@ -21,6 +21,8 @@ License-File: LICENSE
21
21
  Requires-Dist: nonebot2>=2.1.0
22
22
  Requires-Dist: nonebot2[fastapi]>=2.3.3
23
23
  Requires-Dist: nonebot-plugin-htmlrender>=0.3.0
24
+ Requires-Dist: nonebot-plugin-localstore>=0.7.0
25
+ Requires-Dist: nonebot-plugin-apscheduler>=0.5.0
24
26
  Requires-Dist: nonebot-adapter-onebot>=2.4.4
25
27
  Requires-Dist: nonebot-plugin-alconna>=0.50.0
26
28
  Requires-Dist: aiohttp>=3.8.4
@@ -45,7 +47,7 @@ Dynamic: license-file
45
47
 
46
48
  <div align="center">
47
49
 
48
- # nonebot_plugin_l4d2_server 1.3.0
50
+ # nonebot_plugin_l4d2_server 1.4.0
49
51
 
50
52
  _✨Nonebot & Left 4 Dead 2 server 操作 ✨_
51
53
 
@@ -190,18 +192,120 @@ conda install nonebot-plugin-l4d2-server
190
192
  </details>
191
193
  </details>
192
194
 
195
+ ### 额外依赖:Playwright 浏览器内核
196
+
197
+ 本插件出图走 `nonebot-plugin-htmlrender` → Playwright,需要 Chromium 内核。
198
+ 直接 `pip / pdm / poetry add` 装出来的 playwright 不会自动下载浏览器,
199
+ 启动时会报 `Executable doesn't exist ... chrome-win64/chrome.exe` 这类错。
200
+
201
+ 按你的包管理器二选一:
202
+
203
+ ```bash
204
+ # uv(推荐,nonebot2 社区主流)
205
+ uv tool install playwright
206
+ uv run playwright install --with-deps chromium
207
+
208
+ # 或 pipx(隔离环境装全局命令)
209
+ pipx install playwright
210
+ pipx run playwright install --with-deps chromium
211
+
212
+ # 或直接 pip
213
+ pip install playwright
214
+ playwright install --with-deps chromium
215
+ ```
216
+
217
+ > 如果你用 `uv` 跑 bot(即 `uv run` 启动 bot 进程),第一次启动 bot 自己会调
218
+ > `playwright install chromium`,无需上面手工步骤;切到其他用户 / 全局
219
+ > python 时才需要手动装。
220
+ >
221
+ > htmlrender `0.7+` 拆成了 provider 架构并强依赖 `nonebot-plugin-filehost`,
222
+ > 0.6.x 仍提供 `html_to_pic`。本插件 `pyproject.toml` 锁定 `>=0.6.0,<0.7`,
223
+ > 升级前先看 `#104`。
224
+
193
225
  ## 主要功能
194
226
 
195
227
  - [x] 求生服务器-本地多路径操作(传地图等)
196
228
  - [x] 批量查询指定 ip 服务器状态和玩家
197
229
  - [x] connect 指令直接呼出服务器信息
198
230
  - [x] 根据用户名,在已知服务器搜索玩家信息
231
+ - [x] **服务器订阅 / 收藏 + 定时推送**(v1.4.0):上线 / 离线 / 玩家数突变时自动通知群
232
+ - [x] **单服 CRUD 指令**(v1.4.0):不用手动编辑 JSON
233
+ - [x] **创意工坊批量并发下载**(v1.4.0):流式写入 + 进度回报
234
+
235
+ ## 新指令速览(v1.4.0)
236
+
237
+ | 指令 | 别名 | 权限 | 用途 |
238
+ |---|---|---|---|
239
+ | `l4收藏 <组> <id>` | `l4fav`、`l4_favorite` | — | 在群聊触发,自动记住本群为推送目标 |
240
+ | `l4取关 <组> <id>` | `l4unfav`、`l4_unfavorite` | — | 取消本群订阅(不影响其他群) |
241
+ | `l4收藏列表` | `l4favlist`、`l4_list_favorites` | — | 列出本群订阅 |
242
+ | `l4通知目标 <组> <id> <群号>` | `l4notifytarget` | SUPERUSER | 把订阅的推送目标改成别的群 |
243
+ | `l4添加服务器 <组> host:port` | `l4_add_server`、`l4addserver` | SUPERUSER | 新增单服到指定组 |
244
+ | `l4删除服务器 <组> <id或ip>` | `l4_del_server`、`l4delserver` | SUPERUSER | 删除组内单服 |
245
+ | `l4修改服务器 <组> <id> <新ip>` | `l4_edit_server`、`l4editserver` | SUPERUSER | 改单服 ip |
246
+ | `l4查看组 <组>` | `l4showgroup`、`l4列服务器` | SUPERUSER | 列组成员 + 在线状态 |
247
+ | `l4创意工坊 id1,id2 id3` | — | `l4_permission_set` | 批量并发下载(逗号/空格/换行分隔) |
248
+
249
+ ## 数据目录(localstore 默认开启)
250
+
251
+ v1.4.0 起,默认用 `nonebot-plugin-localstore` 自动生成插件同名数据目录,
252
+ 典型路径:`./data/nonebot_plugin_l4d2_server/l4d2/`(受 `LOCALSTORE_USE_CWD`
253
+ 和 `l4_localstore_subdir` 影响)。首次启动时若新目录为空且旧的
254
+ `./data/L4D2/` 仍有内容,会一次性复制过去(旧目录保留以便手动清理)。
255
+
256
+ 不想用 localstore:在 `.env` 里设 `L4_USE_LOCALSTORE=false`,回到老的
257
+ 相对 `l4_path` 模式。
258
+
259
+ 新增 `.env` 字段:
260
+
261
+ ```dotenv
262
+ # 路径
263
+ L4_USE_LOCALSTORE=true # 是否走 localstore 自动路径
264
+ L4_LOCALSTORE_SUBDIR=l4d2 # localstore 下的子目录名
265
+
266
+ # A2S 性能
267
+ L4_A2S_CONCURRENCY=8 # 同时最多几台服务器在查(信号量上限)
268
+ L4_A2S_TIMEOUT=2.5 # 单次 ainfo / aplayers 超时秒
269
+ L4_A2S_CACHE_TTL=15 # 结果缓存秒;0=不缓存
270
+
271
+ # 订阅 / 巡检
272
+ L4_FAVORITE_CHECK_INTERVAL=300 # 巡检间隔秒(≥30)
273
+ L4_FAVORITE_PLAYER_DELTA=5 # 玩家数变化超过此值才推送
274
+
275
+ # 工坊
276
+ L4_WORKSHOP_CONCURRENCY=3 # 批量下载并发上限(1~8)
277
+ ```
278
+
279
+ ## 屏蔽与关键词 — 实现思路(v1.4.0 未实现,仅文档)
280
+
281
+ 下面四种思路由浅入深,可按需选一种或叠加:
282
+
283
+ 1. **SourceBans 自动同步**:定时拉 SourceBans banlist 落到本地
284
+ `<data_dir>/blocklist.json`;A2S 查服后过滤掉已在 banlist 的 IP,
285
+ 渲染层不再展示这些服。
286
+ 2. **本地 JSON 黑名单**:管理员 `l4黑名单 add <ip>` 写入
287
+ `<data_dir>/blocklist.json`;查询结果按黑名单过滤。
288
+ 3. **SourceMod HTTP 聊天镜像**:服务器装 SM 插件暴露 HTTP 接口,
289
+ 机器人拉聊天记录后正则匹配违规词,命中后通过 RCON 自动 kick。
290
+ 4. **关键词正则匹配**:新增配置 `l4_block_keywords: list[str]`;
291
+ 玩家名或服务器名命中则过滤。配合方案 1 自动入库效果最佳。
292
+
293
+ 四类方案都需要新增一个 `services/blocklist.py` + `commands/blocklist.py`
294
+ + `services/filters.py`(在 A2S 结果与渲染之间插入过滤器)。当前
295
+ v1.4.0 已预留 `consts.BLOCKLIST_FILENAME` 常量,避免后续硬编码。
199
296
 
200
297
  ## [数据结构](./docs/standand.md)
201
298
 
202
- > 服务器组文件存放位置:`<l4_path>/<组名>.json`(默认 `data/L4D2/<组名>.json`),旧版 `<l4_path>/l4d2/` 子目录会在启动时自动迁移。
203
- >
204
- > 所有数据路径(组文件、sb_pages、自定义背景图、迁移脚本)都跟着 `l4_path` 配置走,CWD 在哪都无所谓。改 `l4_path` 一处生效。
299
+ > 服务器组文件存放位置:`<data_dir>/<组名>.json`。
300
+ > `<data_dir>` 默认 `data/L4D2`;开启 localstore 后变为
301
+ > `<localstore>/nonebot_plugin_l4d2_server/l4d2/`。
302
+ > 旧版 `<data_dir>/l4d2/` 子目录与 `<data_dir>/l4d2.json` 单文件
303
+ > 都会在启动时自动迁移。
304
+
305
+ 收藏相关数据:
306
+
307
+ - `<data_dir>/favorites.json` — 收藏条目列表
308
+ - `<data_dir>/notify_state.json` — 上次推送状态(避免抖动刷屏)
205
309
 
206
310
  ## env 设置
207
311
 
@@ -212,13 +316,29 @@ conda install nonebot-plugin-l4d2-server
212
316
  """是否启用图片"""
213
317
  l4_connect = True
214
318
  """是否在查服命令后加入connect ip"""
319
+ l4_use_localstore = True
320
+ """是否走 nonebot-plugin-localstore 自动生成插件同名数据目录"""
321
+ l4_localstore_subdir = "l4d2"
322
+ """localstore 下的子目录名"""
215
323
  l4_path = "data/L4D2"
216
- """插件数据根目录。组 JSON / sb_pages / 自定义背景图 / 迁移脚本都从这里派生。"""
324
+ """l4_use_localstore=False 时使用的相对路径"""
217
325
  l4_players = 4
218
326
  """查询总图的时候展示的用户数量"""
219
327
  l4_style = "default"
220
328
  """图片风格,可选包括以下
221
329
  - 简洁
330
+ l4_a2s_concurrency = 8
331
+ """A2S 并发上限(信号量)"""
332
+ l4_a2s_timeout = 2.5
333
+ """A2S 单次超时秒"""
334
+ l4_a2s_cache_ttl = 15
335
+ """A2S 结果缓存秒;0=不缓存"""
336
+ l4_favorite_check_interval = 300
337
+ """收藏巡检间隔秒"""
338
+ l4_favorite_player_delta = 5
339
+ """玩家数变化超过此值才推送"""
340
+ l4_workshop_concurrency = 3
341
+ """创意工坊批量下载并发上限"""
222
342
  ```
223
343
 
224
344
  ## 和 0.x.x 更改部分
@@ -230,6 +350,30 @@ conda install nonebot-plugin-l4d2-server
230
350
  - **查服背景图按渲染类型拆分目录**(后续调整):`/云`(服务器列表)从 `<l4_path>/custom_backgrounds/` 根目录的所有图片中随机抽一张,目录为空时回退到内置 `background.jpg`;`/云1`(单服务器卡)固定使用深蓝灰纯色,不加载任何图片。详见「自定义服务器列表背景图片」;
231
351
  - **数据路径统一从 `l4_path` 派生**:组文件、sb_pages、自定义背景图、迁移脚本都跟着 `l4_path` 配置走,不再各自写死相对路径。`.env` 里改 `L4_PATH` 一处即生效,不用再管 bot 启动 CWD。
232
352
 
353
+ ## v1.4.0 相对 v1.3.x 的变化
354
+
355
+ - **localstore 路径**:默认用 `nonebot-plugin-localstore` 自动生成
356
+ 插件同名数据目录;可通过 `L4_USE_LOCALSTORE=false` 退回旧路径。
357
+ - **A2S 性能**:批量查询加 `asyncio.Semaphore` 上限
358
+ (`l4_a2s_concurrency`),单次超时可配(`l4_a2s_timeout`),
359
+ 结果缓存 `l4_a2s_cache_ttl` 秒(deepcopy 防止下游 mutate);
360
+ SourceBans `refresh_all_pages` 改并发。
361
+ - **收藏 / 订阅**:新增 `l4收藏` / `l4取关` / `l4收藏列表` /
362
+ `l4通知目标`;scheduler 周期巡检(`l4_favorite_check_interval`),
363
+ 上线 / 离线 / 玩家数突变时按群推送。
364
+ - **单服 CRUD**:新增 `l4添加服务器` / `l4删除服务器` / `l4修改服务器` /
365
+ `l4查看组`,ID 稳定不再重排。
366
+ - **创意工坊批量**:`l4创意工坊 123,456 789` 并发下载
367
+ (`l4_workshop_concurrency`),流式写入 + 进度回报。
368
+ - **`tj` / `zl` / `kl` 注册时序 bug**:改为在 `_on_startup` 内调用
369
+ `register_picker_handlers()`,避免导入时 `registry.commands` 还没填。
370
+ - **统一异常类型**:`services/errors.py` 提供 `L4Error` / `L4ServerUnreachableError` /
371
+ `L4TimeoutError` / `L4InvalidInputError` / `L4NotFoundError` / `L4HTTPError`,
372
+ 后续 handler 收敛 `except L4Error`。
373
+ - **`http_helpers.save_url_to_file` dead code** 修复;
374
+ 新增 `stream_download` 流式下载接口。
375
+ - **`http_helpers.STREAM_CHUNK_SIZE` / `STREAM_TIMEOUT`** 新常量。
376
+
233
377
  ## 其他
234
378
 
235
379
  - anne 部分,已移植到[这里](https://github.com/Agnes4m/L4D2UID),通过 core 插件调用
@@ -7,7 +7,7 @@
7
7
 
8
8
  <div align="center">
9
9
 
10
- # nonebot_plugin_l4d2_server 1.3.0
10
+ # nonebot_plugin_l4d2_server 1.4.0
11
11
 
12
12
  _✨Nonebot & Left 4 Dead 2 server 操作 ✨_
13
13
 
@@ -152,18 +152,120 @@ conda install nonebot-plugin-l4d2-server
152
152
  </details>
153
153
  </details>
154
154
 
155
+ ### 额外依赖:Playwright 浏览器内核
156
+
157
+ 本插件出图走 `nonebot-plugin-htmlrender` → Playwright,需要 Chromium 内核。
158
+ 直接 `pip / pdm / poetry add` 装出来的 playwright 不会自动下载浏览器,
159
+ 启动时会报 `Executable doesn't exist ... chrome-win64/chrome.exe` 这类错。
160
+
161
+ 按你的包管理器二选一:
162
+
163
+ ```bash
164
+ # uv(推荐,nonebot2 社区主流)
165
+ uv tool install playwright
166
+ uv run playwright install --with-deps chromium
167
+
168
+ # 或 pipx(隔离环境装全局命令)
169
+ pipx install playwright
170
+ pipx run playwright install --with-deps chromium
171
+
172
+ # 或直接 pip
173
+ pip install playwright
174
+ playwright install --with-deps chromium
175
+ ```
176
+
177
+ > 如果你用 `uv` 跑 bot(即 `uv run` 启动 bot 进程),第一次启动 bot 自己会调
178
+ > `playwright install chromium`,无需上面手工步骤;切到其他用户 / 全局
179
+ > python 时才需要手动装。
180
+ >
181
+ > htmlrender `0.7+` 拆成了 provider 架构并强依赖 `nonebot-plugin-filehost`,
182
+ > 0.6.x 仍提供 `html_to_pic`。本插件 `pyproject.toml` 锁定 `>=0.6.0,<0.7`,
183
+ > 升级前先看 `#104`。
184
+
155
185
  ## 主要功能
156
186
 
157
187
  - [x] 求生服务器-本地多路径操作(传地图等)
158
188
  - [x] 批量查询指定 ip 服务器状态和玩家
159
189
  - [x] connect 指令直接呼出服务器信息
160
190
  - [x] 根据用户名,在已知服务器搜索玩家信息
191
+ - [x] **服务器订阅 / 收藏 + 定时推送**(v1.4.0):上线 / 离线 / 玩家数突变时自动通知群
192
+ - [x] **单服 CRUD 指令**(v1.4.0):不用手动编辑 JSON
193
+ - [x] **创意工坊批量并发下载**(v1.4.0):流式写入 + 进度回报
194
+
195
+ ## 新指令速览(v1.4.0)
196
+
197
+ | 指令 | 别名 | 权限 | 用途 |
198
+ |---|---|---|---|
199
+ | `l4收藏 <组> <id>` | `l4fav`、`l4_favorite` | — | 在群聊触发,自动记住本群为推送目标 |
200
+ | `l4取关 <组> <id>` | `l4unfav`、`l4_unfavorite` | — | 取消本群订阅(不影响其他群) |
201
+ | `l4收藏列表` | `l4favlist`、`l4_list_favorites` | — | 列出本群订阅 |
202
+ | `l4通知目标 <组> <id> <群号>` | `l4notifytarget` | SUPERUSER | 把订阅的推送目标改成别的群 |
203
+ | `l4添加服务器 <组> host:port` | `l4_add_server`、`l4addserver` | SUPERUSER | 新增单服到指定组 |
204
+ | `l4删除服务器 <组> <id或ip>` | `l4_del_server`、`l4delserver` | SUPERUSER | 删除组内单服 |
205
+ | `l4修改服务器 <组> <id> <新ip>` | `l4_edit_server`、`l4editserver` | SUPERUSER | 改单服 ip |
206
+ | `l4查看组 <组>` | `l4showgroup`、`l4列服务器` | SUPERUSER | 列组成员 + 在线状态 |
207
+ | `l4创意工坊 id1,id2 id3` | — | `l4_permission_set` | 批量并发下载(逗号/空格/换行分隔) |
208
+
209
+ ## 数据目录(localstore 默认开启)
210
+
211
+ v1.4.0 起,默认用 `nonebot-plugin-localstore` 自动生成插件同名数据目录,
212
+ 典型路径:`./data/nonebot_plugin_l4d2_server/l4d2/`(受 `LOCALSTORE_USE_CWD`
213
+ 和 `l4_localstore_subdir` 影响)。首次启动时若新目录为空且旧的
214
+ `./data/L4D2/` 仍有内容,会一次性复制过去(旧目录保留以便手动清理)。
215
+
216
+ 不想用 localstore:在 `.env` 里设 `L4_USE_LOCALSTORE=false`,回到老的
217
+ 相对 `l4_path` 模式。
218
+
219
+ 新增 `.env` 字段:
220
+
221
+ ```dotenv
222
+ # 路径
223
+ L4_USE_LOCALSTORE=true # 是否走 localstore 自动路径
224
+ L4_LOCALSTORE_SUBDIR=l4d2 # localstore 下的子目录名
225
+
226
+ # A2S 性能
227
+ L4_A2S_CONCURRENCY=8 # 同时最多几台服务器在查(信号量上限)
228
+ L4_A2S_TIMEOUT=2.5 # 单次 ainfo / aplayers 超时秒
229
+ L4_A2S_CACHE_TTL=15 # 结果缓存秒;0=不缓存
230
+
231
+ # 订阅 / 巡检
232
+ L4_FAVORITE_CHECK_INTERVAL=300 # 巡检间隔秒(≥30)
233
+ L4_FAVORITE_PLAYER_DELTA=5 # 玩家数变化超过此值才推送
234
+
235
+ # 工坊
236
+ L4_WORKSHOP_CONCURRENCY=3 # 批量下载并发上限(1~8)
237
+ ```
238
+
239
+ ## 屏蔽与关键词 — 实现思路(v1.4.0 未实现,仅文档)
240
+
241
+ 下面四种思路由浅入深,可按需选一种或叠加:
242
+
243
+ 1. **SourceBans 自动同步**:定时拉 SourceBans banlist 落到本地
244
+ `<data_dir>/blocklist.json`;A2S 查服后过滤掉已在 banlist 的 IP,
245
+ 渲染层不再展示这些服。
246
+ 2. **本地 JSON 黑名单**:管理员 `l4黑名单 add <ip>` 写入
247
+ `<data_dir>/blocklist.json`;查询结果按黑名单过滤。
248
+ 3. **SourceMod HTTP 聊天镜像**:服务器装 SM 插件暴露 HTTP 接口,
249
+ 机器人拉聊天记录后正则匹配违规词,命中后通过 RCON 自动 kick。
250
+ 4. **关键词正则匹配**:新增配置 `l4_block_keywords: list[str]`;
251
+ 玩家名或服务器名命中则过滤。配合方案 1 自动入库效果最佳。
252
+
253
+ 四类方案都需要新增一个 `services/blocklist.py` + `commands/blocklist.py`
254
+ + `services/filters.py`(在 A2S 结果与渲染之间插入过滤器)。当前
255
+ v1.4.0 已预留 `consts.BLOCKLIST_FILENAME` 常量,避免后续硬编码。
161
256
 
162
257
  ## [数据结构](./docs/standand.md)
163
258
 
164
- > 服务器组文件存放位置:`<l4_path>/<组名>.json`(默认 `data/L4D2/<组名>.json`),旧版 `<l4_path>/l4d2/` 子目录会在启动时自动迁移。
165
- >
166
- > 所有数据路径(组文件、sb_pages、自定义背景图、迁移脚本)都跟着 `l4_path` 配置走,CWD 在哪都无所谓。改 `l4_path` 一处生效。
259
+ > 服务器组文件存放位置:`<data_dir>/<组名>.json`。
260
+ > `<data_dir>` 默认 `data/L4D2`;开启 localstore 后变为
261
+ > `<localstore>/nonebot_plugin_l4d2_server/l4d2/`。
262
+ > 旧版 `<data_dir>/l4d2/` 子目录与 `<data_dir>/l4d2.json` 单文件
263
+ > 都会在启动时自动迁移。
264
+
265
+ 收藏相关数据:
266
+
267
+ - `<data_dir>/favorites.json` — 收藏条目列表
268
+ - `<data_dir>/notify_state.json` — 上次推送状态(避免抖动刷屏)
167
269
 
168
270
  ## env 设置
169
271
 
@@ -174,13 +276,29 @@ conda install nonebot-plugin-l4d2-server
174
276
  """是否启用图片"""
175
277
  l4_connect = True
176
278
  """是否在查服命令后加入connect ip"""
279
+ l4_use_localstore = True
280
+ """是否走 nonebot-plugin-localstore 自动生成插件同名数据目录"""
281
+ l4_localstore_subdir = "l4d2"
282
+ """localstore 下的子目录名"""
177
283
  l4_path = "data/L4D2"
178
- """插件数据根目录。组 JSON / sb_pages / 自定义背景图 / 迁移脚本都从这里派生。"""
284
+ """l4_use_localstore=False 时使用的相对路径"""
179
285
  l4_players = 4
180
286
  """查询总图的时候展示的用户数量"""
181
287
  l4_style = "default"
182
288
  """图片风格,可选包括以下
183
289
  - 简洁
290
+ l4_a2s_concurrency = 8
291
+ """A2S 并发上限(信号量)"""
292
+ l4_a2s_timeout = 2.5
293
+ """A2S 单次超时秒"""
294
+ l4_a2s_cache_ttl = 15
295
+ """A2S 结果缓存秒;0=不缓存"""
296
+ l4_favorite_check_interval = 300
297
+ """收藏巡检间隔秒"""
298
+ l4_favorite_player_delta = 5
299
+ """玩家数变化超过此值才推送"""
300
+ l4_workshop_concurrency = 3
301
+ """创意工坊批量下载并发上限"""
184
302
  ```
185
303
 
186
304
  ## 和 0.x.x 更改部分
@@ -192,6 +310,30 @@ conda install nonebot-plugin-l4d2-server
192
310
  - **查服背景图按渲染类型拆分目录**(后续调整):`/云`(服务器列表)从 `<l4_path>/custom_backgrounds/` 根目录的所有图片中随机抽一张,目录为空时回退到内置 `background.jpg`;`/云1`(单服务器卡)固定使用深蓝灰纯色,不加载任何图片。详见「自定义服务器列表背景图片」;
193
311
  - **数据路径统一从 `l4_path` 派生**:组文件、sb_pages、自定义背景图、迁移脚本都跟着 `l4_path` 配置走,不再各自写死相对路径。`.env` 里改 `L4_PATH` 一处即生效,不用再管 bot 启动 CWD。
194
312
 
313
+ ## v1.4.0 相对 v1.3.x 的变化
314
+
315
+ - **localstore 路径**:默认用 `nonebot-plugin-localstore` 自动生成
316
+ 插件同名数据目录;可通过 `L4_USE_LOCALSTORE=false` 退回旧路径。
317
+ - **A2S 性能**:批量查询加 `asyncio.Semaphore` 上限
318
+ (`l4_a2s_concurrency`),单次超时可配(`l4_a2s_timeout`),
319
+ 结果缓存 `l4_a2s_cache_ttl` 秒(deepcopy 防止下游 mutate);
320
+ SourceBans `refresh_all_pages` 改并发。
321
+ - **收藏 / 订阅**:新增 `l4收藏` / `l4取关` / `l4收藏列表` /
322
+ `l4通知目标`;scheduler 周期巡检(`l4_favorite_check_interval`),
323
+ 上线 / 离线 / 玩家数突变时按群推送。
324
+ - **单服 CRUD**:新增 `l4添加服务器` / `l4删除服务器` / `l4修改服务器` /
325
+ `l4查看组`,ID 稳定不再重排。
326
+ - **创意工坊批量**:`l4创意工坊 123,456 789` 并发下载
327
+ (`l4_workshop_concurrency`),流式写入 + 进度回报。
328
+ - **`tj` / `zl` / `kl` 注册时序 bug**:改为在 `_on_startup` 内调用
329
+ `register_picker_handlers()`,避免导入时 `registry.commands` 还没填。
330
+ - **统一异常类型**:`services/errors.py` 提供 `L4Error` / `L4ServerUnreachableError` /
331
+ `L4TimeoutError` / `L4InvalidInputError` / `L4NotFoundError` / `L4HTTPError`,
332
+ 后续 handler 收敛 `except L4Error`。
333
+ - **`http_helpers.save_url_to_file` dead code** 修复;
334
+ 新增 `stream_download` 流式下载接口。
335
+ - **`http_helpers.STREAM_CHUNK_SIZE` / `STREAM_TIMEOUT`** 新常量。
336
+
195
337
  ## 其他
196
338
 
197
339
  - anne 部分,已移植到[这里](https://github.com/Agnes4m/L4D2UID),通过 core 插件调用
@@ -0,0 +1,128 @@
1
+ """
2
+ * Copyright (c) 2023, Agnes Digital
3
+ *
4
+ * This program is free software: you can redistribute it and or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ """
17
+
18
+ import asyncio
19
+
20
+ from nonebot import get_driver, require
21
+ from nonebot.log import logger
22
+ from nonebot.plugin import PluginMetadata, inherit_supported_adapters
23
+
24
+ # 依赖插件声明 必须在导入其它插件模块之前执行。
25
+ # htmlrender 0.6.x 的 ``__init__.py`` 会 ``require("nonebot_plugin_localstore")``,
26
+ # 所以 localstore 会通过 htmlrender 间接加载;如果想收藏巡检 / 定时任务立刻可用,
27
+ # 把 apscheduler 也显式 require 一下。
28
+ require("nonebot_plugin_alconna")
29
+ require("nonebot_plugin_htmlrender")
30
+ require("nonebot_plugin_apscheduler")
31
+
32
+ from . import commands # noqa: E402, F401 (registers all commands)
33
+ from .config import ConfigModel # noqa: E402
34
+ from .services import migrate, sourceban # noqa: E402
35
+ from .version import __version__ # noqa: E402
36
+
37
+ driver = get_driver()
38
+
39
+ # Initial scan to populate command aliases before any rule refresh.
40
+ from .registry import registry as _registry # noqa: E402
41
+
42
+ _registry.scan_commands()
43
+
44
+
45
+ @driver.on_startup
46
+ async def _on_startup() -> None:
47
+ from .commands.admin import register_picker_handlers
48
+ from .commands.query import refresh_server_command_rule
49
+ from .config import config
50
+ from .render.background import ensure_user_background_dir
51
+ from .services.favorite import init_favorite_scheduler
52
+ from .services.history import purge_older_than, record
53
+ from .services.path_resolver import migrate_legacy
54
+
55
+ config.data_dir # 触发 localstore 目录创建
56
+ migrate_legacy() # 首次启动把插件根 data/L4D2/ 复制过去
57
+ migrate.migrate_legacy_layout()
58
+ await sourceban.reload_registry()
59
+ sourceban.register_anne_alias()
60
+ refresh_server_command_rule()
61
+ register_picker_handlers()
62
+ ensure_user_background_dir()
63
+ await init_favorite_scheduler()
64
+ # 启动后台 A2S 历史记录任务 + 清过期记录
65
+ await _start_history_recorder()
66
+ await asyncio.to_thread(
67
+ purge_older_than, int(config.l4_history_retention_days),
68
+ )
69
+
70
+
71
+ async def _start_history_recorder() -> None:
72
+ """apscheduler 注册 interval 任务,周期 ``config.l4_history_interval`` 秒。
73
+
74
+ 任务对 ``registry.group_names`` 内每个组的每台服跑一次 ``record``。
75
+ 收藏巡检的 ``run_favorite_check`` 已经会写历史,本任务只覆盖**未被收藏**
76
+ 的服,避免「你只查不收藏的服没历史」。
77
+ """
78
+ from nonebot_plugin_apscheduler import scheduler
79
+
80
+ async def _record_all() -> None:
81
+ from .api import L4API
82
+ from .registry import registry
83
+
84
+ ips: list[tuple[str, int]] = []
85
+ for tag in registry.group_names:
86
+ for entry in registry.get(tag) or []:
87
+ ips.append((entry["host"], int(entry["port"])))
88
+ if not ips:
89
+ return
90
+ try:
91
+ results = await L4API.a2s_info_batch(ips, want_players=False)
92
+ except Exception as exc:
93
+ logger.warning(f"[l4] 历史记录批量失败: {exc}")
94
+ return
95
+ for (server, _), ip in zip(results, ips):
96
+ record(
97
+ host=ip[0],
98
+ port=ip[1],
99
+ server_name=str(getattr(server, "server_name", "") or ""),
100
+ map_name=str(getattr(server, "map_name", "") or ""),
101
+ player_count=int(getattr(server, "player_count", 0) or 0),
102
+ max_players=int(getattr(server, "max_players", 0) or 0),
103
+ ping=int(getattr(server, "ping", 0) or 0) or None,
104
+ )
105
+
106
+ try:
107
+ scheduler.add_job(
108
+ _record_all, "interval",
109
+ seconds=int(config.l4_history_interval),
110
+ id="l4_history_record", replace_existing=True,
111
+ )
112
+ except Exception as exc:
113
+ logger.warning(f"[l4] 注册历史记录任务失败: {exc}")
114
+
115
+
116
+ __plugin_meta__ = PluginMetadata(
117
+ name="求生之路小助手",
118
+ description="可用于管理求生之路查服和本地管理",
119
+ usage="群内对有关求生之路的查询和操作",
120
+ config=ConfigModel,
121
+ type="application",
122
+ homepage="https://github.com/Agnes4m/nonebot_plugin_l4d2_server",
123
+ supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
124
+ extra={
125
+ "version": __version__,
126
+ "author": "Agnes4m <Z735803792@163.com>",
127
+ },
128
+ )