nonebot-plugin-l4d2-server 0.6.6__py3-none-any.whl → 1.0.0a2__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.
- nonebot_plugin_l4d2_server/__init__.py +10 -93
- nonebot_plugin_l4d2_server/__main__.py +140 -0
- nonebot_plugin_l4d2_server/config.py +35 -0
- nonebot_plugin_l4d2_server/data/font/loli.ttf +0 -0
- nonebot_plugin_l4d2_server/l4_anne/__init__.py +124 -0
- nonebot_plugin_l4d2_server/l4_anne/ranne.py +18 -0
- nonebot_plugin_l4d2_server/l4_help/Help.json +102 -0
- nonebot_plugin_l4d2_server/l4_help/__init__.py +57 -0
- nonebot_plugin_l4d2_server/l4_help/draw.py +206 -0
- nonebot_plugin_l4d2_server/l4_help/icon//344/273/213/347/273/215.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//344/273/273/345/212/241.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//344/277/241/346/201/257.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/205/254/345/221/212.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/210/200/345/211/221.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/210/207/346/215/242.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/210/240/351/231/244.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/210/267/346/226/260.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/215/241/347/273/204.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/223/252/351/207/214.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/234/260/345/233/276.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/205/245.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/257/274/345/207/272.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//345/275/261.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/213/274/345/233/276.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/216/242/347/264/242.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/216/250/351/200/201.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/224/266/351/233/206.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/224/273/347/225/245.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/233/264/346/226/260.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/235/220/346/226/231.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/237/245/350/257/242.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/240/241/351/252/214.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/257/217/346/234/210.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/267/261/346/270/212.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/267/273/345/212/240.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//346/270/205/351/231/244.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//347/212/266/346/200/201.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//347/255/276/345/210/260.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//347/273/221/345/256/232.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//350/241/250.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//350/241/250/346/203/205.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//350/247/222/350/211/262.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//350/256/260/345/275/225.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//351/205/215/347/275/256.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/icon//351/207/215/345/220/257.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/texture2d/badge.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/texture2d/banner.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/texture2d/bg.jpg +0 -0
- nonebot_plugin_l4d2_server/l4_help/texture2d/button.png +0 -0
- nonebot_plugin_l4d2_server/l4_help/texture2d/icon.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/__init__.py +16 -0
- nonebot_plugin_l4d2_server/l4_image/anne_pil.py +17 -0
- nonebot_plugin_l4d2_server/l4_image/convert.py +175 -0
- nonebot_plugin_l4d2_server/{l4d2_image → l4_image}/download.py +11 -35
- nonebot_plugin_l4d2_server/l4_image/html_img.py +105 -0
- nonebot_plugin_l4d2_server/l4_image/image_tools.py +468 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image/template → l4_image/img/anne}/back.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/anne/back1.jpg +0 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/head/head.png +0 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/header/logo.png +0 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/header/player1.jpg +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Bocchi_The_Rock.html +299 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Bocchi_The_Rock.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/HYPixel11pxU-2.ttf +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Pixel.html +341 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Pixel.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Rainbow.html +355 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Rainbow.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/Tutumianhuatang-Bold-2.ttf +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/bilibili.svg +1 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/github.svg +1 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/template/l.svg +0 -1
- nonebot_plugin_l4d2_server/l4_image/img/template/m.svg +1 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/normal.html +247 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/vac.png +0 -0
- nonebot_plugin_l4d2_server/l4_image/img/template/vac_white.png +0 -0
- nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/template/w.svg +1 -1
- nonebot_plugin_l4d2_server/l4_image/model.py +15 -0
- nonebot_plugin_l4d2_server/{l4d2_image → l4_image}/vtfs.py +4 -2
- nonebot_plugin_l4d2_server/l4_request/__init__.py +143 -0
- nonebot_plugin_l4d2_server/l4_request/draw_msg.py +83 -0
- nonebot_plugin_l4d2_server/utils/api/api.py +10 -0
- nonebot_plugin_l4d2_server/utils/api/models.py +137 -0
- nonebot_plugin_l4d2_server/utils/api/request.py +337 -0
- nonebot_plugin_l4d2_server/utils/database/models.py +18 -0
- nonebot_plugin_l4d2_server/{l4d2_utils → utils}/utils.py +60 -63
- {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a2.dist-info}/METADATA +57 -66
- nonebot_plugin_l4d2_server-1.0.0a2.dist-info/RECORD +96 -0
- {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a2.dist-info}/WHEEL +1 -1
- nonebot_plugin_l4d2_server/data/L4D2/image/template/help.html +0 -263
- nonebot_plugin_l4d2_server/data/L4D2/image/template/help_dack.html +0 -231
- nonebot_plugin_l4d2_server/data/L4D2/image/template/m.svg +0 -1
- nonebot_plugin_l4d2_server/data/img/white.png +0 -0
- nonebot_plugin_l4d2_server/l4d2_anne/__init__.py +0 -95
- nonebot_plugin_l4d2_server/l4d2_anne/analysis.py +0 -54
- nonebot_plugin_l4d2_server/l4d2_anne/anne_telecom.py +0 -79
- nonebot_plugin_l4d2_server/l4d2_anne/server.py +0 -47
- nonebot_plugin_l4d2_server/l4d2_anne/startand.py +0 -17
- nonebot_plugin_l4d2_server/l4d2_anne/utils.py +0 -294
- nonebot_plugin_l4d2_server/l4d2_data/__init__.py +0 -105
- nonebot_plugin_l4d2_server/l4d2_data/config.py +0 -18
- nonebot_plugin_l4d2_server/l4d2_data/players.py +0 -100
- nonebot_plugin_l4d2_server/l4d2_data/serverip.py +0 -40
- nonebot_plugin_l4d2_server/l4d2_file/__init__.py +0 -222
- nonebot_plugin_l4d2_server/l4d2_file/ayromote.py +0 -64
- nonebot_plugin_l4d2_server/l4d2_file/input_json.py +0 -77
- nonebot_plugin_l4d2_server/l4d2_file/remote.py +0 -86
- nonebot_plugin_l4d2_server/l4d2_file/utils.py +0 -104
- nonebot_plugin_l4d2_server/l4d2_image/__init__.py +0 -125
- nonebot_plugin_l4d2_server/l4d2_image/htmlimg.py +0 -18
- nonebot_plugin_l4d2_server/l4d2_image/images.py +0 -92
- nonebot_plugin_l4d2_server/l4d2_image/one.py +0 -44
- nonebot_plugin_l4d2_server/l4d2_image/send_image_tool.py +0 -32
- nonebot_plugin_l4d2_server/l4d2_image/steam.py +0 -63
- nonebot_plugin_l4d2_server/l4d2_push/__init__.py +0 -225
- nonebot_plugin_l4d2_server/l4d2_queries/__init__.py +0 -326
- nonebot_plugin_l4d2_server/l4d2_queries/himi.py +0 -113
- nonebot_plugin_l4d2_server/l4d2_queries/local_ip.py +0 -41
- nonebot_plugin_l4d2_server/l4d2_queries/qqgroup.py +0 -370
- nonebot_plugin_l4d2_server/l4d2_queries/send_msg.py +0 -131
- nonebot_plugin_l4d2_server/l4d2_queries/utils.py +0 -212
- nonebot_plugin_l4d2_server/l4d2_server/__init__.py +0 -118
- nonebot_plugin_l4d2_server/l4d2_server/index.py +0 -0
- nonebot_plugin_l4d2_server/l4d2_server/rcon.py +0 -53
- nonebot_plugin_l4d2_server/l4d2_server/workshop.py +0 -82
- nonebot_plugin_l4d2_server/l4d2_update/__init__.py +0 -137
- nonebot_plugin_l4d2_server/l4d2_update/draw_update_log.py +0 -45
- nonebot_plugin_l4d2_server/l4d2_update/restart.py +0 -69
- nonebot_plugin_l4d2_server/l4d2_update/update.py +0 -53
- nonebot_plugin_l4d2_server/l4d2_utils/classcal.py +0 -53
- nonebot_plugin_l4d2_server/l4d2_utils/command.py +0 -23
- nonebot_plugin_l4d2_server/l4d2_utils/config.py +0 -201
- nonebot_plugin_l4d2_server/l4d2_utils/message.py +0 -59
- nonebot_plugin_l4d2_server/l4d2_utils/rule.py +0 -35
- nonebot_plugin_l4d2_server/l4d2_utils/seach.py +0 -43
- nonebot_plugin_l4d2_server/l4d2_utils/txt_to_img.py +0 -32
- nonebot_plugin_l4d2_server/l4d2_web/web.py +0 -277
- nonebot_plugin_l4d2_server/l4d2_web/webUI.py +0 -506
- nonebot_plugin_l4d2_server/l4d2_web/webUI_s.py +0 -94
- nonebot_plugin_l4d2_server-0.6.6.dist-info/RECORD +0 -70
- /nonebot_plugin_l4d2_server/{data/L4D2/image/template → l4_image/img/anne}/anne.html +0 -0
- /nonebot_plugin_l4d2_server/{data/L4D2/image/template → l4_image/img/anne}/group_ip.html +0 -0
- /nonebot_plugin_l4d2_server/{data/L4D2/image/template → l4_image/img/anne}/ip.html +0 -0
- /nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/template/fingerprint.svg +0 -0
- /nonebot_plugin_l4d2_server/{data/L4D2/image → l4_image/img}/template/vue.css +0 -0
- /nonebot_plugin_l4d2_server/{l4d2_data/database.py → l4_request/utils.py} +0 -0
- {nonebot_plugin_l4d2_server-0.6.6.dist-info → nonebot_plugin_l4d2_server-1.0.0a2.dist-info}/licenses/LICENSE +0 -0
@@ -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
|
-
)
|