nonebot-plugin-rollpig 0.2.0__py3-none-any.whl → 0.2.2__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,22 +1,18 @@
1
+ import json, random, datetime
2
+ from pathlib import Path
3
+
1
4
  from nonebot import on_command, require
5
+ from nonebot.adapters.onebot.v11 import Event, MessageSegment
6
+ from nonebot.log import logger
2
7
  from nonebot.plugin import PluginMetadata
3
- from nonebot.adapters.onebot.v11 import MessageSegment
4
8
 
5
9
  # 确保依赖插件先被 NoneBot 注册
6
- require("nonebot_plugin_apscheduler")
7
10
  require("nonebot_plugin_htmlrender")
8
11
  require("nonebot_plugin_localstore")
9
12
 
10
- from nonebot_plugin_apscheduler import scheduler
11
13
  from nonebot_plugin_htmlrender import template_to_pic
12
14
  import nonebot_plugin_localstore as store
13
15
 
14
- from nonebot.log import logger
15
- import random
16
- import json
17
- import datetime
18
- from pathlib import Path
19
-
20
16
  # 插件配置页
21
17
  __plugin_meta__ = PluginMetadata(
22
18
  name="今天是什么小猪",
@@ -38,7 +34,7 @@ RES_DIR = PLUGIN_DIR / "resource"
38
34
  # 今日记录
39
35
  TODAY_PATH = store.get_plugin_data_file("today.json")
40
36
 
41
- cmd = on_command("今天是什么小猪", aliases={"今日小猪", "我是什么小猪"})
37
+ cmd = on_command("今天是什么小猪", aliases={"今日小猪"})
42
38
 
43
39
 
44
40
  def load_json(path, default):
@@ -47,7 +43,6 @@ def load_json(path, default):
47
43
  return default
48
44
  return json.loads(path.read_text("utf-8"))
49
45
 
50
-
51
46
  def save_json(path, data):
52
47
  path.write_text(
53
48
  json.dumps(data, ensure_ascii=False, indent=2),
@@ -56,7 +51,6 @@ def save_json(path, data):
56
51
 
57
52
  def find_image_file(pig_id: str) -> Path | None:
58
53
  exts = ["png", "jpg", "jpeg", "webp", "gif"]
59
-
60
54
  for ext in exts:
61
55
  file = IMAGE_DIR / f"{pig_id}.{ext}"
62
56
  if file.exists():
@@ -64,48 +58,46 @@ def find_image_file(pig_id: str) -> Path | None:
64
58
  return None
65
59
 
66
60
 
67
- # 0 点自动清空
68
- @scheduler.scheduled_job("cron", hour=0, minute=0)
69
- def reset_today():
70
- if TODAY_PATH.exists():
71
- TODAY_PATH.unlink()
72
- logger.info("已清空今日记录")
61
+ # 载入小猪信息
62
+ PIG_LIST = load_json(PIGINFO_PATH, [])
63
+ if not PIG_LIST:
64
+ logger.error("小猪信息为空或不存在,请检查资源文件!")
73
65
 
74
66
  # 主函数
75
67
  @cmd.handle()
76
- async def _(bot, event):
68
+ async def _(event: Event):
77
69
  today_str = datetime.date.today().isoformat()
70
+ user_id = str(event.user_id)
78
71
 
79
72
  # 读取今日缓存
80
- today_data = load_json(TODAY_PATH, {})
81
-
82
- # 确保当天有字典存储用户数据
83
- if today_str not in today_data:
84
- today_data[today_str] = {}
85
-
86
- user_id = str(event.user_id) # 使用 QQ 号作为 key
87
-
88
- # 不重复抽
89
- if user_id in today_data[today_str]:
90
- pig = today_data[today_str][user_id]
91
- await send_rendered_pig(event, pig)
73
+ today_cache = load_json(TODAY_PATH, {"date": "", "records": {}})
74
+
75
+ # 检查日期,如果不是今天,则清空记录
76
+ if today_cache.get("date") != today_str:
77
+ today_cache = {"date": today_str, "records": {}}
78
+
79
+ user_records = today_cache["records"]
80
+
81
+ # 如果用户今天已经抽过,直接发送结果
82
+ if user_id in user_records:
83
+ pig = user_records[user_id]
84
+ await send_rendered_pig(pig)
92
85
  return
93
86
 
94
- piglist = load_json(PIGINFO_PATH, [])
95
- if not piglist:
96
- logger.error("pig.json 里没找到小猪信息哦~")
87
+ if not PIG_LIST:
88
+ await cmd.finish("小猪信息加载失败,请检查后台报错!")
97
89
  return
98
90
 
99
- # 随机
100
- pig = random.choice(piglist)
91
+ # 随机抽取
92
+ pig = random.choice(PIG_LIST)
101
93
 
102
94
  # 保存当天该用户的抽取结果
103
- today_data[today_str][user_id] = pig
104
- save_json(TODAY_PATH, today_data)
95
+ user_records[user_id] = pig
96
+ save_json(TODAY_PATH, today_cache)
105
97
 
106
- await send_rendered_pig(event, pig)
98
+ await send_rendered_pig(pig)
107
99
 
108
- async def send_rendered_pig(event, pig_data):
100
+ async def send_rendered_pig(pig_data: dict):
109
101
 
110
102
  # 使用 id 字段作为图片名
111
103
  pig_id = pig_data.get("id", "")
@@ -130,4 +122,4 @@ async def send_rendered_pig(event, pig_data):
130
122
  },
131
123
  )
132
124
 
133
- await cmd.finish(MessageSegment.image(pic))
125
+ await cmd.finish(MessageSegment.image(pic))
@@ -238,5 +238,29 @@
238
238
  "name": "猪排",
239
239
  "description": "建议烤熟食用",
240
240
  "analysis": "充满危机的世界里,你深知比起花哨的外表,实实在在恢复的那几格饥饿值才是最靠谱的保障。"
241
+ },
242
+ {
243
+ "id": "pig_god",
244
+ "name": "智慧小猪之神",
245
+ "description": "能带来智慧和好运的神奇小猪。",
246
+ "analysis": "你拥有超凡的智慧和乐于助人的心。虽然看起来可爱呆萌,但你总能在关键时刻给予指引,是猪的守护神,象征着幸运和成功。"
247
+ },
248
+ {
249
+ "id": "tank_pig",
250
+ "name": "坦克猪",
251
+ "description": "等待驾驶的重装小猪",
252
+ "analysis": "你拥有呆萌外表和钢铁之心。平时或许处于“待机”状态,看起来有些慵懒,但只要找对启动方式(按F),你就能化身坚不可摧的堡垒,碾压一切困难。"
253
+ },
254
+ {
255
+ "id": "lao_zhu_li",
256
+ "name": "老猪历",
257
+ "description": "资深有经验的猪前辈",
258
+ "analysis": "你拥有深厚的资历和丰富的经验。在大家眼中,你德高望重,遇事沉稳,总能用积累的智慧指引方向,是值得信赖的可靠前辈。"
259
+ },
260
+ {
261
+ "id": "invisible_pig",
262
+ "name": "隐形猪",
263
+ "description": "擅长隐身的神秘小猪",
264
+ "analysis": "你自带低调气场,擅长隐藏行踪。在人群中你虽不显眼,但总能默默观察一切,像个神秘的旁观者,拥有独特的洞察力。"
241
265
  }
242
266
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot_plugin_rollpig
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: 今天是什么小猪
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,4 @@
1
- nonebot_plugin_rollpig/__init__.py,sha256=brN4rRpt41rC3Ow-A2lYEBhuJVl94IqrNFBmnutJhmM,3689
1
+ nonebot_plugin_rollpig/__init__.py,sha256=paIp_Tqb-qBhe3tbvD5kEm2QIAHf3Frr6kDOY-ZexwI,3607
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
@@ -13,7 +13,9 @@ nonebot_plugin_rollpig/resource/image/explosive-pig.png,sha256=XRM33JxTbQ1Bqw2Wg
13
13
  nonebot_plugin_rollpig/resource/image/goblin-pig.png,sha256=if1Zvs70PIxDKWhhXACvhC1iBkESTg_cLCXvazXfQXc,59660
14
14
  nonebot_plugin_rollpig/resource/image/heaven-pig.png,sha256=040-bRaWpqBRNos1ZJtCK4nex63538JYI0gH99zUQLY,16832
15
15
  nonebot_plugin_rollpig/resource/image/human.png,sha256=y2MZg0Ccf5ixRHDx4fF6UIra6BI2HS5Ta_KRmbWULTI,5318
16
+ nonebot_plugin_rollpig/resource/image/invisible_pig.png,sha256=GjzA7fGZO7YS-nUqs4TqYh5Di3YupB-mGzzXf4Q0j44,16190
16
17
  nonebot_plugin_rollpig/resource/image/landmine-pig.png,sha256=UD3OMdPLushgE2GloIMyilut0QPoW3ui8_komc4xV-0,66099
18
+ nonebot_plugin_rollpig/resource/image/lao_zhu_li.png,sha256=qvQvyd1seC1-DDIdtDAlc3vPVxNGCLpcZc6uzmhqZgU,30435
17
19
  nonebot_plugin_rollpig/resource/image/magic-pig.png,sha256=QOA-_NYiVU-9tFDvL1-YrPnyoOshO3VDMNm5nflVWcY,45549
18
20
  nonebot_plugin_rollpig/resource/image/mc_porkchop.png,sha256=M8HF032rs9bbH-3TPB3go-WCrWwtbdZ6QTJamrPfaqM,35825
19
21
  nonebot_plugin_rollpig/resource/image/mechanical-pig.png,sha256=fy0WZeg-P0XDaQlKwYoGeZ3x-yVJ92M8VKLshr9R1qY,27301
@@ -26,6 +28,7 @@ nonebot_plugin_rollpig/resource/image/pig-souffle.png,sha256=WQkawKPidErANfWbgdM
26
28
  nonebot_plugin_rollpig/resource/image/pig-stamp.png,sha256=XjXECXX3ycWhAULjyc46sKVoYheedsdCfhJvmGXxutc,14028
27
29
  nonebot_plugin_rollpig/resource/image/pig-turtle.png,sha256=S16Wphg2_S4HmSifx4r3K6pNOQr7ADptZQjDymL2wc8,95055
28
30
  nonebot_plugin_rollpig/resource/image/pig.png,sha256=4ipCbYjK6rVqDLIeUH3HSCgUO8T5vTWybFa2hrXzfk4,10494
31
+ nonebot_plugin_rollpig/resource/image/pig_god.png,sha256=Hb1jUepKCczklcxnkqj6C9BdYtPaebUqMLwnDljxk_k,39122
29
32
  nonebot_plugin_rollpig/resource/image/pork-skewer.png,sha256=zmupRrODQ3VqqlsXLiDsQ5VWyNgnIOvqTP7S2_0Ig5U,9122
30
33
  nonebot_plugin_rollpig/resource/image/rainbow-pig.png,sha256=oMgqUANyXws4jpvIdCge4F0o13dEzMkABGMnsNM3mhU,67432
31
34
  nonebot_plugin_rollpig/resource/image/roasted-pig.png,sha256=KsIVHZslhVP0e3aklKw3-w_LfFVdIcZI_aFcg_VAxrE,39770
@@ -33,15 +36,16 @@ nonebot_plugin_rollpig/resource/image/skeleton-pig.png,sha256=hAKL6v5W2gyjuHKciE
33
36
  nonebot_plugin_rollpig/resource/image/snow-pig.png,sha256=IYvo1qUUsKC5JLGcHEcMWroyONO1L4Xcf15eBel-l90,18550
34
37
  nonebot_plugin_rollpig/resource/image/soul-pig.png,sha256=PlAp7k_DneuLpmN79NHqdsd_dM_o9bjmnTN7htzUaDE,13984
35
38
  nonebot_plugin_rollpig/resource/image/tangyuan_pig.png,sha256=igvJN9grj_hBDeKampFa6WJTg4VjrkyxpUdWzq4AoNk,1640768
39
+ nonebot_plugin_rollpig/resource/image/tank_pig.png,sha256=tKJ7Lowe1zo3eRH1N7ngKIPretGMW5UV7EaTVmbUYkg,52611
36
40
  nonebot_plugin_rollpig/resource/image/taxi-pig.png,sha256=d75kqIQbQK7U64SV4oKwnXMxKTCgmheo14gP1kmu7Zg,54313
37
41
  nonebot_plugin_rollpig/resource/image/vangogh_pig.png,sha256=twRQfwU4nE3f0UacjxFzUK5kpCQ5CzBaQmBYZDXN6Sc,2578934
38
42
  nonebot_plugin_rollpig/resource/image/watermelon-pig.png,sha256=Fuoe-svB661glzMeHbuA9RXJhKNvJ8DhQLuAfZbG6Rc,1325162
39
43
  nonebot_plugin_rollpig/resource/image/wild-boar.png,sha256=daBhmLS0SFVqhYtn12QsNjg1KzNh5oiuI7wFN-J4xbM,13378
40
44
  nonebot_plugin_rollpig/resource/image/zhuge-liang.png,sha256=yvF5hNUzBXJIHi-vwg5f4YD_aEtqUJeIarpyiNReios,49905
41
45
  nonebot_plugin_rollpig/resource/image/zombie-pig.png,sha256=fKQlp_kI3x8wMlVUT6U-rilMLpH0TpT_-ViNVWBSbcM,20797
42
- nonebot_plugin_rollpig/resource/pig.json,sha256=PqBF8X5TLqK1dOEtrKBd51hHJ4_h5XY3afGaUKRe3YI,11905
46
+ nonebot_plugin_rollpig/resource/pig.json,sha256=0YHz5eLZOSwo-3Yh44UgXrZ4vTmpvSDMx9Ejh0htlxM,13236
43
47
  nonebot_plugin_rollpig/resource/template.html,sha256=vX7vbT3BmmsXhswiUIHqHNLds_CcUQIuZKdnz5bVthc,1060
44
- nonebot_plugin_rollpig-0.2.0.dist-info/licenses/LICENSE,sha256=zn7XqavdCw11Nln_m8Eu0S7C3rZ9C-VGbqbrVGeSTGg,1087
45
- nonebot_plugin_rollpig-0.2.0.dist-info/METADATA,sha256=vULjnmd6elL8jHvL6n1feRWg_6LMJm7Wm6Q_wuHPlLY,2658
46
- nonebot_plugin_rollpig-0.2.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
47
- nonebot_plugin_rollpig-0.2.0.dist-info/RECORD,,
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,,