nonebot-plugin-bugu 0.3.0__tar.gz → 0.4.1__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.
Files changed (33) hide show
  1. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/PKG-INFO +41 -14
  2. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/README.md +40 -13
  3. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/__init__.py +4 -0
  4. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/commands.py +3 -1
  5. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/draw.py +10 -0
  6. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/common.py +33 -1
  7. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/recipes/render.py +130 -1
  8. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/recipes/reply.py +105 -8
  9. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/starsea/render.py +275 -0
  10. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/starsea/reply.py +192 -20
  11. nonebot_plugin_bugu-0.4.1/nonebot_plugin_bugu/warmup.py +121 -0
  12. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/pyproject.toml +1 -1
  13. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/LICENSE +0 -0
  14. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/api.py +0 -0
  15. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/config.py +0 -0
  16. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/__init__.py +0 -0
  17. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/flowers/__init__.py +0 -0
  18. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/flowers/data.py +0 -0
  19. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/flowers/render.py +0 -0
  20. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/flowers/reply.py +0 -0
  21. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/neighbors/__init__.py +0 -0
  22. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/neighbors/data.py +0 -0
  23. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/neighbors/render.py +0 -0
  24. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/neighbors/reply.py +0 -0
  25. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/recipes/__init__.py +0 -0
  26. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/recipes/data.py +0 -0
  27. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/recipes/search.py +0 -0
  28. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/starsea/__init__.py +0 -0
  29. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/starsea/data.py +0 -0
  30. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/features/starsea/search.py +0 -0
  31. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/fonts.py +0 -0
  32. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/runtime.py +0 -0
  33. {nonebot_plugin_bugu-0.3.0 → nonebot_plugin_bugu-0.4.1}/nonebot_plugin_bugu/values.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-bugu
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: 布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘与鲜花培育
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -37,8 +37,8 @@ Description-Content-Type: text/markdown
37
37
 
38
38
  | 模块 | 能干什么 |
39
39
  | --- | --- |
40
- | 🍳 **菜谱查询** | 121 道菜谱的食材 / 厨具 / 力气 / 特殊效果 / 获取途径,支持按食材、类型、厨具、效果、特征搜索 |
41
- | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;还能按物种反查「在哪几个岛」 |
40
+ | 🍳 **菜谱查询** | 121 道菜谱的食材 / 厨具 / 力气 / 特殊效果 / 获取途径;支持按食材、类型、厨具、效果、特征搜索,也能按目录一页页翻 |
41
+ | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;物种图鉴可按大类翻页;还能按物种反查「在哪几个岛」 |
42
42
  | 🧑‍🤝‍🧑 **友邻备忘** | 10 位友邻的立绘、资料、介绍和喜爱 / 好感 / 反感 / 关于词条与友邻能力 |
43
43
  | 🌷 **鲜花培育** | 13 个品种 87 种花色的杂交配方表 + 花色图鉴(品质、颜色、产地) |
44
44
 
@@ -52,6 +52,12 @@ Description-Content-Type: text/markdown
52
52
 
53
53
  ![鲜花培育](docs/flower-card.png)
54
54
 
55
+ 不知道菜名 / 物种名也能查——目录是图片,用页码翻:
56
+
57
+ ![菜谱目录](docs/recipe-catalog.png)
58
+
59
+ ![星海图鉴](docs/starsea-catalog.png)
60
+
55
61
  ## 安装
56
62
 
57
63
  需要 Python 3.9+ 和 NoneBot2(OneBot V11 适配器)。
@@ -89,7 +95,7 @@ nonebot.load_plugin("nonebot_plugin_bugu")
89
95
  | --- | --- | --- |
90
96
  | `BUGU_API_BASE` | `https://bugu.nsun200512.cc` | 数据站点地址 |
91
97
  | `BUGU_REQUEST_TIMEOUT` | `15.0` | 单次请求超时(秒) |
92
- | `BUGU_DATA_CACHE_TTL` | `21600` | 数据内存缓存时长(秒) |
98
+ | `BUGU_DATA_CACHE_TTL` | `21600` | 数据内存缓存时长(秒);后台刷新间隔 = 它的一半(最低 30 分钟) |
93
99
  | `BUGU_IMAGE_CACHE_TTL` | `2592000` | 底图 / 图标 / 立绘磁盘缓存时长(秒) |
94
100
  | `BUGU_IMAGE_ENABLED` | `true` | 是否出图;关闭后只发文字 |
95
101
  | `BUGU_COOLDOWN_SECONDS` | `3` | 同一用户两次出图的最小间隔(秒),`0` 不限制 |
@@ -116,12 +122,14 @@ nonebot.load_plugin("nonebot_plugin_bugu")
116
122
  | 指令 | 权限 | 说明 |
117
123
  | --- | --- | --- |
118
124
  | `/布谷` | 所有人 | 全部指令一览 |
125
+ | `/菜谱 列表 [类型/厨具/词] [页码]` | 所有人 | 菜谱目录卡片,可翻页 |
119
126
  | `/菜谱 [菜名 / 编号]` | 所有人 | 不带参数看统计;带参数出菜谱卡片 |
120
- | `/菜谱 随机` | 所有人 | 随手看一道 |
127
+ | `/菜谱 随机 [条件]` | 所有人 | 随手看一道(可按类型/厨具限定) |
121
128
  | `/菜谱查 <关键词>` | 所有人 | 搜索 / 筛选(关键词可混写) |
122
129
  | `/星海 <任意词>` | 所有人 | 智能识别区域 / 点位 / 物种 |
123
130
  | `/星海地图 [区域]` | 所有人 | 区域地图卡片,不带参数列所有区域 |
124
- | `/星海点位 <点位名>` | 所有人 | 点位详情卡片 |
131
+ | `/星海 列表 [大类] [页码]` | 所有人 | 物种图鉴卡片;不带大类先出大类索引 |
132
+ | `/星海点位 [区域 / 点位名]` | 所有人 | 给区域出点位清单卡片,给点位名出详情 |
125
133
  | `/星海查 <物种 / 大类>` | 所有人 | 跨区域搜索 |
126
134
  | `/友邻 [名字] [分区]` | 所有人 | 友邻名单 / 档案卡;分区可填 喜爱 / 好感 / 反感 / 关于 / 介绍 |
127
135
  | `/鲜花 [品种 / 花名]` | 所有人 | 品种列表 / 培育配方卡 / 单朵花详情 |
@@ -132,25 +140,36 @@ nonebot.load_plugin("nonebot_plugin_bugu")
132
140
  一个查询里可以同时混写食材、菜名、类型、厨具、效果、特征,规则和站点一致:
133
141
 
134
142
  ```
143
+ /菜谱 列表 → 目录第 1 页(每页 15 道,5×3)
144
+ /菜谱 列表 2 → 第 2 页
145
+ /菜谱 列表 简单 → 只看简单类型
146
+ /菜谱 列表 煮锅 3 → 煮锅分类的第 3 页
135
147
  /菜谱 炒鲜蔬 → 精确菜名出卡片
136
148
  /菜谱 12 → 按编号出卡片
149
+ /菜谱 随机 汤羹 → 在汤羹里随机
137
150
  /菜谱查 苹果 → 「可用苹果烹饪」+「名称含苹果」两组
138
151
  /菜谱查 煮锅 苹果 → 用苹果做的煮锅菜谱
139
152
  /菜谱查 秘制 → 只看秘制菜谱
140
153
  /菜谱查 甜点 煮锅 → 甜点特征 + 煮锅
141
154
  ```
142
155
 
156
+ 打错字也有救:没命中时会用编辑距离给几个相近的菜名。
157
+
143
158
  支持的筛选值:菜品类型(简单 / 招牌 / 宴客 / 秘制 / 奇迹盛宴)、厨具(煮锅 / 烤箱 / 榨汁机)、
144
159
  特殊效果(大力播洒 / 大力敲伐 / 钓鱼之力……)、菜品特征(荤菜 / 素菜 / 主食 / 汤羹……)。
145
160
 
146
161
  ### 星海地图
147
162
 
148
163
  ```
149
- /星海地图 → 三个区域列表
150
- /星海地图 H83 → 禾夏 H83 区地图卡片(点位 1~15 编号 + 图例)
164
+ /星海 → 星海用法
165
+ /星海 列表 → 图鉴大类索引(11 个大类 + 数量 + 代表物种)
166
+ /星海 列表 河鱼 → 河鱼图鉴(27 种,每页 32 个,带品质/特产/采集点数量)
167
+ /星海 列表 鱼 2 → 口语别名 + 翻页
168
+ /星海地图 → 三个区域列表
169
+ /星海地图 H83 → 禾夏 H83 区地图卡片(点位 1~15 编号 + 图例)
170
+ /星海点位 H83 → 这个区域的点位清单(编号/类型/物种数)
151
171
  /星海点位 迷途小屋之屿 → 点位详情(昆虫 12 / 树木 3 / 鲜花 3 / 创想卡 1 / 种子 1)
152
172
  /星海查 三色锦鲤 → 这个物种出现在哪几个点位
153
- /星海 河鱼 → 智能识别
154
173
  ```
155
174
 
156
175
  搜索支持物种名、大类(`鱼`→河鱼/海鱼,`生物`→昆虫/河鱼/海鱼/海岸生物,也认 `树`、`花`、`矿`、`特产`)和点位名。
@@ -169,8 +188,16 @@ nonebot.load_plugin("nonebot_plugin_bugu")
169
188
  - 接口:`/api/bootstrap`(菜谱)、`/api/starsea`(星海)、`/api/neighbors`(友邻)、`/api/flowers`(鲜花)
170
189
  - 图片:底图 / 菜品 / 图标 / 立绘都从同站点下载并本地缓存
171
190
 
172
- 本插件只做聊天查询,**数据版权归布谷工具箱所有**。站点更新后最迟等缓存过期(默认 6 小时),
173
- 或者让超管发一次 `/布谷刷新`。
191
+ 本插件只做聊天查询,**数据版权归布谷工具箱所有**。
192
+
193
+ ### 数据刷新
194
+
195
+ 四套数据是常开后台预热的,没有开关:
196
+
197
+ - **启动时**先拉一遍(第一条命令就是热的)
198
+ - 之后**每 3 小时**自动刷新一次(= `BUGU_DATA_CACHE_TTL` 的一半,最低 30 分钟)
199
+ - 刷新失败不会清掉旧数据,**10 分钟后重试**,期间照常使用旧缓存
200
+ - 需要立刻同步站点改动时,超管发 `/布谷刷新`
174
201
 
175
202
  ## 常见问题
176
203
 
@@ -181,8 +208,8 @@ nonebot.load_plugin("nonebot_plugin_bugu")
181
208
 
182
209
  **Q:会不会被站点限流?**
183
210
 
184
- 四个接口都是按需拉取并缓存 6 小时,图片按 URL 缓存 30 天,正常使用打不了几发请求。
185
- 遇到 429 会提示「请求太频繁」,等一会儿再试。
211
+ 四个接口每 3 小时才拉一次(后台预热),图片按 URL 缓存 30 天,正常使用打不了几发请求。
212
+ 遇到 429 会提示「请求太频繁」,后台刷新会自动退避重试,旧缓存继续可用。
186
213
 
187
214
  ## 开发
188
215
 
@@ -200,7 +227,7 @@ nonebot_plugin_bugu/
200
227
  ├── config.py # 配置项
201
228
  ├── api.py # 四个接口的客户端 + 内存 / 磁盘缓存
202
229
  ├── values.py # 字段兜底与通用小工具
203
- ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚
230
+ ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚、分页卡片
204
231
  ├── fonts.py # 中文字体探测
205
232
  ├── runtime.py # 单例:客户端 / 字体 / 进度
206
233
  ├── commands.py # 命令注册与分发
@@ -9,8 +9,8 @@
9
9
 
10
10
  | 模块 | 能干什么 |
11
11
  | --- | --- |
12
- | 🍳 **菜谱查询** | 121 道菜谱的食材 / 厨具 / 力气 / 特殊效果 / 获取途径,支持按食材、类型、厨具、效果、特征搜索 |
13
- | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;还能按物种反查「在哪几个岛」 |
12
+ | 🍳 **菜谱查询** | 121 道菜谱的食材 / 厨具 / 力气 / 特殊效果 / 获取途径;支持按食材、类型、厨具、效果、特征搜索,也能按目录一页页翻 |
13
+ | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;物种图鉴可按大类翻页;还能按物种反查「在哪几个岛」 |
14
14
  | 🧑‍🤝‍🧑 **友邻备忘** | 10 位友邻的立绘、资料、介绍和喜爱 / 好感 / 反感 / 关于词条与友邻能力 |
15
15
  | 🌷 **鲜花培育** | 13 个品种 87 种花色的杂交配方表 + 花色图鉴(品质、颜色、产地) |
16
16
 
@@ -24,6 +24,12 @@
24
24
 
25
25
  ![鲜花培育](docs/flower-card.png)
26
26
 
27
+ 不知道菜名 / 物种名也能查——目录是图片,用页码翻:
28
+
29
+ ![菜谱目录](docs/recipe-catalog.png)
30
+
31
+ ![星海图鉴](docs/starsea-catalog.png)
32
+
27
33
  ## 安装
28
34
 
29
35
  需要 Python 3.9+ 和 NoneBot2(OneBot V11 适配器)。
@@ -61,7 +67,7 @@ nonebot.load_plugin("nonebot_plugin_bugu")
61
67
  | --- | --- | --- |
62
68
  | `BUGU_API_BASE` | `https://bugu.nsun200512.cc` | 数据站点地址 |
63
69
  | `BUGU_REQUEST_TIMEOUT` | `15.0` | 单次请求超时(秒) |
64
- | `BUGU_DATA_CACHE_TTL` | `21600` | 数据内存缓存时长(秒) |
70
+ | `BUGU_DATA_CACHE_TTL` | `21600` | 数据内存缓存时长(秒);后台刷新间隔 = 它的一半(最低 30 分钟) |
65
71
  | `BUGU_IMAGE_CACHE_TTL` | `2592000` | 底图 / 图标 / 立绘磁盘缓存时长(秒) |
66
72
  | `BUGU_IMAGE_ENABLED` | `true` | 是否出图;关闭后只发文字 |
67
73
  | `BUGU_COOLDOWN_SECONDS` | `3` | 同一用户两次出图的最小间隔(秒),`0` 不限制 |
@@ -88,12 +94,14 @@ nonebot.load_plugin("nonebot_plugin_bugu")
88
94
  | 指令 | 权限 | 说明 |
89
95
  | --- | --- | --- |
90
96
  | `/布谷` | 所有人 | 全部指令一览 |
97
+ | `/菜谱 列表 [类型/厨具/词] [页码]` | 所有人 | 菜谱目录卡片,可翻页 |
91
98
  | `/菜谱 [菜名 / 编号]` | 所有人 | 不带参数看统计;带参数出菜谱卡片 |
92
- | `/菜谱 随机` | 所有人 | 随手看一道 |
99
+ | `/菜谱 随机 [条件]` | 所有人 | 随手看一道(可按类型/厨具限定) |
93
100
  | `/菜谱查 <关键词>` | 所有人 | 搜索 / 筛选(关键词可混写) |
94
101
  | `/星海 <任意词>` | 所有人 | 智能识别区域 / 点位 / 物种 |
95
102
  | `/星海地图 [区域]` | 所有人 | 区域地图卡片,不带参数列所有区域 |
96
- | `/星海点位 <点位名>` | 所有人 | 点位详情卡片 |
103
+ | `/星海 列表 [大类] [页码]` | 所有人 | 物种图鉴卡片;不带大类先出大类索引 |
104
+ | `/星海点位 [区域 / 点位名]` | 所有人 | 给区域出点位清单卡片,给点位名出详情 |
97
105
  | `/星海查 <物种 / 大类>` | 所有人 | 跨区域搜索 |
98
106
  | `/友邻 [名字] [分区]` | 所有人 | 友邻名单 / 档案卡;分区可填 喜爱 / 好感 / 反感 / 关于 / 介绍 |
99
107
  | `/鲜花 [品种 / 花名]` | 所有人 | 品种列表 / 培育配方卡 / 单朵花详情 |
@@ -104,25 +112,36 @@ nonebot.load_plugin("nonebot_plugin_bugu")
104
112
  一个查询里可以同时混写食材、菜名、类型、厨具、效果、特征,规则和站点一致:
105
113
 
106
114
  ```
115
+ /菜谱 列表 → 目录第 1 页(每页 15 道,5×3)
116
+ /菜谱 列表 2 → 第 2 页
117
+ /菜谱 列表 简单 → 只看简单类型
118
+ /菜谱 列表 煮锅 3 → 煮锅分类的第 3 页
107
119
  /菜谱 炒鲜蔬 → 精确菜名出卡片
108
120
  /菜谱 12 → 按编号出卡片
121
+ /菜谱 随机 汤羹 → 在汤羹里随机
109
122
  /菜谱查 苹果 → 「可用苹果烹饪」+「名称含苹果」两组
110
123
  /菜谱查 煮锅 苹果 → 用苹果做的煮锅菜谱
111
124
  /菜谱查 秘制 → 只看秘制菜谱
112
125
  /菜谱查 甜点 煮锅 → 甜点特征 + 煮锅
113
126
  ```
114
127
 
128
+ 打错字也有救:没命中时会用编辑距离给几个相近的菜名。
129
+
115
130
  支持的筛选值:菜品类型(简单 / 招牌 / 宴客 / 秘制 / 奇迹盛宴)、厨具(煮锅 / 烤箱 / 榨汁机)、
116
131
  特殊效果(大力播洒 / 大力敲伐 / 钓鱼之力……)、菜品特征(荤菜 / 素菜 / 主食 / 汤羹……)。
117
132
 
118
133
  ### 星海地图
119
134
 
120
135
  ```
121
- /星海地图 → 三个区域列表
122
- /星海地图 H83 → 禾夏 H83 区地图卡片(点位 1~15 编号 + 图例)
136
+ /星海 → 星海用法
137
+ /星海 列表 → 图鉴大类索引(11 个大类 + 数量 + 代表物种)
138
+ /星海 列表 河鱼 → 河鱼图鉴(27 种,每页 32 个,带品质/特产/采集点数量)
139
+ /星海 列表 鱼 2 → 口语别名 + 翻页
140
+ /星海地图 → 三个区域列表
141
+ /星海地图 H83 → 禾夏 H83 区地图卡片(点位 1~15 编号 + 图例)
142
+ /星海点位 H83 → 这个区域的点位清单(编号/类型/物种数)
123
143
  /星海点位 迷途小屋之屿 → 点位详情(昆虫 12 / 树木 3 / 鲜花 3 / 创想卡 1 / 种子 1)
124
144
  /星海查 三色锦鲤 → 这个物种出现在哪几个点位
125
- /星海 河鱼 → 智能识别
126
145
  ```
127
146
 
128
147
  搜索支持物种名、大类(`鱼`→河鱼/海鱼,`生物`→昆虫/河鱼/海鱼/海岸生物,也认 `树`、`花`、`矿`、`特产`)和点位名。
@@ -141,8 +160,16 @@ nonebot.load_plugin("nonebot_plugin_bugu")
141
160
  - 接口:`/api/bootstrap`(菜谱)、`/api/starsea`(星海)、`/api/neighbors`(友邻)、`/api/flowers`(鲜花)
142
161
  - 图片:底图 / 菜品 / 图标 / 立绘都从同站点下载并本地缓存
143
162
 
144
- 本插件只做聊天查询,**数据版权归布谷工具箱所有**。站点更新后最迟等缓存过期(默认 6 小时),
145
- 或者让超管发一次 `/布谷刷新`。
163
+ 本插件只做聊天查询,**数据版权归布谷工具箱所有**。
164
+
165
+ ### 数据刷新
166
+
167
+ 四套数据是常开后台预热的,没有开关:
168
+
169
+ - **启动时**先拉一遍(第一条命令就是热的)
170
+ - 之后**每 3 小时**自动刷新一次(= `BUGU_DATA_CACHE_TTL` 的一半,最低 30 分钟)
171
+ - 刷新失败不会清掉旧数据,**10 分钟后重试**,期间照常使用旧缓存
172
+ - 需要立刻同步站点改动时,超管发 `/布谷刷新`
146
173
 
147
174
  ## 常见问题
148
175
 
@@ -153,8 +180,8 @@ nonebot.load_plugin("nonebot_plugin_bugu")
153
180
 
154
181
  **Q:会不会被站点限流?**
155
182
 
156
- 四个接口都是按需拉取并缓存 6 小时,图片按 URL 缓存 30 天,正常使用打不了几发请求。
157
- 遇到 429 会提示「请求太频繁」,等一会儿再试。
183
+ 四个接口每 3 小时才拉一次(后台预热),图片按 URL 缓存 30 天,正常使用打不了几发请求。
184
+ 遇到 429 会提示「请求太频繁」,后台刷新会自动退避重试,旧缓存继续可用。
158
185
 
159
186
  ## 开发
160
187
 
@@ -172,7 +199,7 @@ nonebot_plugin_bugu/
172
199
  ├── config.py # 配置项
173
200
  ├── api.py # 四个接口的客户端 + 内存 / 磁盘缓存
174
201
  ├── values.py # 字段兜底与通用小工具
175
- ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚
202
+ ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚、分页卡片
176
203
  ├── fonts.py # 中文字体探测
177
204
  ├── runtime.py # 单例:客户端 / 字体 / 进度
178
205
  ├── commands.py # 命令注册与分发
@@ -28,3 +28,7 @@ __plugin_meta__ = PluginMetadata(
28
28
  require("nonebot_plugin_localstore")
29
29
 
30
30
  from . import commands as commands # noqa: E402,F401
31
+ from .warmup import setup as setup_warmup # noqa: E402
32
+
33
+ # 后台定时预热(常开):启动先刷一遍,之后按缓存 TTL 的一半循环刷新
34
+ setup_warmup()
@@ -91,11 +91,13 @@ def help_text() -> str:
91
91
  "",
92
92
  "【星海地图】",
93
93
  f" {start}星海 <词> 智能识别区域 / 点位 / 物种",
94
+ f" {start}星海 列表 [大类] [页码] 物种图鉴(出图)",
94
95
  f" {start}星海地图 [区域] 区域地图卡片",
95
- f" {start}星海点位 <点位名> 点位详情",
96
+ f" {start}星海点位 [区域 / 点位名] 区域点位清单 / 点位详情",
96
97
  f" {start}星海查 <物种 / 大类> 跨区域搜索",
97
98
  "",
98
99
  "【菜谱】",
100
+ f" {start}菜谱 列表 [类型 / 厨具 / 词] [页码] 翻目录(出图)",
99
101
  f" {start}菜谱 <菜名 / 编号> 菜谱卡片",
100
102
  f" {start}菜谱查 <食材 / 类型 / 厨具> 搜索筛选",
101
103
  f" {start}菜谱 随机 随手看一道",
@@ -353,6 +353,16 @@ def encode(image: Image.Image) -> bytes:
353
353
  return buffer.getvalue()
354
354
 
355
355
 
356
+ def flatten(content: Image.Image, width: int) -> bytes:
357
+ """把透明内容层贴到渐变底上并编码(目录类卡片没有额外页脚时用)。"""
358
+ bbox = content.getbbox()
359
+ height = bbox[3] if bbox else 1
360
+ height = max(1, min(height, content.height))
361
+ canvas = background(width, height)
362
+ canvas.alpha_composite(content.crop((0, 0, width, height)))
363
+ return encode(canvas)
364
+
365
+
356
366
  def finish(
357
367
  content: Image.Image,
358
368
  width: int,
@@ -3,8 +3,9 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
+ import math
6
7
  from dataclasses import dataclass
7
- from typing import Callable, Optional, Union
8
+ from typing import Callable, List, Optional, Sequence, Tuple, Union
8
9
 
9
10
  import nonebot
10
11
  from nonebot.log import logger
@@ -67,3 +68,34 @@ async def render_card(
67
68
  except Exception:
68
69
  logger.opt(exception=True).error(f"{label}渲染异常")
69
70
  return None
71
+
72
+
73
+ # ------------------------------------------------------------------ 分页
74
+
75
+
76
+ def paginate(
77
+ items: Sequence,
78
+ page: int,
79
+ per_page: int = 15,
80
+ ) -> Tuple[List, int, int]:
81
+ """按页切片,返回 ``(当前页内容, 实际页码, 总页数)``。"""
82
+ total_pages = max(1, math.ceil(len(items) / max(1, per_page)))
83
+ page = min(max(1, int(page or 1)), total_pages)
84
+ start = (page - 1) * per_page
85
+ return list(items[start : start + per_page]), page, total_pages
86
+
87
+
88
+ def split_page(tokens: Sequence[str]) -> Tuple[List[str], int]:
89
+ """最后一个纯数字 token 当作页码:``["简单", "2"]`` → ``(["简单"], 2)``。"""
90
+ items = [token for token in tokens if token]
91
+ if items and items[-1].isdigit():
92
+ return items[:-1], int(items[-1])
93
+ return items, 1
94
+
95
+
96
+ def page_footer(current: int, total: int, command: str, spec: str = "") -> str:
97
+ """分页页脚:告诉用户怎么翻页 / 看详情。"""
98
+ suffix = f" {spec}" if spec else ""
99
+ if current < total:
100
+ return usage(f"{command}{suffix} {current + 1} 看下一页")
101
+ return usage(f"{command}{suffix} 1 回到第一页")
@@ -6,7 +6,8 @@
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
- from typing import Dict, List, Optional, Tuple
9
+ import math
10
+ from typing import Dict, List, Optional, Sequence, Tuple
10
11
 
11
12
  from ...draw import (
12
13
  BG_BOTTOM,
@@ -23,12 +24,14 @@ from ...draw import (
23
24
  draw_paragraph,
24
25
  finish,
25
26
  fit_text,
27
+ flatten,
26
28
  icon_disc,
27
29
  open_image,
28
30
  require_pillow,
29
31
  resize,
30
32
  resolve_fontset,
31
33
  text_width,
34
+ wrap_text,
32
35
  )
33
36
  from ...fonts import FontSet
34
37
  from ...values import grade_text
@@ -353,3 +356,129 @@ def render_recipe_card(
353
356
 
354
357
  right = f"#{recipe.number_text}" + (f" · {recipe.type}" if recipe.type else "")
355
358
  return finish(content, width, fonts=font_set, pad=pad, right_text=right)
359
+
360
+
361
+ # ------------------------------------------------------------------ 目录卡片
362
+
363
+
364
+ def render_recipe_catalog(
365
+ book: RecipeBook,
366
+ recipes: Sequence[Recipe],
367
+ images: Dict[str, Optional[bytes]],
368
+ *,
369
+ page: int = 1,
370
+ total_pages: int = 1,
371
+ total_items: Optional[int] = None,
372
+ spec: str = "",
373
+ fonts: Optional[FontSet] = None,
374
+ width: int = 1200,
375
+ columns: int = 5,
376
+ ) -> bytes:
377
+ """菜谱目录:一页若干道菜,带菜图、编号、名称和类型。
378
+
379
+ 不知道菜名的人可以一页页翻,也可以按类型 / 厨具 / 关键词过滤后再翻。
380
+ """
381
+ require_pillow()
382
+ font_set = resolve_fontset(fonts)
383
+
384
+ from PIL import Image, ImageDraw
385
+
386
+ pad = 40
387
+ gap = 16
388
+ cell_w = (width - pad * 2 - gap * (columns - 1)) // columns
389
+ art = cell_w - 12
390
+ cell_h = art + 92
391
+ rows = max(1, math.ceil(max(1, len(recipes)) / columns))
392
+
393
+ estimate = pad + 76 + rows * (cell_h + 16) + 90
394
+ content = Image.new("RGBA", (width, estimate), (0, 0, 0, 0))
395
+ draw = ImageDraw.Draw(content)
396
+
397
+ title_font = font_set.get(36, True)
398
+ title = "菜谱目录" + (f" · {spec}" if spec else "")
399
+ bold_text(draw, (pad, pad), fit_text(draw, title, title_font, width - pad * 2 - 260), title_font, font_set)
400
+ page_text = f"共 {total_items if total_items is not None else len(recipes)} 道 · 第 {page}/{total_pages} 页"
401
+ draw.text((width - pad, pad + 14), page_text, font=font_set.get(17), fill=DIM, anchor="rt")
402
+
403
+ top = pad + 66
404
+ for index, recipe in enumerate(recipes):
405
+ row, col = divmod(index, columns)
406
+ x = pad + col * (cell_w + gap)
407
+ y = top + row * (cell_h + 16)
408
+ _draw_catalog_cell(content, draw, recipe, images, x, y, cell_w, art, font_set)
409
+
410
+ footer_y = top + rows * (cell_h + 16) + 10
411
+ draw.line([(pad, footer_y), (width - pad, footer_y)], fill=LINE, width=1)
412
+ footer_hint = (
413
+ f"下一页:/菜谱 列表 {spec + ' ' if spec else ''}{page + 1}"
414
+ if page < total_pages
415
+ else "已到最后一页"
416
+ )
417
+ draw.text((pad, footer_y + 14), "数据来源:布谷工具箱 · bugu.nsun200512.cc", font=font_set.get(15), fill=FAINT)
418
+ draw.text((width - pad, footer_y + 14), footer_hint, font=font_set.get(15), fill=FAINT, anchor="rt")
419
+ return flatten(content, width)
420
+
421
+
422
+ def _draw_catalog_cell(
423
+ canvas,
424
+ draw: Draw,
425
+ recipe: Recipe,
426
+ images: Dict[str, Optional[bytes]],
427
+ x: int,
428
+ y: int,
429
+ cell_w: int,
430
+ art: int,
431
+ fonts: FontSet,
432
+ ) -> None:
433
+ quality = hex_to_rgb(recipe.panel_color, (156, 194, 194))
434
+ draw.rounded_rectangle(
435
+ [x, y, x + cell_w, y + art],
436
+ 14,
437
+ fill=mix(quality, BG_BOTTOM, 0.80),
438
+ outline=quality,
439
+ width=2,
440
+ )
441
+ dish = open_image(images.get(recipe.dish) if recipe.dish else None, "菜品图")
442
+ if dish is not None:
443
+ box = art - 26
444
+ scale = min(box / dish.width, box / dish.height)
445
+ dish = resize(dish, (max(1, round(dish.width * scale)), max(1, round(dish.height * scale))))
446
+ canvas.alpha_composite(dish, (x + (cell_w - dish.width) // 2, y + (art - dish.height) // 2))
447
+ else:
448
+ draw.text(
449
+ (x + cell_w / 2, y + art / 2),
450
+ "???" if recipe.incomplete else "菜",
451
+ font=fonts.get(30, True),
452
+ fill=DIM,
453
+ anchor="mm",
454
+ )
455
+
456
+ # 编号 + 品质角标
457
+ draw.rounded_rectangle([x + 8, y + 8, x + 62, y + 34], 13, fill=(18, 24, 50))
458
+ draw.text((x + 35, y + 21), f"#{recipe.number_text}", font=fonts.get(14), fill=CREAM, anchor="mm")
459
+ if recipe.quality:
460
+ color = hex_to_rgb(recipe.panel_color, (156, 194, 194))
461
+ draw.ellipse([x + cell_w - 34, y + 8, x + cell_w - 8, y + 34], fill=color)
462
+ draw.text(
463
+ (x + cell_w - 21, y + 21), recipe.quality, font=fonts.get(15, True), fill=(33, 32, 26), anchor="mm"
464
+ )
465
+
466
+ # 名称
467
+ name_font = fonts.get(18, True)
468
+ lines = wrap_text(draw, recipe.display_name, name_font, cell_w - 8, max_lines=2)
469
+ for i, line in enumerate(lines):
470
+ draw.text(
471
+ (x + cell_w / 2, y + art + 12 + i * 24), line, font=name_font, fill=CREAM, anchor="mt"
472
+ )
473
+
474
+ # 类型 / 厨具
475
+ meta = [recipe.type or "未分类"]
476
+ if recipe.kitchen is not None and recipe.kitchen.specified:
477
+ meta.append(recipe.kitchen.name)
478
+ draw.text(
479
+ (x + cell_w / 2, y + art + 14 + len(lines) * 24),
480
+ fit_text(draw, " · ".join(meta), fonts.get(14), cell_w - 8),
481
+ font=fonts.get(14),
482
+ fill=DIM,
483
+ anchor="mt",
484
+ )
@@ -3,12 +3,13 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import random
6
+ from difflib import get_close_matches
6
7
  from typing import Dict, List, Sequence, Set, Tuple
7
8
 
8
9
  from ...values import grade_text
9
- from ..common import Reply, ReplyEnv, render_card, usage
10
+ from ..common import Reply, ReplyEnv, page_footer, paginate, render_card, split_page, usage
10
11
  from .data import Recipe, RecipeBook
11
- from .render import render_recipe_card
12
+ from .render import render_recipe_card, render_recipe_catalog
12
13
  from .search import (
13
14
  FILTER_LABELS,
14
15
  RecipeHit,
@@ -32,10 +33,11 @@ def stats_text(book: RecipeBook) -> str:
32
33
  lines.append("按厨具:" + "、".join(f"{o.value} {o.count}" for o in kitchen_options))
33
34
  lines.append("")
34
35
  lines.append(usage(
36
+ "菜谱 列表 [类型 / 厨具 / 关键词] [页码] —— 翻目录,不知道菜名也能挑",
35
37
  "菜谱 <菜名 / 编号> —— 查看菜谱卡片",
36
38
  "菜谱查 <食材 / 菜名 / 类型 / 厨具> —— 搜索与筛选",
37
- "菜谱 随机 —— 随机看一道",
38
- "例:菜谱 炒鲜蔬 / 菜谱 12 / 菜谱查 苹果 / 菜谱查 煮锅 苹果",
39
+ "菜谱 随机 [条件] —— 随机看一道",
40
+ "例:菜谱 列表 简单 / 菜谱 炒鲜蔬 / 菜谱查 煮锅 苹果",
39
41
  ))
40
42
  return "\n".join(lines)
41
43
 
@@ -131,6 +133,78 @@ def list_text(
131
133
  return "\n".join(lines)
132
134
 
133
135
 
136
+ CATALOG_WORDS = ("列表", "目录", "浏览", "全部")
137
+ RANDOM_WORDS = ("随机", "随便", "来一个", "random")
138
+
139
+
140
+ def suggest_recipes(book: RecipeBook, text: str, limit: int = 5) -> List[str]:
141
+ """没找到时给几个相近的菜名。"""
142
+ names = [recipe.display_name for recipe in book.recipes]
143
+ return get_close_matches(text, names, n=limit, cutoff=0.4)
144
+
145
+
146
+ def catalog_text(book: RecipeBook, spec: str = "", page: int = 1, per_page: int = 15) -> str:
147
+ """分页目录:不知道菜名也能一页页翻,或按类型 / 厨具 / 关键词过滤。"""
148
+ spec = (spec or "").strip()
149
+ if spec:
150
+ hits, _ = search(book, spec)
151
+ pool = [hit.recipe for hit in hits]
152
+ title = f"菜谱列表 · {spec}"
153
+ else:
154
+ pool = list(book.recipes)
155
+ title = "菜谱列表"
156
+
157
+ if not pool:
158
+ suggestions = suggest_recipes(book, spec)
159
+ lines = [f"没找到和「{spec}」有关的菜谱。"]
160
+ if suggestions:
161
+ lines.append("是不是在找:" + "、".join(suggestions))
162
+ lines.append(usage("菜谱 列表 简单 看看有什么"))
163
+ return "\n".join(lines)
164
+
165
+ items, page, total = paginate(pool, page, per_page)
166
+ lines = [f"{title} · 共 {len(pool)} 道(第 {page}/{total} 页)", ""]
167
+ for recipe in items:
168
+ tags = [recipe.type or "未分类"]
169
+ if recipe.quality:
170
+ tags.append(recipe.quality)
171
+ if recipe.kitchen is not None and recipe.kitchen.specified:
172
+ tags.append(recipe.kitchen.name)
173
+ lines.append(f"#{recipe.number_text} {recipe.display_name} · " + " · ".join(tags))
174
+ lines.append("")
175
+ lines.append(page_footer(page, total, "菜谱 列表", spec))
176
+ return "\n".join(lines)
177
+
178
+
179
+ async def catalog_reply(book: RecipeBook, spec: str, page: int, env: ReplyEnv) -> Reply:
180
+ """菜谱目录的分页卡片(图片版,失败退回文字)。"""
181
+ spec = (spec or "").strip()
182
+ if spec:
183
+ hits, _ = search(book, spec)
184
+ pool = [hit.recipe for hit in hits]
185
+ else:
186
+ pool = list(book.recipes)
187
+ if not pool:
188
+ return catalog_text(book, spec, page)
189
+ items, page, total = paginate(pool, page, 15)
190
+ png = None
191
+ if env.can_render:
192
+ images = await env.client.get_images([recipe.dish for recipe in items if recipe.dish])
193
+ png = await render_card(
194
+ render_recipe_catalog,
195
+ book,
196
+ items,
197
+ images,
198
+ page=page,
199
+ total_pages=total,
200
+ total_items=len(pool),
201
+ spec=spec,
202
+ fonts=env.fonts,
203
+ label="菜谱目录卡片",
204
+ )
205
+ return png if png is not None else catalog_text(book, spec, page)
206
+
207
+
134
208
  def filter_text(book: RecipeBook, key: str, value: str, limit: int = 30) -> str:
135
209
  recipes = list_by_filter(book, key, value)
136
210
  label = FILTER_LABELS.get(key, key)
@@ -173,8 +247,19 @@ async def reply_recipes(arg: str, env: ReplyEnv) -> Reply:
173
247
  arg = (arg or "").strip()
174
248
  if not arg:
175
249
  return stats_text(book)
176
- if arg in {"随机", "随便", "来一个", "random"}:
177
- return await _recipe_reply(book, random.choice(book.recipes), env)
250
+
251
+ catalog_word = next((word for word in CATALOG_WORDS if arg.startswith(word)), "")
252
+ if catalog_word:
253
+ tokens, page = split_page(arg[len(catalog_word) :].split())
254
+ return await catalog_reply(book, " ".join(tokens), page, env)
255
+
256
+ random_word = next((word for word in RANDOM_WORDS if arg.startswith(word)), "")
257
+ if random_word:
258
+ spec = arg[len(random_word) :].strip()
259
+ pool = [hit.recipe for hit in search(book, spec)[0]] if spec else list(book.recipes)
260
+ if not pool:
261
+ return f"没找到符合「{spec}」的菜谱,换个条件试试。"
262
+ return await _recipe_reply(book, random.choice(pool), env)
178
263
 
179
264
  exact = book.find_exact(arg)
180
265
  if exact is not None:
@@ -189,6 +274,13 @@ async def reply_recipes(arg: str, env: ReplyEnv) -> Reply:
189
274
  hits, _ = search(book, arg)
190
275
  if len(hits) == 1:
191
276
  return await _recipe_reply(book, hits[0].recipe, env)
277
+ if not hits:
278
+ suggestions = suggest_recipes(book, arg)
279
+ lines = [f"没找到和「{arg}」有关的菜谱。"]
280
+ if suggestions:
281
+ lines.append("是不是在找:" + "、".join(suggestions))
282
+ lines.append(usage("菜谱 列表 简单 翻翻目录"))
283
+ return "\n".join(lines)
192
284
  return list_text(book, hits, arg, limit=env.config.bugu_search_limit)
193
285
 
194
286
 
@@ -206,8 +298,13 @@ async def reply_search(arg: str, env: ReplyEnv) -> Reply:
206
298
  hits, parsed = search(book, arg)
207
299
  if len(hits) == 1:
208
300
  return await _recipe_reply(book, hits[0].recipe, env)
209
- if not hits and parsed.is_empty:
210
- return f"没找到「{arg}」。试试菜名、编号、食材(苹果 / 海鲜),或者类型(简单 / 招牌 / 宴客 / 秘制)。"
301
+ if not hits:
302
+ suggestions = suggest_recipes(book, arg)
303
+ lines = [f"没找到和「{arg}」有关的菜谱。"]
304
+ if suggestions:
305
+ lines.append("是不是在找:" + "、".join(suggestions))
306
+ lines.append("可以按食材查(苹果 / 海鲜),或者按类型翻目录(菜谱 列表 简单)。")
307
+ return "\n".join(lines)
211
308
  return list_text(book, hits, arg, limit=env.config.bugu_search_limit)
212
309
 
213
310