nonebot-plugin-rollpig 0.2.3__py3-none-any.whl → 0.2.5__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_rollpig/__init__.py +30 -17
- {nonebot_plugin_rollpig-0.2.3.dist-info → nonebot_plugin_rollpig-0.2.5.dist-info}/METADATA +1 -1
- {nonebot_plugin_rollpig-0.2.3.dist-info → nonebot_plugin_rollpig-0.2.5.dist-info}/RECORD +5 -5
- {nonebot_plugin_rollpig-0.2.3.dist-info → nonebot_plugin_rollpig-0.2.5.dist-info}/WHEEL +0 -0
- {nonebot_plugin_rollpig-0.2.3.dist-info → nonebot_plugin_rollpig-0.2.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import json, random, datetime
|
|
1
|
+
import json, random, datetime, asyncio, requests
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
|
|
4
4
|
from nonebot import on_command, require
|
|
5
5
|
from nonebot.adapters.onebot.v11 import Event, MessageSegment
|
|
6
6
|
from nonebot.log import logger
|
|
7
7
|
from nonebot.plugin import PluginMetadata
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
pig_images = []
|
|
9
10
|
|
|
10
11
|
# 确保依赖插件先被 NoneBot 注册
|
|
11
12
|
require("nonebot_plugin_htmlrender")
|
|
@@ -20,7 +21,7 @@ __plugin_meta__ = PluginMetadata(
|
|
|
20
21
|
description="抽取属于自己的小猪",
|
|
21
22
|
usage="""
|
|
22
23
|
今日小猪 - 抽取今天属于你的小猪
|
|
23
|
-
随机小猪 - 从
|
|
24
|
+
随机小猪 - 从PigHub随机获取一张猪猪图
|
|
24
25
|
""",
|
|
25
26
|
type="application",
|
|
26
27
|
homepage="https://github.com/Bearlele/nonebot-plugin-rollpig",
|
|
@@ -41,19 +42,31 @@ roll_pig = on_command("随机小猪", block=True)
|
|
|
41
42
|
|
|
42
43
|
@roll_pig.handle()
|
|
43
44
|
async def _(event: Event):
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
global pig_images
|
|
46
|
+
if not pig_images:
|
|
47
|
+
try:
|
|
48
|
+
data = await asyncio.to_thread(sync_fetch_pig_data, "https://pighub.top/api/all-images")
|
|
49
|
+
if data and data.get("images"):
|
|
50
|
+
pig_images = data["images"]
|
|
51
|
+
logger.success(f"成功从 PigHub 缓存 {len(pig_images)} 头猪猪")
|
|
52
|
+
else:
|
|
53
|
+
logger.warning("PigHub 中找不到猪猪")
|
|
54
|
+
except requests.exceptions.RequestException as e:
|
|
55
|
+
logger.error(f"从PigHub中获取猪猪失败: {e}")
|
|
56
|
+
|
|
57
|
+
if not pig_images:
|
|
58
|
+
await roll_pig.finish("猪圈空荡荡...")
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
pig = random.choice(pig_images)
|
|
62
|
+
image_url = "https://pighub.top/data/" + pig["thumbnail"].split("/")[-1]
|
|
63
|
+
await roll_pig.finish(MessageSegment.image(image_url))
|
|
64
|
+
|
|
65
|
+
def sync_fetch_pig_data(url: str):
|
|
66
|
+
response = requests.get(url, timeout=30)
|
|
67
|
+
response.raise_for_status()
|
|
68
|
+
|
|
69
|
+
return response.json()
|
|
57
70
|
|
|
58
71
|
def load_json(path, default):
|
|
59
72
|
if not path.exists():
|
|
@@ -78,7 +91,7 @@ def find_image_file(pig_id: str) -> Path | None:
|
|
|
78
91
|
# 载入小猪信息
|
|
79
92
|
PIG_LIST = load_json(PIGINFO_PATH, [])
|
|
80
93
|
if not PIG_LIST:
|
|
81
|
-
logger.error("
|
|
94
|
+
logger.error("猪圈空荡荡,请检查资源文件!")
|
|
82
95
|
|
|
83
96
|
# 主函数
|
|
84
97
|
@cmd.handle()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
nonebot_plugin_rollpig/__init__.py,sha256=
|
|
1
|
+
nonebot_plugin_rollpig/__init__.py,sha256=A58M1sibFY4ygSfAjgSfxpboemxDo18c7WZQBFfUtjE,4781
|
|
2
2
|
nonebot_plugin_rollpig/resource/image/android-pig.png,sha256=WwY2rtsABH8YbDDIoQDR6WdHW8qpStm_lF8eXZ4K-Tc,37845
|
|
3
3
|
nonebot_plugin_rollpig/resource/image/apple-pig.png,sha256=HSh8SRguD65ZZLnbnTgtNiAqqNzZKuFijtKIC3TLZDU,41533
|
|
4
4
|
nonebot_plugin_rollpig/resource/image/bacon.png,sha256=7G86_W17C14qCRDKCGuRES4yfidIrIMz2gxOat3Gnn8,55722
|
|
@@ -45,7 +45,7 @@ nonebot_plugin_rollpig/resource/image/zhuge-liang.png,sha256=yvF5hNUzBXJIHi-vwg5
|
|
|
45
45
|
nonebot_plugin_rollpig/resource/image/zombie-pig.png,sha256=fKQlp_kI3x8wMlVUT6U-rilMLpH0TpT_-ViNVWBSbcM,20797
|
|
46
46
|
nonebot_plugin_rollpig/resource/pig.json,sha256=0YHz5eLZOSwo-3Yh44UgXrZ4vTmpvSDMx9Ejh0htlxM,13236
|
|
47
47
|
nonebot_plugin_rollpig/resource/template.html,sha256=vX7vbT3BmmsXhswiUIHqHNLds_CcUQIuZKdnz5bVthc,1060
|
|
48
|
-
nonebot_plugin_rollpig-0.2.
|
|
49
|
-
nonebot_plugin_rollpig-0.2.
|
|
50
|
-
nonebot_plugin_rollpig-0.2.
|
|
51
|
-
nonebot_plugin_rollpig-0.2.
|
|
48
|
+
nonebot_plugin_rollpig-0.2.5.dist-info/licenses/LICENSE,sha256=zn7XqavdCw11Nln_m8Eu0S7C3rZ9C-VGbqbrVGeSTGg,1087
|
|
49
|
+
nonebot_plugin_rollpig-0.2.5.dist-info/METADATA,sha256=XNJd-tb4Lm8CEZj8h3-NOnLLw0ubvW4sXBRibCa8k6Q,2720
|
|
50
|
+
nonebot_plugin_rollpig-0.2.5.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
51
|
+
nonebot_plugin_rollpig-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
{nonebot_plugin_rollpig-0.2.3.dist-info → nonebot_plugin_rollpig-0.2.5.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|