nonebot-plugin-rollpig 0.2.0__tar.gz → 0.2.2__tar.gz
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-0.2.0 → nonebot_plugin_rollpig-0.2.2}/PKG-INFO +1 -1
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/__init__.py +33 -41
- nonebot_plugin_rollpig-0.2.2/nonebot_plugin_rollpig/resource/image/invisible_pig.png +0 -0
- nonebot_plugin_rollpig-0.2.2/nonebot_plugin_rollpig/resource/image/lao_zhu_li.png +0 -0
- nonebot_plugin_rollpig-0.2.2/nonebot_plugin_rollpig/resource/image/pig_god.png +0 -0
- nonebot_plugin_rollpig-0.2.2/nonebot_plugin_rollpig/resource/image/tank_pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/pig.json +24 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/pyproject.toml +1 -1
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/LICENSE +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/README.md +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/android-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/apple-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/bacon.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/big-lazy-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/black-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/black-white-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/chained_crown_pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/crystal-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/demon-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/doll-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/explosive-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/goblin-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/heaven-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/human.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/landmine-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/magic-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/mc_porkchop.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/mechanical-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-ball.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-bun.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-cat.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-die.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-human.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-souffle.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-stamp.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig-turtle.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/pork-skewer.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/rainbow-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/roasted-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/skeleton-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/snow-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/soul-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/tangyuan_pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/taxi-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/vangogh_pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/watermelon-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/wild-boar.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/zhuge-liang.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/image/zombie-pig.png +0 -0
- {nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/resource/template.html +0 -0
{nonebot_plugin_rollpig-0.2.0 → nonebot_plugin_rollpig-0.2.2}/nonebot_plugin_rollpig/__init__.py
RENAMED
|
@@ -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
|
-
#
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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 _(
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
if
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
#
|
|
89
|
-
if user_id in
|
|
90
|
-
pig =
|
|
91
|
-
await send_rendered_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
|
-
|
|
95
|
-
|
|
96
|
-
logger.error("pig.json 里没找到小猪信息哦~")
|
|
87
|
+
if not PIG_LIST:
|
|
88
|
+
await cmd.finish("小猪信息加载失败,请检查后台报错!")
|
|
97
89
|
return
|
|
98
90
|
|
|
99
|
-
#
|
|
100
|
-
pig = random.choice(
|
|
91
|
+
# 随机抽取
|
|
92
|
+
pig = random.choice(PIG_LIST)
|
|
101
93
|
|
|
102
94
|
# 保存当天该用户的抽取结果
|
|
103
|
-
|
|
104
|
-
save_json(TODAY_PATH,
|
|
95
|
+
user_records[user_id] = pig
|
|
96
|
+
save_json(TODAY_PATH, today_cache)
|
|
105
97
|
|
|
106
|
-
await send_rendered_pig(
|
|
98
|
+
await send_rendered_pig(pig)
|
|
107
99
|
|
|
108
|
-
async def send_rendered_pig(
|
|
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))
|
|
Binary file
|
|
@@ -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
|
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|