nonebot-plugin-rollpig 0.2.4__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.
@@ -1,33 +1,13 @@
1
1
  import json, random, datetime, asyncio, requests
2
2
  from pathlib import Path
3
3
 
4
- from nonebot import on_command, require, on_startup
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
9
  pig_images = []
10
10
 
11
- @on_startup
12
- async def load_pig_images():
13
- global pig_images
14
- try:
15
- data = await asyncio.to_thread(sync_fetch_pig_data, "https://pighub.top/api/all-images")
16
-
17
- if data and data.get("images"):
18
- pig_images = data["images"]
19
- logger.success(f"成功从 PigHub 缓存 {len(pig_images)} 头猪猪")
20
- else:
21
- logger.warning("PigHub 中找不到猪猪")
22
- except requests.exceptions.RequestException as e:
23
- logger.error(f"从PigHub中获取猪猪失败: {e}")
24
-
25
- def sync_fetch_pig_data(url: str):
26
- response = requests.get(url, timeout=30)
27
- response.raise_for_status()
28
-
29
- return response.json()
30
-
31
11
  # 确保依赖插件先被 NoneBot 注册
32
12
  require("nonebot_plugin_htmlrender")
33
13
  require("nonebot_plugin_localstore")
@@ -64,9 +44,6 @@ roll_pig = on_command("随机小猪", block=True)
64
44
  async def _(event: Event):
65
45
  global pig_images
66
46
  if not pig_images:
67
- await roll_pig.finish("猪圈空荡荡,猪猪还没加载出来或者加载失败了...")
68
-
69
- # 再次尝试
70
47
  try:
71
48
  data = await asyncio.to_thread(sync_fetch_pig_data, "https://pighub.top/api/all-images")
72
49
  if data and data.get("images"):
@@ -78,13 +55,18 @@ async def _(event: Event):
78
55
  logger.error(f"从PigHub中获取猪猪失败: {e}")
79
56
 
80
57
  if not pig_images:
81
- await roll_pig.finish("猪圈空荡荡,猪猪还是没加载出来...")
58
+ await roll_pig.finish("猪圈空荡荡...")
82
59
  return
83
60
 
84
61
  pig = random.choice(pig_images)
85
62
  image_url = "https://pighub.top/data/" + pig["thumbnail"].split("/")[-1]
86
63
  await roll_pig.finish(MessageSegment.image(image_url))
87
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()
88
70
 
89
71
  def load_json(path, default):
90
72
  if not path.exists():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot_plugin_rollpig
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: 今天是什么小猪
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,4 @@
1
- nonebot_plugin_rollpig/__init__.py,sha256=BkTa4KmzREAFDwqm_VaEdQJIPxgzwe26lNcVFXmT7A0,5501
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.4.dist-info/licenses/LICENSE,sha256=zn7XqavdCw11Nln_m8Eu0S7C3rZ9C-VGbqbrVGeSTGg,1087
49
- nonebot_plugin_rollpig-0.2.4.dist-info/METADATA,sha256=Ewp0ze1G1_24hTqyDlWkcA-xYhgRH_i9_igiBFRlAng,2720
50
- nonebot_plugin_rollpig-0.2.4.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
51
- nonebot_plugin_rollpig-0.2.4.dist-info/RECORD,,
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,,