nonebot-plugin-l4d2-server 0.6.6__py3-none-any.whl → 1.0.0a1__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.
Files changed (186) hide show
  1. nonebot_plugin_l4d2_server/__init__.py +9 -92
  2. nonebot_plugin_l4d2_server/__main__.py +90 -0
  3. nonebot_plugin_l4d2_server/config.py +30 -0
  4. nonebot_plugin_l4d2_server/data/L4D2/image/head/head.png +0 -0
  5. nonebot_plugin_l4d2_server/data/L4D2/image/header/logo.png +0 -0
  6. nonebot_plugin_l4d2_server/data/L4D2/image/header/player1.jpg +0 -0
  7. nonebot_plugin_l4d2_server/data/L4D2/image/template/anne.html +50 -42
  8. nonebot_plugin_l4d2_server/data/L4D2/image/template/back.png +0 -0
  9. nonebot_plugin_l4d2_server/data/L4D2/image/template/group_ip.html +1 -2
  10. nonebot_plugin_l4d2_server/data/L4D2/image/template/help.html +1 -2
  11. nonebot_plugin_l4d2_server/data/L4D2/image/template/help_dack.html +259 -221
  12. nonebot_plugin_l4d2_server/data/L4D2/image/template/ip.html +1 -2
  13. nonebot_plugin_l4d2_server/data/font/loli.ttf +0 -0
  14. nonebot_plugin_l4d2_server/data/icon//344/273/213/347/273/215.png +0 -0
  15. nonebot_plugin_l4d2_server/data/icon//344/273/273/345/212/241.png +0 -0
  16. nonebot_plugin_l4d2_server/data/icon//344/277/241/346/201/257.png +0 -0
  17. nonebot_plugin_l4d2_server/data/icon//345/205/254/345/221/212.png +0 -0
  18. nonebot_plugin_l4d2_server/data/icon//345/210/200/345/211/221.png +0 -0
  19. nonebot_plugin_l4d2_server/data/icon//345/210/207/346/215/242.png +0 -0
  20. nonebot_plugin_l4d2_server/data/icon//345/210/240/351/231/244.png +0 -0
  21. nonebot_plugin_l4d2_server/data/icon//345/210/267/346/226/260.png +0 -0
  22. nonebot_plugin_l4d2_server/data/icon//345/215/241/347/273/204.png +0 -0
  23. nonebot_plugin_l4d2_server/data/icon//345/223/252/351/207/214.png +0 -0
  24. nonebot_plugin_l4d2_server/data/icon//345/234/260/345/233/276.png +0 -0
  25. nonebot_plugin_l4d2_server/data/icon//345/257/274/345/205/245.png +0 -0
  26. nonebot_plugin_l4d2_server/data/icon//345/257/274/345/207/272.png +0 -0
  27. nonebot_plugin_l4d2_server/data/icon//345/275/261.png +0 -0
  28. nonebot_plugin_l4d2_server/data/icon//346/213/274/345/233/276.png +0 -0
  29. nonebot_plugin_l4d2_server/data/icon//346/216/242/347/264/242.png +0 -0
  30. nonebot_plugin_l4d2_server/data/icon//346/216/250/351/200/201.png +0 -0
  31. nonebot_plugin_l4d2_server/data/icon//346/224/266/351/233/206.png +0 -0
  32. nonebot_plugin_l4d2_server/data/icon//346/224/273/347/225/245.png +0 -0
  33. nonebot_plugin_l4d2_server/data/icon//346/233/264/346/226/260.png +0 -0
  34. nonebot_plugin_l4d2_server/data/icon//346/235/220/346/226/231.png +0 -0
  35. nonebot_plugin_l4d2_server/data/icon//346/237/245/350/257/242.png +0 -0
  36. nonebot_plugin_l4d2_server/data/icon//346/240/241/351/252/214.png +0 -0
  37. nonebot_plugin_l4d2_server/data/icon//346/257/217/346/234/210.png +0 -0
  38. nonebot_plugin_l4d2_server/data/icon//346/267/261/346/270/212.png +0 -0
  39. nonebot_plugin_l4d2_server/data/icon//346/267/273/345/212/240.png +0 -0
  40. nonebot_plugin_l4d2_server/data/icon//346/270/205/351/231/244.png +0 -0
  41. nonebot_plugin_l4d2_server/data/icon//347/212/266/346/200/201.png +0 -0
  42. nonebot_plugin_l4d2_server/data/icon//347/255/276/345/210/260.png +0 -0
  43. nonebot_plugin_l4d2_server/data/icon//347/273/221/345/256/232.png +0 -0
  44. nonebot_plugin_l4d2_server/data/icon//350/241/250.png +0 -0
  45. nonebot_plugin_l4d2_server/data/icon//350/241/250/346/203/205.png +0 -0
  46. nonebot_plugin_l4d2_server/data/icon//350/247/222/350/211/262.png +0 -0
  47. nonebot_plugin_l4d2_server/data/icon//350/256/260/345/275/225.png +0 -0
  48. nonebot_plugin_l4d2_server/data/icon//351/205/215/347/275/256.png +0 -0
  49. nonebot_plugin_l4d2_server/data/icon//351/207/215/345/220/257.png +0 -0
  50. nonebot_plugin_l4d2_server/data/img/l4d2.png +0 -0
  51. nonebot_plugin_l4d2_server/data/img/linux.png +0 -0
  52. nonebot_plugin_l4d2_server/data/img/vac.png +0 -0
  53. nonebot_plugin_l4d2_server/data/img/white.png +0 -0
  54. nonebot_plugin_l4d2_server/l4_help/Help.json +65 -0
  55. nonebot_plugin_l4d2_server/l4_help/__init__.py +57 -0
  56. nonebot_plugin_l4d2_server/l4_help/draw.py +206 -0
  57. nonebot_plugin_l4d2_server/l4_help/icon//344/273/213/347/273/215.png +0 -0
  58. nonebot_plugin_l4d2_server/l4_help/icon//344/273/273/345/212/241.png +0 -0
  59. nonebot_plugin_l4d2_server/l4_help/icon//344/277/241/346/201/257.png +0 -0
  60. nonebot_plugin_l4d2_server/l4_help/icon//345/205/254/345/221/212.png +0 -0
  61. nonebot_plugin_l4d2_server/l4_help/icon//345/210/200/345/211/221.png +0 -0
  62. nonebot_plugin_l4d2_server/l4_help/icon//345/210/207/346/215/242.png +0 -0
  63. nonebot_plugin_l4d2_server/l4_help/icon//345/210/240/351/231/244.png +0 -0
  64. nonebot_plugin_l4d2_server/l4_help/icon//345/210/267/346/226/260.png +0 -0
  65. nonebot_plugin_l4d2_server/l4_help/icon//345/215/241/347/273/204.png +0 -0
  66. nonebot_plugin_l4d2_server/l4_help/icon//345/223/252/351/207/214.png +0 -0
  67. nonebot_plugin_l4d2_server/l4_help/icon//345/234/260/345/233/276.png +0 -0
  68. nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/205/245.png +0 -0
  69. nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/207/272.png +0 -0
  70. nonebot_plugin_l4d2_server/l4_help/icon//345/275/261.png +0 -0
  71. nonebot_plugin_l4d2_server/l4_help/icon//346/213/274/345/233/276.png +0 -0
  72. nonebot_plugin_l4d2_server/l4_help/icon//346/216/242/347/264/242.png +0 -0
  73. nonebot_plugin_l4d2_server/l4_help/icon//346/216/250/351/200/201.png +0 -0
  74. nonebot_plugin_l4d2_server/l4_help/icon//346/224/266/351/233/206.png +0 -0
  75. nonebot_plugin_l4d2_server/l4_help/icon//346/224/273/347/225/245.png +0 -0
  76. nonebot_plugin_l4d2_server/l4_help/icon//346/233/264/346/226/260.png +0 -0
  77. nonebot_plugin_l4d2_server/l4_help/icon//346/235/220/346/226/231.png +0 -0
  78. nonebot_plugin_l4d2_server/l4_help/icon//346/237/245/350/257/242.png +0 -0
  79. nonebot_plugin_l4d2_server/l4_help/icon//346/240/241/351/252/214.png +0 -0
  80. nonebot_plugin_l4d2_server/l4_help/icon//346/257/217/346/234/210.png +0 -0
  81. nonebot_plugin_l4d2_server/l4_help/icon//346/267/261/346/270/212.png +0 -0
  82. nonebot_plugin_l4d2_server/l4_help/icon//346/267/273/345/212/240.png +0 -0
  83. nonebot_plugin_l4d2_server/l4_help/icon//346/270/205/351/231/244.png +0 -0
  84. nonebot_plugin_l4d2_server/l4_help/icon//347/212/266/346/200/201.png +0 -0
  85. nonebot_plugin_l4d2_server/l4_help/icon//347/255/276/345/210/260.png +0 -0
  86. nonebot_plugin_l4d2_server/l4_help/icon//347/273/221/345/256/232.png +0 -0
  87. nonebot_plugin_l4d2_server/l4_help/icon//350/241/250.png +0 -0
  88. nonebot_plugin_l4d2_server/l4_help/icon//350/241/250/346/203/205.png +0 -0
  89. nonebot_plugin_l4d2_server/l4_help/icon//350/247/222/350/211/262.png +0 -0
  90. nonebot_plugin_l4d2_server/l4_help/icon//350/256/260/345/275/225.png +0 -0
  91. nonebot_plugin_l4d2_server/l4_help/icon//351/205/215/347/275/256.png +0 -0
  92. nonebot_plugin_l4d2_server/l4_help/icon//351/207/215/345/220/257.png +0 -0
  93. nonebot_plugin_l4d2_server/l4_help/texture2d/badge.png +0 -0
  94. nonebot_plugin_l4d2_server/l4_help/texture2d/banner.png +0 -0
  95. nonebot_plugin_l4d2_server/l4_help/texture2d/bg.jpg +0 -0
  96. nonebot_plugin_l4d2_server/l4_help/texture2d/button.png +0 -0
  97. nonebot_plugin_l4d2_server/l4_help/texture2d/icon.png +0 -0
  98. nonebot_plugin_l4d2_server/l4_image/__init__.py +16 -0
  99. nonebot_plugin_l4d2_server/l4_image/convert.py +175 -0
  100. nonebot_plugin_l4d2_server/{l4d2_image → l4_image}/download.py +6 -30
  101. nonebot_plugin_l4d2_server/{l4d2_image/__init__.py → l4_image/html_img.py} +54 -45
  102. nonebot_plugin_l4d2_server/l4_image/image_tools.py +468 -0
  103. nonebot_plugin_l4d2_server/l4_image/img/anne/anne.html +60 -0
  104. nonebot_plugin_l4d2_server/l4_image/img/anne/back.png +0 -0
  105. nonebot_plugin_l4d2_server/l4_image/img/anne/group_ip.html +259 -0
  106. nonebot_plugin_l4d2_server/l4_image/img/anne/ip.html +55 -0
  107. nonebot_plugin_l4d2_server/l4_image/img/head/head.png +0 -0
  108. nonebot_plugin_l4d2_server/l4_image/img/header/logo.png +0 -0
  109. nonebot_plugin_l4d2_server/l4_image/img/header/player1.jpg +0 -0
  110. nonebot_plugin_l4d2_server/l4_image/img/template/Bocchi_The_Rock.html +312 -0
  111. nonebot_plugin_l4d2_server/l4_image/img/template/Bocchi_The_Rock.png +0 -0
  112. nonebot_plugin_l4d2_server/l4_image/img/template/HYPixel11pxU-2.ttf +0 -0
  113. nonebot_plugin_l4d2_server/l4_image/img/template/Pixel.html +350 -0
  114. nonebot_plugin_l4d2_server/l4_image/img/template/Pixel.png +0 -0
  115. nonebot_plugin_l4d2_server/l4_image/img/template/Rainbow.html +321 -0
  116. nonebot_plugin_l4d2_server/l4_image/img/template/Rainbow.png +0 -0
  117. nonebot_plugin_l4d2_server/l4_image/img/template/Tutumianhuatang-Bold-2.ttf +0 -0
  118. nonebot_plugin_l4d2_server/l4_image/img/template/bilibili.svg +1 -0
  119. nonebot_plugin_l4d2_server/l4_image/img/template/fingerprint.svg +15 -0
  120. nonebot_plugin_l4d2_server/l4_image/img/template/github.svg +1 -0
  121. nonebot_plugin_l4d2_server/l4_image/img/template/l.svg +9 -0
  122. nonebot_plugin_l4d2_server/l4_image/img/template/m.svg +1 -0
  123. nonebot_plugin_l4d2_server/l4_image/img/template/normal.html +257 -0
  124. nonebot_plugin_l4d2_server/l4_image/img/template/vue.css +531 -0
  125. nonebot_plugin_l4d2_server/l4_image/img/template/w.svg +1 -0
  126. nonebot_plugin_l4d2_server/l4_image/img/template//345/276/256/350/275/257/351/233/205/351/273/221.ttf +0 -0
  127. nonebot_plugin_l4d2_server/l4_image/model.py +15 -0
  128. nonebot_plugin_l4d2_server/{l4d2_image → l4_image}/vtfs.py +2 -0
  129. nonebot_plugin_l4d2_server/l4_request/__init__.py +84 -0
  130. nonebot_plugin_l4d2_server/l4_request/draw_msg.py +88 -0
  131. nonebot_plugin_l4d2_server/utils/api/api.py +4 -0
  132. nonebot_plugin_l4d2_server/utils/api/models.py +29 -0
  133. nonebot_plugin_l4d2_server/utils/api/request.py +119 -0
  134. nonebot_plugin_l4d2_server/utils/database/models.py +29 -0
  135. nonebot_plugin_l4d2_server/{l4d2_utils → utils}/utils.py +52 -55
  136. {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a1.dist-info}/METADATA +47 -64
  137. nonebot_plugin_l4d2_server-1.0.0a1.dist-info/RECORD +144 -0
  138. {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a1.dist-info}/WHEEL +1 -1
  139. nonebot_plugin_l4d2_server/l4d2_anne/__init__.py +0 -95
  140. nonebot_plugin_l4d2_server/l4d2_anne/analysis.py +0 -54
  141. nonebot_plugin_l4d2_server/l4d2_anne/anne_telecom.py +0 -79
  142. nonebot_plugin_l4d2_server/l4d2_anne/server.py +0 -47
  143. nonebot_plugin_l4d2_server/l4d2_anne/startand.py +0 -17
  144. nonebot_plugin_l4d2_server/l4d2_anne/utils.py +0 -294
  145. nonebot_plugin_l4d2_server/l4d2_data/__init__.py +0 -105
  146. nonebot_plugin_l4d2_server/l4d2_data/config.py +0 -18
  147. nonebot_plugin_l4d2_server/l4d2_data/database.py +0 -0
  148. nonebot_plugin_l4d2_server/l4d2_data/players.py +0 -100
  149. nonebot_plugin_l4d2_server/l4d2_data/serverip.py +0 -40
  150. nonebot_plugin_l4d2_server/l4d2_file/__init__.py +0 -222
  151. nonebot_plugin_l4d2_server/l4d2_file/ayromote.py +0 -64
  152. nonebot_plugin_l4d2_server/l4d2_file/input_json.py +0 -77
  153. nonebot_plugin_l4d2_server/l4d2_file/remote.py +0 -86
  154. nonebot_plugin_l4d2_server/l4d2_file/utils.py +0 -104
  155. nonebot_plugin_l4d2_server/l4d2_image/htmlimg.py +0 -18
  156. nonebot_plugin_l4d2_server/l4d2_image/images.py +0 -92
  157. nonebot_plugin_l4d2_server/l4d2_image/one.py +0 -44
  158. nonebot_plugin_l4d2_server/l4d2_image/send_image_tool.py +0 -32
  159. nonebot_plugin_l4d2_server/l4d2_image/steam.py +0 -63
  160. nonebot_plugin_l4d2_server/l4d2_push/__init__.py +0 -225
  161. nonebot_plugin_l4d2_server/l4d2_queries/__init__.py +0 -326
  162. nonebot_plugin_l4d2_server/l4d2_queries/himi.py +0 -113
  163. nonebot_plugin_l4d2_server/l4d2_queries/local_ip.py +0 -41
  164. nonebot_plugin_l4d2_server/l4d2_queries/qqgroup.py +0 -370
  165. nonebot_plugin_l4d2_server/l4d2_queries/send_msg.py +0 -131
  166. nonebot_plugin_l4d2_server/l4d2_queries/utils.py +0 -212
  167. nonebot_plugin_l4d2_server/l4d2_server/__init__.py +0 -118
  168. nonebot_plugin_l4d2_server/l4d2_server/index.py +0 -0
  169. nonebot_plugin_l4d2_server/l4d2_server/rcon.py +0 -53
  170. nonebot_plugin_l4d2_server/l4d2_server/workshop.py +0 -82
  171. nonebot_plugin_l4d2_server/l4d2_update/__init__.py +0 -137
  172. nonebot_plugin_l4d2_server/l4d2_update/draw_update_log.py +0 -45
  173. nonebot_plugin_l4d2_server/l4d2_update/restart.py +0 -69
  174. nonebot_plugin_l4d2_server/l4d2_update/update.py +0 -53
  175. nonebot_plugin_l4d2_server/l4d2_utils/classcal.py +0 -53
  176. nonebot_plugin_l4d2_server/l4d2_utils/command.py +0 -23
  177. nonebot_plugin_l4d2_server/l4d2_utils/config.py +0 -201
  178. nonebot_plugin_l4d2_server/l4d2_utils/message.py +0 -59
  179. nonebot_plugin_l4d2_server/l4d2_utils/rule.py +0 -35
  180. nonebot_plugin_l4d2_server/l4d2_utils/seach.py +0 -43
  181. nonebot_plugin_l4d2_server/l4d2_utils/txt_to_img.py +0 -32
  182. nonebot_plugin_l4d2_server/l4d2_web/web.py +0 -277
  183. nonebot_plugin_l4d2_server/l4d2_web/webUI.py +0 -506
  184. nonebot_plugin_l4d2_server/l4d2_web/webUI_s.py +0 -94
  185. nonebot_plugin_l4d2_server-0.6.6.dist-info/RECORD +0 -70
  186. {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a1.dist-info}/licenses/LICENSE +0 -0
@@ -1,104 +0,0 @@
1
- import io
2
- import zipfile
3
- from pathlib import Path
4
- from typing import Callable, Dict, List
5
- from zipfile import ZipFile
6
-
7
- import rarfile
8
- from nonebot.log import logger
9
- from pyunpack import Archive
10
-
11
- from ..l4d2_utils.config import systems
12
- from ..l4d2_utils.utils import get_file, get_vpk
13
-
14
-
15
- async def updown_l4d2_vpk(map_paths: Path, name: str, url: str):
16
- """从url下载压缩包并解压到位置"""
17
- original_vpk_files = get_vpk(map_paths)
18
- down_file = Path(map_paths, name)
19
- if await get_file(url, down_file) is None:
20
- return None
21
- msg = open_packet(name, down_file)
22
- logger.info(msg)
23
-
24
- extracted_vpk_files = get_vpk(map_paths)
25
- # 获取新增vpk文件的list
26
- return list(set(extracted_vpk_files) - set(original_vpk_files))
27
-
28
-
29
- SUPPORTED_EXTENSIONS = (".zip", ".7z", ".rar")
30
-
31
-
32
- def unzip_zipfile(down_file: Path, down_path: Path):
33
- """解压zip文件"""
34
- with support_gbk(zipfile.ZipFile(down_file, "r")) as z:
35
- z.extractall(down_path)
36
- down_file.unlink()
37
-
38
-
39
- def unpack_7zfile(down_file: Path, down_path: Path):
40
- """解压7z文件"""
41
- Archive(str(down_file)).extractall(str(down_path))
42
- down_file.unlink()
43
-
44
-
45
- def unpack_rarfile(down_file: Path, down_path: Path):
46
- """解压rar文件"""
47
- with rarfile.RarFile(down_file, "r") as z:
48
- z.extractall(down_path)
49
- down_file.unlink()
50
-
51
-
52
- def open_packet(name: str, down_file: Path) -> str:
53
- """解压压缩包"""
54
- down_path = down_file.parent
55
- logger.info("文件名为:" + name)
56
- logger.info(f"系统为{systems}")
57
-
58
- if name.endswith(".vpk"):
59
- return "vpk文件已下载"
60
-
61
- for ext in SUPPORTED_EXTENSIONS:
62
- if name.endswith(ext):
63
- mes = f"{ext[1:]}文件已下载,正在解压"
64
- unpack_funcs: Dict[str, Callable] = {
65
- ".zip": unzip_zipfile,
66
- ".7z": unpack_7zfile,
67
- ".rar": unpack_rarfile,
68
- }
69
- unpack_func = unpack_funcs.get(ext)
70
- if not unpack_func:
71
- raise ValueError(f"不支持的拓展名: {ext}")
72
- unpack_func(down_file, down_path)
73
- return mes
74
-
75
- raise ValueError(f"不支持的文件: {name}")
76
-
77
-
78
- def support_gbk(zip_file: ZipFile):
79
- """
80
- 压缩包中文恢复
81
- """
82
- if type(zip_file) == ZipFile:
83
- name_to_info = zip_file.NameToInfo
84
- # copy map first
85
- for name, info in name_to_info.copy().items():
86
- real_name = name.encode("cp437").decode("gbk")
87
- if real_name != name:
88
- info.filename = real_name
89
- del name_to_info[name]
90
- name_to_info[real_name] = info
91
- return zip_file
92
-
93
-
94
- async def all_zip_to_one(data_list: List[bytes]):
95
- """多压缩包文件合并"""
96
- file_list = [io.BytesIO(data).getbuffer() for data in data_list]
97
- data_file = io.BytesIO()
98
-
99
- with ZipFile(data_file, mode="w") as zf:
100
- for i, file in enumerate(file_list):
101
- filename = f"file{i}.zip"
102
- zf.writestr(filename, file)
103
-
104
- return data_file.getbuffer()
@@ -1,18 +0,0 @@
1
- class DATAPANDS:
2
- def __init__(self, data_dict: dict) -> None:
3
- self.new_data = {}
4
- self.data_dict = data_dict
5
- for key in data_dict:
6
- self.dict_pan(key)
7
-
8
- def dict_pan(self, key):
9
- """dict转化为图像所需要的dict量化"""
10
- # 删除不必要的数据
11
- if key == "刷特模式":
12
- self.data_dict.pop(key)
13
- elif key == "游戏模式" or key == "特感数量" or key == "刷新间隔":
14
- for item in self.data_dict[key]:
15
- if item in self.new_data:
16
- self.new_data[item] += 1
17
- else:
18
- self.new_data[item] = 1
@@ -1,92 +0,0 @@
1
- import sys
2
- from base64 import b64encode
3
- from io import BytesIO
4
- from pathlib import Path
5
- from typing import Union, overload
6
-
7
- import aiofiles
8
- from PIL import Image
9
-
10
- MAIN_PATH = Path() / "data" / "GenshinUID"
11
- sys.path.append(str(MAIN_PATH))
12
- CONFIG_PATH = MAIN_PATH / "config.json"
13
- RESOURCE_PATH = MAIN_PATH / "resource"
14
- WIKI_PATH = MAIN_PATH / "wiki"
15
- CU_BG_PATH = MAIN_PATH / "bg"
16
- CU_CHBG_PATH = MAIN_PATH / "chbg"
17
- WEAPON_PATH = RESOURCE_PATH / "weapon"
18
- GACHA_IMG_PATH = RESOURCE_PATH / "gacha_img"
19
- CHAR_PATH = RESOURCE_PATH / "chars"
20
- CHAR_STAND_PATH = RESOURCE_PATH / "char_stand"
21
- CHAR_SIDE_PATH = RESOURCE_PATH / "char_side"
22
- CHAR_NAMECARD_PATH = RESOURCE_PATH / "char_namecard"
23
- REL_PATH = RESOURCE_PATH / "reliquaries"
24
- ICON_PATH = RESOURCE_PATH / "icon"
25
- TEMP_PATH = RESOURCE_PATH / "temp"
26
- CARD_PATH = RESOURCE_PATH / "card"
27
- GUIDE_PATH = WIKI_PATH / "guide"
28
- TEXT2D_PATH = Path(__file__).parents[2] / "resource" / "texture2d"
29
-
30
- PLAYER_PATH = MAIN_PATH / "players"
31
-
32
-
33
- TEXT2D_PATH = Path(__file__).parents[2] / "resource" / "texture2d"
34
- FETTER_PATH = TEXT2D_PATH / "fetter"
35
- TALENT_PATH = TEXT2D_PATH / "talent"
36
- WEAPON_BG_PATH = TEXT2D_PATH / "weapon"
37
- WEAPON_AFFIX_PATH = TEXT2D_PATH / "weapon_affix"
38
- LEVEL_PATH = TEXT2D_PATH / "level"
39
-
40
- BG_PATH = Path(__file__).parent / "bg"
41
- TEXT_PATH = Path(__file__).parent / "texture2d"
42
- ring_pic = Image.open(TEXT_PATH / "ring.png")
43
- mask_pic = Image.open(TEXT_PATH / "mask.png")
44
- NM_BG_PATH = BG_PATH / "nm_bg"
45
- SP_BG_PATH = BG_PATH / "sp_bg"
46
-
47
- bg_path = CU_BG_PATH if list(CU_BG_PATH.iterdir()) != [] else NM_BG_PATH
48
-
49
-
50
- @overload
51
- async def convert_img(img: Image.Image, is_base64: bool = False) -> bytes: ...
52
-
53
-
54
- @overload
55
- async def convert_img(img: Image.Image, is_base64: bool = True) -> str: ...
56
-
57
-
58
- @overload
59
- async def convert_img(img: bytes, is_base64: bool = False) -> str: ...
60
-
61
-
62
- @overload
63
- async def convert_img(img: Path, is_base64: bool = False) -> str: ...
64
-
65
-
66
- async def convert_img(
67
- img: Union[Image.Image, str, Path, bytes],
68
- is_base64: bool = False,
69
- ):
70
- """
71
- :说明:
72
- 将PIL.Image对象转换为bytes或者base64格式。
73
- :参数:
74
- * img (Image): 图片。
75
- * is_base64 (bool): 是否转换为base64格式, 不填默认转为bytes。
76
- :返回:
77
- * res: bytes对象或base64编码图片。
78
- """
79
- if isinstance(img, Image.Image):
80
- img = img.convert("RGB")
81
- result_buffer = BytesIO()
82
- img.save(result_buffer, format="PNG", quality=80, subsampling=0)
83
- res = result_buffer.getvalue()
84
- if is_base64:
85
- res = "base64://" + b64encode(res).decode()
86
- return res
87
- if isinstance(img, bytes):
88
- pass
89
- else:
90
- async with aiofiles.open(img, "rb") as fp:
91
- img = await fp.read()
92
- return f"[CQ:image,file=base64://{b64encode(img).decode()}]"
@@ -1,44 +0,0 @@
1
- from pathlib import Path
2
- from typing import List
3
-
4
- from PIL import Image
5
-
6
- # 半透明素材
7
- half_whitel_image_path = Path(__file__).parent.parent.joinpath("data/img/white.png")
8
- half_whitel_image = Image.open(half_whitel_image_path)
9
-
10
-
11
- async def one_server_img(msg: dict):
12
- """单个服务器的dict信息变成图片"""
13
- img_background = await adjust_image_size(msg["Players"])
14
- img_background = await adjust_server_name(img_background, msg["name"])
15
-
16
-
17
- async def adjust_image_size(text_list):
18
- """初始化背景"""
19
- initial_width = 1080
20
- initial_height = 600
21
- height_increment = 100
22
-
23
- num_players = len(text_list.get("Player", []))
24
- final_height = initial_height + num_players * height_increment
25
-
26
- return Image.new("RGBA", (initial_width, final_height), "white")
27
-
28
-
29
- async def adjust_server_name(image: Image.Image, name: str):
30
- """写标题"""
31
- if image and name:
32
- ...
33
-
34
-
35
- async def adjust_ping(image: Image.Image, ping: str):
36
- """写ping"""
37
- if image and ping:
38
- ...
39
-
40
-
41
- async def adjust_player(image: Image.Image, player: List[dict]):
42
- """写玩家"""
43
- if image and player:
44
- ...
@@ -1,32 +0,0 @@
1
- from base64 import b64encode
2
- from io import BytesIO
3
- from pathlib import Path
4
- from typing import Union
5
-
6
- from PIL import Image
7
-
8
-
9
- async def convert_img(
10
- img: Union[Image.Image, str, Path, bytes],
11
- is_base64: bool = False,
12
- ):
13
- """
14
- :说明:
15
- 将PIL.Image对象转换为bytes或者base64格式。
16
- :参数:
17
- * img (Image): 图片。
18
- * is_base64 (bool): 是否转换为base64格式, 不填默认转为bytes。
19
- :返回:
20
- * res: bytes对象或base64编码图片。
21
- """
22
- if isinstance(img, Image.Image):
23
- img = img.convert("RGBA")
24
- result_buffer = BytesIO()
25
- img.save(result_buffer, format="PNG", quality=80, subsampling=0)
26
- res = result_buffer.getvalue()
27
- if is_base64:
28
- res = b64encode(res).decode()
29
- return res
30
- if isinstance(img, bytes):
31
- return b64encode(img).decode()
32
- return f"[CQ:image,file=file:///{img!s}]"
@@ -1,63 +0,0 @@
1
- # from PIL import Image
2
- # from bs4 import BeautifulSoup
3
- from urllib.parse import unquote
4
-
5
- import aiohttp
6
- import httpx
7
-
8
- headers = {
9
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0", # noqa: E501
10
- }
11
-
12
-
13
- async def url_to_byte(url: str):
14
- """获取URL数据的字节流"""
15
-
16
- async with aiohttp.ClientSession() as session:
17
- async with session.get(url, headers=headers, timeout=600) as response:
18
- if response.status == 200:
19
- return await response.read()
20
- return None
21
-
22
-
23
- async def url_to_msg(url: str):
24
- """获取URL数据的字节流"""
25
-
26
- async with aiohttp.ClientSession() as session:
27
- async with session.get(url, headers=headers, timeout=600) as response:
28
- if response.status == 200:
29
- return await response.text()
30
- return None
31
-
32
-
33
- async def url_to_byte_name(url: str, filename: str = ""):
34
- """获取URL数据的字节流"""
35
-
36
- if filename == "htp":
37
- response = httpx.get(url, headers=headers, timeout=600) # noqa: ASYNC100
38
- content_disposition = response.headers.get("Content-Disposition")
39
- if not content_disposition:
40
- return None
41
- if "''" in content_disposition:
42
- file_name = content_disposition.split("''")[-1]
43
- else:
44
- file_name = content_disposition
45
- file_name = unquote(file_name)
46
- if response.content and file_name:
47
- return [response.content, file_name]
48
- return None
49
- async with aiohttp.ClientSession() as session:
50
- async with session.get(url, headers=headers, timeout=600) as response:
51
- content_disposition = response.headers.get("Content-Disposition")
52
- if not content_disposition:
53
- return None
54
- if "''" in content_disposition:
55
- file_name = content_disposition.split("''")[-1]
56
- else:
57
- file_name = content_disposition
58
- if not file_name:
59
- file_name = "anyone"
60
- file_name = unquote(file_name)
61
- if response.status == 200:
62
- return [await response.read(), file_name]
63
- return None
@@ -1,225 +0,0 @@
1
- from pathlib import Path
2
- from typing import Dict, Optional, Union
3
-
4
- import a2s
5
-
6
- try:
7
- import ujson as json
8
- except ImportError:
9
- import json
10
-
11
- from nonebot import get_bot, get_driver, on_command, require
12
- from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message, MessageSegment
13
- from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
14
- from nonebot.log import logger
15
- from nonebot.matcher import Matcher
16
- from nonebot.params import CommandArg
17
- from nonebot.permission import SUPERUSER
18
- from nonebot_plugin_saa import MessageFactory
19
-
20
- from ..l4d2_queries import get_ip_to_mes
21
- from ..l4d2_queries.utils import json_server_to_tag_dict
22
- from ..l4d2_utils.config import l4_config
23
- from ..l4d2_utils.utils import extract_last_digit, split_maohao
24
-
25
- require("nonebot_plugin_apscheduler")
26
- try:
27
- scheduler = require("nonebot_plugin_apscheduler").scheduler
28
- except Exception:
29
- scheduler = None
30
- driver = get_driver()
31
- sch_json = Path("data/L4D2/scheduler.json")
32
- if not sch_json.exists():
33
- with sch_json.open("w") as f:
34
- json.dump({}, f, ensure_ascii=False)
35
-
36
- add_rss = on_command(
37
- "add_rss",
38
- aliases={"求生定时添加"},
39
- priority=30,
40
- permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
41
- )
42
- del_rss = on_command(
43
- "del_rss",
44
- aliases={"求生定时删除"},
45
- priority=30,
46
- permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
47
- )
48
-
49
-
50
- @add_rss.handle()
51
- async def _(event: GroupMessageEvent, matcher: Matcher, args: Message = CommandArg()):
52
- group_id = event.group_id
53
- if not group_id:
54
- return
55
- msg = args.extract_plain_text()
56
- command, message = await extract_last_digit(msg)
57
- push_msg = await get_ip_to_mes(msg=message, command=command)
58
- if not push_msg:
59
- return
60
- if push_msg in ["服务器无响应", None]:
61
- await matcher.finish("无响应的服务器,请检查")
62
- else:
63
- return_msg = await add_or_update_data(group_id, msg)
64
- await MessageFactory(push_msg).send()
65
- # if isinstance(push_msg, bytes):
66
- # await matcher.finish(MessageSegment.image(push_msg))
67
- # elif isinstance(push_msg, Union[Message, MessageSegment]):
68
- # await matcher.finish(push_msg)
69
- # else:
70
- # await matcher.send(push_msg)
71
- if return_msg == "add":
72
- await matcher.send(f"已添加群定时任务【{msg}】{l4_config.l4_push_times}次")
73
- elif return_msg in ["update", "change"]:
74
- await matcher.send(f"已更新群定时任务【{msg}】{l4_config.l4_push_times}次")
75
-
76
-
77
- @del_rss.handle()
78
- async def _(event: GroupMessageEvent, matcher: Matcher):
79
- group_id = event.group_id
80
- if not group_id:
81
- return
82
- await add_or_update_data(group_id, "", ad_mode="del")
83
- await matcher.finish("已删除群定时任务")
84
-
85
-
86
- async def add_or_update_data(group_i: int, some_str: str = "", ad_mode: str = "add"):
87
- """添加或者删除定时任务
88
- mode == [new,update,del,change]
89
- """
90
- group_id = str(group_i)
91
- sch_json = Path("data/L4D2/scheduler.json")
92
- if ad_mode == "add":
93
- if sch_json.exists():
94
- with sch_json.open(encoding="utf-8") as f:
95
- scheduler_data = json.load(f)
96
- try:
97
- msg_dict = scheduler_data[group_id]
98
- # times = msg_dict["times"]
99
- old_msg = msg_dict["msg"]
100
- scheduler_data[group_id] = {
101
- "times": l4_config.l4_push_times,
102
- "msg": some_str,
103
- }
104
- mode = "update" if old_msg == some_str else "change"
105
- except Exception:
106
- scheduler_data[group_id] = {
107
- "times": l4_config.l4_push_times,
108
- "msg": some_str,
109
- }
110
- mode = "new"
111
-
112
- else:
113
- scheduler_data = {
114
- group_id: {"times": l4_config.l4_push_times, "msg": some_str},
115
- }
116
- mode = "new"
117
-
118
- with sch_json.open("w", encoding="utf-8") as f:
119
- json.dump(scheduler_data, f, ensure_ascii=False)
120
-
121
- else:
122
- if sch_json.exists():
123
- with sch_json.open() as f:
124
- scheduler_data: Dict[str, Dict[str, Union[str, int]]] = json.load(f)
125
- try:
126
- msg_dict = scheduler_data[group_id]
127
- # times = msg_dict["times"]
128
- old_msg = msg_dict["msg"]
129
- scheduler_data[group_id] = {"times": 0, "msg": old_msg}
130
- except Exception:
131
- scheduler_data[group_id] = {"times": 0, "msg": some_str}
132
- else:
133
- scheduler_data = {group_id: {"times": 0, "msg": some_str}}
134
- mode = "del"
135
-
136
- with sch_json.open("w", encoding="utf-8") as f:
137
- json.dump(scheduler_data, f, ensure_ascii=False)
138
-
139
- return mode
140
-
141
-
142
- async def rss_ip():
143
- """推送一次"""
144
- sch_json = Path("data/L4D2/scheduler.json")
145
-
146
- if sch_json.exists():
147
- with sch_json.open(encoding="utf-8") as f:
148
- scheduler_data: Dict[str, Dict[str, Union[int, str]]] = json.load(f)
149
-
150
- for key, value in scheduler_data.items():
151
- try:
152
- recipient_id = int(key)
153
- count = value["times"]
154
- msg = str(value["msg"])
155
- count = int(count)
156
-
157
- if count > 0:
158
- msg_read = await send_message(recipient_id, msg, value)
159
- if msg_read and isinstance(msg_read, str):
160
- scheduler_data[key]["ip_detail"] = msg_read
161
- count -= 1
162
-
163
- scheduler_data[key]["times"] = count
164
- except TypeError:
165
- continue
166
-
167
- with sch_json.open(mode="w", encoding="utf-8") as f:
168
- json.dump(scheduler_data, f, ensure_ascii=False)
169
-
170
-
171
- async def send_message(
172
- recipient_id: int,
173
- msg: str,
174
- value: Optional[Dict[str, Union[int, str]]] = None,
175
- ):
176
- # 执行发送消息的操作,参数可以根据需要进行传递和使用
177
- command, message = await extract_last_digit(msg)
178
- push_msg = await get_ip_to_mes(msg=message, command=command)
179
- if isinstance(push_msg, bytes):
180
- await get_bot().send_group_msg(
181
- group_id=recipient_id,
182
- message=MessageSegment.image(push_msg),
183
- )
184
- return None
185
- if msg and isinstance(push_msg, str):
186
- # 单服务器
187
- message = await json_server_to_tag_dict(msg, command)
188
- if len(message) == 0 or not value:
189
- # 关键词不匹配,忽略
190
- return None
191
- try:
192
- old_msg = value.get("ip_detail", {})
193
- if not isinstance(old_msg, dict):
194
- return None
195
- ip = str(message["ip"])
196
- host, port = split_maohao(ip)
197
- msg_: a2s.SourceInfo = await a2s.ainfo((host, port))
198
- value["map_"] = msg_.map_name
199
- value["rank_players"] = f"{msg_.player_count}/{msg_.max_players}"
200
- if (
201
- old_msg["map_"] == value["map_"]
202
- and old_msg["rank_players"] == value["rank_players"]
203
- ):
204
- logger.info(f"{msg}{command}人数和地图未发生变化")
205
- else:
206
- await get_bot().send_group_msg(group_id=recipient_id, message=push_msg)
207
- except Exception as e:
208
- logger.warning(e)
209
-
210
- return value
211
- return None
212
-
213
-
214
- async def server_is_change():
215
- """检测服务器是否发生变化"""
216
-
217
-
218
- if scheduler:
219
- logger.success("已成功启动求生定时推送")
220
- scheduler.add_job(
221
- rss_ip,
222
- "interval",
223
- minutes=l4_config.l4_push_interval,
224
- id="rss_ip",
225
- )