nonebot-plugin-rollpig 0.2.2__py3-none-any.whl → 0.2.3__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.
@@ -5,6 +5,7 @@ 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
+ import requests
8
9
 
9
10
  # 确保依赖插件先被 NoneBot 注册
10
11
  require("nonebot_plugin_htmlrender")
@@ -19,6 +20,7 @@ __plugin_meta__ = PluginMetadata(
19
20
  description="抽取属于自己的小猪",
20
21
  usage="""
21
22
  今日小猪 - 抽取今天属于你的小猪
23
+ 随机小猪 - 从pighub随机获取一张猪猪图
22
24
  """,
23
25
  type="application",
24
26
  homepage="https://github.com/Bearlele/nonebot-plugin-rollpig",
@@ -34,7 +36,23 @@ RES_DIR = PLUGIN_DIR / "resource"
34
36
  # 今日记录
35
37
  TODAY_PATH = store.get_plugin_data_file("today.json")
36
38
 
37
- cmd = on_command("今天是什么小猪", aliases={"今日小猪"})
39
+ cmd = on_command("今天是什么小猪", aliases={"今日小猪"}, block=True)
40
+ roll_pig = on_command("随机小猪", block=True)
41
+
42
+ @roll_pig.handle()
43
+ async def _(event: Event):
44
+ try:
45
+ response = requests.get("https://pighub.top/api/all-images")
46
+ response.raise_for_status() # 检查请求是否成功
47
+ data = response.json()
48
+ if data and data["images"]:
49
+ pig = random.choice(data["images"])
50
+ image_url = "https://pighub.top/data/" + pig["thumbnail"].split("/")[-1]
51
+ await roll_pig.finish(MessageSegment.image(image_url))
52
+ else:
53
+ await roll_pig.finish("没有找到小猪图片")
54
+ except requests.exceptions.RequestException as e:
55
+ await roll_pig.finish(f"请求出错:{e}")
38
56
 
39
57
 
40
58
  def load_json(path, default):
@@ -57,7 +75,6 @@ def find_image_file(pig_id: str) -> Path | None:
57
75
  return file
58
76
  return None
59
77
 
60
-
61
78
  # 载入小猪信息
62
79
  PIG_LIST = load_json(PIGINFO_PATH, [])
63
80
  if not PIG_LIST:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot_plugin_rollpig
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: 今天是什么小猪
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -57,6 +57,8 @@ nb plugin install nonebot_plugin_rollpig
57
57
  - 重复抽取不会改变结果 🐷
58
58
  - 每天 0 点自动重置 🐖
59
59
 
60
+ **随机小猪** - 从PigHub随机获取一张猪猪图 🐖
61
+
60
62
  ---
61
63
 
62
64
  ### 🐖 新增小猪 🐖
@@ -1,4 +1,4 @@
1
- nonebot_plugin_rollpig/__init__.py,sha256=paIp_Tqb-qBhe3tbvD5kEm2QIAHf3Frr6kDOY-ZexwI,3607
1
+ nonebot_plugin_rollpig/__init__.py,sha256=LQf4_AmGVwpiiVMMMeaeHZCXZ8E_NDvkLqZ4HU6XW-w,4396
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.2.dist-info/licenses/LICENSE,sha256=zn7XqavdCw11Nln_m8Eu0S7C3rZ9C-VGbqbrVGeSTGg,1087
49
- nonebot_plugin_rollpig-0.2.2.dist-info/METADATA,sha256=LAeigOITB1Ay6mdVZbxnNOTmxWz8g9QaSo10u0ZYA-o,2658
50
- nonebot_plugin_rollpig-0.2.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
51
- nonebot_plugin_rollpig-0.2.2.dist-info/RECORD,,
48
+ nonebot_plugin_rollpig-0.2.3.dist-info/licenses/LICENSE,sha256=zn7XqavdCw11Nln_m8Eu0S7C3rZ9C-VGbqbrVGeSTGg,1087
49
+ nonebot_plugin_rollpig-0.2.3.dist-info/METADATA,sha256=oZINPcuDR7NUb6oIPeN4RYfNuRGw8o5AyFisOp3xy5w,2720
50
+ nonebot_plugin_rollpig-0.2.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
51
+ nonebot_plugin_rollpig-0.2.3.dist-info/RECORD,,