nonebot-plugin-bugu 0.2.1__tar.gz → 0.3.0__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 (34) hide show
  1. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/PKG-INFO +3 -33
  2. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/README.md +1 -31
  3. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/__init__.py +2 -3
  4. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/commands.py +5 -21
  5. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/config.py +0 -4
  6. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/draw.py +0 -25
  7. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/common.py +1 -32
  8. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/flowers/data.py +0 -3
  9. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/flowers/render.py +0 -8
  10. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/flowers/reply.py +0 -2
  11. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/neighbors/render.py +0 -1
  12. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/recipes/render.py +0 -16
  13. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/recipes/reply.py +0 -2
  14. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/starsea/render.py +5 -24
  15. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/starsea/reply.py +8 -33
  16. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/runtime.py +5 -35
  17. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/pyproject.toml +2 -2
  18. nonebot_plugin_bugu-0.2.1/nonebot_plugin_bugu/collection.py +0 -166
  19. nonebot_plugin_bugu-0.2.1/nonebot_plugin_bugu/features/collection.py +0 -247
  20. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/LICENSE +0 -0
  21. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/api.py +0 -0
  22. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/__init__.py +0 -0
  23. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/flowers/__init__.py +0 -0
  24. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/neighbors/__init__.py +0 -0
  25. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/neighbors/data.py +0 -0
  26. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/neighbors/reply.py +0 -0
  27. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/recipes/__init__.py +0 -0
  28. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/recipes/data.py +0 -0
  29. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/recipes/search.py +0 -0
  30. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/starsea/__init__.py +0 -0
  31. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/starsea/data.py +0 -0
  32. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/features/starsea/search.py +0 -0
  33. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/fonts.py +0 -0
  34. {nonebot_plugin_bugu-0.2.1 → nonebot_plugin_bugu-0.3.0}/nonebot_plugin_bugu/values.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-bugu
3
- Version: 0.2.1
4
- Summary: 布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘、鲜花培育与收集进度
3
+ Version: 0.3.0
4
+ Summary: 布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘与鲜花培育
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
7
7
  Keywords: nonebot,nonebot2,onebot,bugu,starsea,recipe,星布谷地,星海地图,菜谱
@@ -41,7 +41,6 @@ Description-Content-Type: text/markdown
41
41
  | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;还能按物种反查「在哪几个岛」 |
42
42
  | 🧑‍🤝‍🧑 **友邻备忘** | 10 位友邻的立绘、资料、介绍和喜爱 / 好感 / 反感 / 关于词条与友邻能力 |
43
43
  | 🌷 **鲜花培育** | 13 个品种 87 种花色的杂交配方表 + 花色图鉴(品质、颜色、产地) |
44
- | ✅ **收集进度** | 按 QQ 号记录已收集的物种 / 鲜花 / 菜谱,卡片上直接打勾,进度只存在本机 |
45
44
 
46
45
  ![区域地图](docs/map-card.png)
47
46
 
@@ -99,7 +98,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
99
98
  | `BUGU_FONT_INDEX` | `0` | 字体索引(`.ttc` 集合文件用) |
100
99
  | `BUGU_BOLD_FONT_PATH` | `(空)` | 粗体字体路径,留空用常规体加描边模拟 |
101
100
  | `BUGU_BOLD_FONT_INDEX` | `0` | 粗体字体索引 |
102
- | `BUGU_COLLECTION_PATH` | `(空)` | 收集进度文件路径,留空用 localstore 的 data 目录 |
103
101
 
104
102
  ### 关于字体
105
103
 
@@ -127,7 +125,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
127
125
  | `/星海查 <物种 / 大类>` | 所有人 | 跨区域搜索 |
128
126
  | `/友邻 [名字] [分区]` | 所有人 | 友邻名单 / 档案卡;分区可填 喜爱 / 好感 / 反感 / 关于 / 介绍 |
129
127
  | `/鲜花 [品种 / 花名]` | 所有人 | 品种列表 / 培育配方卡 / 单朵花详情 |
130
- | `/收藏 [名字 / 类型]` | 所有人 | 标记收集进度 |
131
128
  | `/布谷刷新` | 超级用户 | 强制刷新四个模块的数据并清空图片缓存 |
132
129
 
133
130
  ### 菜谱搜索
@@ -166,26 +163,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
166
163
  /鲜花 黄百合 → 单朵花:品质、颜色、产地、由谁培育、能培育出什么
167
164
  ```
168
165
 
169
- ## 收集进度
170
-
171
- 站点自己的「我已获得 / 我已解锁」要邮箱 + 密码登录才能同步。
172
- **在 bot 里保存用户的站点密码是不合适的**,所以插件做了一份本机进度:
173
-
174
- - 按 QQ 号分开,存在 `localstore` 的 data 目录(`collection.json`)
175
- - 三类进度互不影响:星海物种、鲜花、菜谱
176
- - 标记后,点位卡片 / 鲜花卡片 / 菜谱卡片上会直接出现绿勾或「已解锁」
177
- - 同名条目跨图鉴时(例如「紫罗兰」既是星海物种又是鲜花)会提示按类型再发一次:
178
-
179
- ```
180
- /收藏 疆星步甲 → 切换星海物种
181
- /收藏 鲜花 紫罗兰 → 指明类型
182
- /收藏 星海 → 每个点位的收集进度
183
- /收藏 鲜花 / 菜谱 → 分类进度
184
- /收藏 清空 → 清空自己的进度
185
- ```
186
-
187
- > 如果以后站点开放了 token 形式的公开进度接口,可以再考虑和站点账号打通。
188
-
189
166
  ## 数据来源
190
167
 
191
168
  - 站点:<https://bugu.nsun200512.cc>
@@ -207,11 +184,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
207
184
  四个接口都是按需拉取并缓存 6 小时,图片按 URL 缓存 30 天,正常使用打不了几发请求。
208
185
  遇到 429 会提示「请求太频繁」,等一会儿再试。
209
186
 
210
- **Q:为什么收集进度不能和网页同步?**
211
-
212
- 网页同步依赖账号密码,插件不保存用户密码。需要的只是「我收集了哪些」,
213
- 本机记录已经够用,也不会因为换 bot 环境而泄露账号。
214
-
215
187
  ## 开发
216
188
 
217
189
  ```bash
@@ -230,7 +202,6 @@ nonebot_plugin_bugu/
230
202
  ├── values.py # 字段兜底与通用小工具
231
203
  ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚
232
204
  ├── fonts.py # 中文字体探测
233
- ├── collection.py # 收集进度存储(按 QQ 号)
234
205
  ├── runtime.py # 单例:客户端 / 字体 / 进度
235
206
  ├── commands.py # 命令注册与分发
236
207
  └── features/
@@ -238,8 +209,7 @@ nonebot_plugin_bugu/
238
209
  ├── starsea/ # data / search / render / reply
239
210
  ├── recipes/ # data / search / render / reply
240
211
  ├── neighbors/ # data / render / reply
241
- ├── flowers/ # data / render / reply
242
- └── collection.py # 收藏命令逻辑
212
+ └── flowers/ # data / render / reply
243
213
  ```
244
214
 
245
215
  ## 许可证
@@ -13,7 +13,6 @@
13
13
  | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;还能按物种反查「在哪几个岛」 |
14
14
  | 🧑‍🤝‍🧑 **友邻备忘** | 10 位友邻的立绘、资料、介绍和喜爱 / 好感 / 反感 / 关于词条与友邻能力 |
15
15
  | 🌷 **鲜花培育** | 13 个品种 87 种花色的杂交配方表 + 花色图鉴(品质、颜色、产地) |
16
- | ✅ **收集进度** | 按 QQ 号记录已收集的物种 / 鲜花 / 菜谱,卡片上直接打勾,进度只存在本机 |
17
16
 
18
17
  ![区域地图](docs/map-card.png)
19
18
 
@@ -71,7 +70,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
71
70
  | `BUGU_FONT_INDEX` | `0` | 字体索引(`.ttc` 集合文件用) |
72
71
  | `BUGU_BOLD_FONT_PATH` | `(空)` | 粗体字体路径,留空用常规体加描边模拟 |
73
72
  | `BUGU_BOLD_FONT_INDEX` | `0` | 粗体字体索引 |
74
- | `BUGU_COLLECTION_PATH` | `(空)` | 收集进度文件路径,留空用 localstore 的 data 目录 |
75
73
 
76
74
  ### 关于字体
77
75
 
@@ -99,7 +97,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
99
97
  | `/星海查 <物种 / 大类>` | 所有人 | 跨区域搜索 |
100
98
  | `/友邻 [名字] [分区]` | 所有人 | 友邻名单 / 档案卡;分区可填 喜爱 / 好感 / 反感 / 关于 / 介绍 |
101
99
  | `/鲜花 [品种 / 花名]` | 所有人 | 品种列表 / 培育配方卡 / 单朵花详情 |
102
- | `/收藏 [名字 / 类型]` | 所有人 | 标记收集进度 |
103
100
  | `/布谷刷新` | 超级用户 | 强制刷新四个模块的数据并清空图片缓存 |
104
101
 
105
102
  ### 菜谱搜索
@@ -138,26 +135,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
138
135
  /鲜花 黄百合 → 单朵花:品质、颜色、产地、由谁培育、能培育出什么
139
136
  ```
140
137
 
141
- ## 收集进度
142
-
143
- 站点自己的「我已获得 / 我已解锁」要邮箱 + 密码登录才能同步。
144
- **在 bot 里保存用户的站点密码是不合适的**,所以插件做了一份本机进度:
145
-
146
- - 按 QQ 号分开,存在 `localstore` 的 data 目录(`collection.json`)
147
- - 三类进度互不影响:星海物种、鲜花、菜谱
148
- - 标记后,点位卡片 / 鲜花卡片 / 菜谱卡片上会直接出现绿勾或「已解锁」
149
- - 同名条目跨图鉴时(例如「紫罗兰」既是星海物种又是鲜花)会提示按类型再发一次:
150
-
151
- ```
152
- /收藏 疆星步甲 → 切换星海物种
153
- /收藏 鲜花 紫罗兰 → 指明类型
154
- /收藏 星海 → 每个点位的收集进度
155
- /收藏 鲜花 / 菜谱 → 分类进度
156
- /收藏 清空 → 清空自己的进度
157
- ```
158
-
159
- > 如果以后站点开放了 token 形式的公开进度接口,可以再考虑和站点账号打通。
160
-
161
138
  ## 数据来源
162
139
 
163
140
  - 站点:<https://bugu.nsun200512.cc>
@@ -179,11 +156,6 @@ nonebot.load_plugin("nonebot_plugin_bugu")
179
156
  四个接口都是按需拉取并缓存 6 小时,图片按 URL 缓存 30 天,正常使用打不了几发请求。
180
157
  遇到 429 会提示「请求太频繁」,等一会儿再试。
181
158
 
182
- **Q:为什么收集进度不能和网页同步?**
183
-
184
- 网页同步依赖账号密码,插件不保存用户密码。需要的只是「我收集了哪些」,
185
- 本机记录已经够用,也不会因为换 bot 环境而泄露账号。
186
-
187
159
  ## 开发
188
160
 
189
161
  ```bash
@@ -202,7 +174,6 @@ nonebot_plugin_bugu/
202
174
  ├── values.py # 字段兜底与通用小工具
203
175
  ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚
204
176
  ├── fonts.py # 中文字体探测
205
- ├── collection.py # 收集进度存储(按 QQ 号)
206
177
  ├── runtime.py # 单例:客户端 / 字体 / 进度
207
178
  ├── commands.py # 命令注册与分发
208
179
  └── features/
@@ -210,8 +181,7 @@ nonebot_plugin_bugu/
210
181
  ├── starsea/ # data / search / render / reply
211
182
  ├── recipes/ # data / search / render / reply
212
183
  ├── neighbors/ # data / render / reply
213
- ├── flowers/ # data / render / reply
214
- └── collection.py # 收藏命令逻辑
184
+ └── flowers/ # data / render / reply
215
185
  ```
216
186
 
217
187
  ## 许可证
@@ -8,8 +8,8 @@ from .config import Config
8
8
  __plugin_meta__ = PluginMetadata(
9
9
  name="布谷工具箱",
10
10
  description=(
11
- "星布谷地小助手:菜谱查询、星海地图、友邻备忘、鲜花培育,"
12
- "外加按 QQ 号记录的收集进度。数据来自布谷工具箱"
11
+ "星布谷地小助手:菜谱查询、星海地图、友邻备忘、鲜花培育。"
12
+ "数据来自布谷工具箱"
13
13
  ),
14
14
  usage=(
15
15
  "/布谷 —— 查看全部指令\n"
@@ -17,7 +17,6 @@ __plugin_meta__ = PluginMetadata(
17
17
  "/星海 <词> —— 星海智能查询;/星海地图 / /星海点位 / /星海查\n"
18
18
  "/友邻 [名字] [喜爱/好感/反感/关于] —— 友邻档案\n"
19
19
  "/鲜花 [品种 / 花名] —— 培育配方与花色\n"
20
- "/收藏 [名字] —— 标记收集进度\n"
21
20
  "/布谷刷新 —— 超管:刷新数据并清空图片缓存"
22
21
  ),
23
22
  type="application",
@@ -16,14 +16,13 @@ from nonebot.params import CommandArg
16
16
  from nonebot.permission import SUPERUSER
17
17
 
18
18
  from .api import BuguError
19
- from .features import collection as collection_feature
20
19
  from .features.common import Reply, ReplyEnv, command_start
21
20
  from .features.flowers import reply as flower_feature
22
21
  from .features.neighbors import reply as neighbor_feature
23
22
  from .features.recipes import reply as recipe_feature
24
23
  from .features.starsea import reply as starsea_feature
25
24
  from .fonts import FontError, FontSet
26
- from .runtime import get_client, get_config, get_fonts, get_store
25
+ from .runtime import get_client, get_config, get_fonts
27
26
 
28
27
  PRIORITY = 12
29
28
 
@@ -38,7 +37,6 @@ recipe = on_command("菜谱", priority=PRIORITY, block=True)
38
37
  recipe_search = on_command("菜谱查", aliases={"菜谱搜索"}, priority=PRIORITY, block=True)
39
38
  neighbor = on_command("友邻", aliases={"友邻备忘"}, priority=PRIORITY, block=True)
40
39
  flower = on_command("鲜花", aliases={"花谱", "鲜花培育"}, priority=PRIORITY, block=True)
41
- collection = on_command("收藏", aliases={"布谷收藏"}, priority=PRIORITY, block=True)
42
40
  refresh = on_command("布谷刷新", priority=PRIORITY, block=True, permission=SUPERUSER)
43
41
 
44
42
 
@@ -66,18 +64,16 @@ class Cooldown:
66
64
  _cooldown = Cooldown()
67
65
 
68
66
 
69
- def _env(event: Optional[MessageEvent]) -> ReplyEnv:
67
+ def _env() -> ReplyEnv:
70
68
  config = get_config()
71
69
  client = get_client(config)
72
- store = get_store(config)
73
70
  fonts: Optional[FontSet] = None
74
71
  if config.bugu_image_enabled:
75
72
  try:
76
73
  fonts = get_fonts(config)
77
74
  except FontError as exc:
78
75
  logger.warning(f"布谷工具箱没有可用字体,改为纯文字:{exc}")
79
- user_id = event.get_user_id() if event is not None else ""
80
- return ReplyEnv(client=client, config=config, fonts=fonts, user_id=user_id, store=store)
76
+ return ReplyEnv(client=client, config=config, fonts=fonts)
81
77
 
82
78
 
83
79
  def _as_segment(reply: Reply):
@@ -112,11 +108,6 @@ def help_text() -> str:
112
108
  f" {start}鲜花 品种列表",
113
109
  f" {start}鲜花 <品种 / 花名> 杂交配方与花色",
114
110
  "",
115
- "【收集进度】",
116
- f" {start}收藏 总览",
117
- f" {start}收藏 <名字> 标记 / 取消",
118
- f" {start}收藏 星海 / 鲜花 / 菜谱 分类进度",
119
- "",
120
111
  "数据来源:布谷工具箱 bugu.nsun200512.cc",
121
112
  ]
122
113
  )
@@ -134,12 +125,10 @@ async def _run(
134
125
  matcher_name: str,
135
126
  cooldown: bool = True,
136
127
  ) -> None:
137
- env = _env(event)
138
- if env.store is not None:
139
- await env.store.ensure_loaded()
128
+ env = _env()
140
129
 
141
130
  if cooldown and env.config.bugu_cooldown_seconds:
142
- left = _cooldown.remaining(f"{env.user_id}:{matcher_name}", env.config.bugu_cooldown_seconds)
131
+ left = _cooldown.remaining(f"{event.get_user_id()}:{matcher_name}", env.config.bugu_cooldown_seconds)
143
132
  if left > 0:
144
133
  await matcher.finish(f"慢一点,{left:.0f} 秒后再试")
145
134
 
@@ -205,11 +194,6 @@ async def _handle_flower(event: MessageEvent, arg: Message = CommandArg()) -> No
205
194
  await _run(flower, event, arg, flower_feature.reply_flowers, matcher_name="flower")
206
195
 
207
196
 
208
- @collection.handle()
209
- async def _handle_collection(event: MessageEvent, arg: Message = CommandArg()) -> None:
210
- await _run(collection, event, arg, collection_feature.reply_collection, matcher_name="collection", cooldown=False)
211
-
212
-
213
197
  @refresh.handle()
214
198
  async def _handle_refresh() -> None:
215
199
  config = get_config()
@@ -58,10 +58,6 @@ class Config(BaseModel):
58
58
  default=0,
59
59
  description="粗体字体文件内的索引(.ttc 集合文件用)",
60
60
  )
61
- bugu_collection_path: str = Field(
62
- default="",
63
- description="收集进度文件路径,留空用 nonebot-plugin-localstore 的 data 目录",
64
- )
65
61
 
66
62
  @field_validator("bugu_api_base")
67
63
  @classmethod
@@ -38,7 +38,6 @@ BADGE_BLUE = (32, 52, 92)
38
38
  BADGE_BLUE_LINE = (108, 148, 210)
39
39
  TYPE_CHIP_INK = (42, 33, 24)
40
40
  SPECIALTY_BLUE = (59, 130, 196)
41
- GREEN = (76, 175, 98)
42
41
 
43
42
  GRADE_COLORS = {
44
43
  "S": (198, 158, 58),
@@ -314,30 +313,6 @@ def number_badge(
314
313
  draw.text((cx, cy), str(number), font=font, fill=ink, anchor="mm")
315
314
 
316
315
 
317
- def check_mark(
318
- draw: ImageDraw.ImageDraw,
319
- cx: float,
320
- cy: float,
321
- radius: int,
322
- *,
323
- fill=GREEN,
324
- outline=(11, 16, 36),
325
- ) -> None:
326
- """右上角的绿色对勾(收集进度)。"""
327
- draw.ellipse(
328
- [cx - radius, cy - radius, cx + radius, cy + radius],
329
- fill=fill,
330
- outline=outline,
331
- width=2,
332
- )
333
- r = radius * 0.5
334
- draw.line(
335
- [(cx - r * 0.8, cy + r * 0.1), (cx - r * 0.2, cy + r * 0.7), (cx + r, cy - r * 0.68)],
336
- fill=(255, 255, 255),
337
- width=max(2, radius // 5),
338
- )
339
-
340
-
341
316
  def icon_disc(
342
317
  canvas: Image.Image,
343
318
  draw: ImageDraw.ImageDraw,
@@ -4,13 +4,12 @@ from __future__ import annotations
4
4
 
5
5
  import asyncio
6
6
  from dataclasses import dataclass
7
- from typing import Callable, Optional, Set, Union
7
+ from typing import Callable, Optional, Union
8
8
 
9
9
  import nonebot
10
10
  from nonebot.log import logger
11
11
 
12
12
  from ..api import BuguClient
13
- from ..collection import KINDS, CollectionStore
14
13
  from ..config import Config
15
14
  from ..draw import DrawError
16
15
  from ..fonts import FontError, FontSet
@@ -25,36 +24,6 @@ class ReplyEnv:
25
24
  client: BuguClient
26
25
  config: Config
27
26
  fonts: Optional[FontSet]
28
- user_id: str = ""
29
- store: Optional[CollectionStore] = None
30
-
31
- def collected(self, kind: str) -> Set[str]:
32
- """当前用户某一类的收集集合(没有登录态 / 没存过就是空集)。"""
33
- if self.store is None or not self.user_id:
34
- return set()
35
- return self.store.items(self.user_id, kind)
36
-
37
- def collected_ids(self, kind: str) -> Set[int]:
38
- """星海物种 / 菜谱的 key 是数字,这里直接转好。"""
39
- out: Set[int] = set()
40
- for value in self.collected(kind):
41
- try:
42
- out.add(int(value))
43
- except (TypeError, ValueError):
44
- continue
45
- return out
46
-
47
- @property
48
- def collected_totals(self) -> dict:
49
- """各类进度条数(用于「收藏」概览)。"""
50
- if self.store is None or not self.user_id:
51
- return {}
52
- return {kind: len(self.store.items(self.user_id, kind)) for kind in KINDS}
53
-
54
- def is_collected(self, kind: str, key) -> bool:
55
- if self.store is None or not self.user_id:
56
- return False
57
- return self.store.has(self.user_id, kind, key)
58
27
 
59
28
  @property
60
29
  def can_render(self) -> bool:
@@ -110,9 +110,6 @@ class FlowerBook:
110
110
  def is_star_seed(self, species: str) -> bool:
111
111
  return self.area_of(species).startswith("星海花种")
112
112
 
113
- def collected_names(self, species: str) -> List[str]:
114
- return [f.name for f in self.flowers_of(species)]
115
-
116
113
 
117
114
  def parse_flowers(payload: Dict[str, Any], base: str) -> FlowerBook:
118
115
  if not isinstance(payload, dict):
@@ -14,7 +14,6 @@ from ...draw import (
14
14
  YELLOW,
15
15
  Draw,
16
16
  bold_text,
17
- check_mark,
18
17
  chip,
19
18
  finish,
20
19
  fit_text,
@@ -136,8 +135,6 @@ def _draw_tile(
136
135
  cy: float,
137
136
  radius: int,
138
137
  fonts: FontSet,
139
- *,
140
- done: bool = False,
141
138
  ) -> None:
142
139
  icon = open_image(icon_bytes, "鲜花图标")
143
140
  icon_disc(
@@ -163,9 +160,6 @@ def _draw_tile(
163
160
  )
164
161
  draw.text((bx, by), flower.grade, font=fonts.get(13, True), fill=TYPE_CHIP_INK, anchor="mm")
165
162
 
166
- if done:
167
- check_mark(draw, cx + radius * 0.72, cy - radius * 0.72, 11)
168
-
169
163
  font = fonts.get(15)
170
164
  for i, line in enumerate(wrap_text(draw, flower.name, font, radius * 3, max_lines=1)):
171
165
  draw.text((cx, cy + radius + 8 + i * 19), line, font=font, fill=CREAM, anchor="mt")
@@ -193,7 +187,6 @@ def render_flower_card(
193
187
  *,
194
188
  fonts: Optional[FontSet] = None,
195
189
  width: int = 1040,
196
- collected: Optional[set] = None,
197
190
  ) -> bytes:
198
191
  require_pillow()
199
192
  font_set = resolve_fontset(fonts)
@@ -288,7 +281,6 @@ def render_flower_card(
288
281
  cy,
289
282
  38,
290
283
  font_set,
291
- done=bool(collected and flower.name in collected),
292
284
  )
293
285
 
294
286
  return finish(
@@ -4,7 +4,6 @@ from __future__ import annotations
4
4
 
5
5
  from typing import List
6
6
 
7
- from ...collection import KIND_FLOWER
8
7
  from ...values import grade_text
9
8
  from ..common import Reply, ReplyEnv, render_card, usage
10
9
  from .data import Flower, FlowerBook
@@ -89,7 +88,6 @@ async def _species_reply(book: FlowerBook, species: str, env: ReplyEnv) -> Reply
89
88
  species,
90
89
  {name: fetched.get(url) for name, url in url_map.items()},
91
90
  fonts=env.fonts,
92
- collected=env.collected(KIND_FLOWER) or None,
93
91
  label="鲜花培育卡片",
94
92
  )
95
93
  return png if png is not None else species_text(book, species)
@@ -109,7 +109,6 @@ def render_neighbor_card(
109
109
  *,
110
110
  fonts: Optional[FontSet] = None,
111
111
  width: int = 1000,
112
- collected: Optional[set] = None,
113
112
  ) -> bytes:
114
113
  require_pillow()
115
114
  font_set = resolve_fontset(fonts)
@@ -19,7 +19,6 @@ from ...draw import (
19
19
  YELLOW,
20
20
  Draw,
21
21
  bold_text,
22
- chip,
23
22
  chip_row,
24
23
  draw_paragraph,
25
24
  finish,
@@ -142,7 +141,6 @@ def render_recipe_card(
142
141
  *,
143
142
  fonts: Optional[FontSet] = None,
144
143
  width: int = 1000,
145
- unlocked: bool = False,
146
144
  ) -> bytes:
147
145
  require_pillow()
148
146
  font_set = resolve_fontset(fonts)
@@ -183,20 +181,6 @@ def render_recipe_card(
183
181
  anchor="mm",
184
182
  )
185
183
 
186
- if unlocked:
187
- chip(
188
- draw,
189
- pad + 12,
190
- pad + art - 42,
191
- "已解锁",
192
- font_set.get(14, True),
193
- fill=(76, 175, 98),
194
- ink=(255, 255, 255),
195
- pad_x=12,
196
- height=26,
197
- radius=13,
198
- )
199
-
200
184
  avatar = open_image(images.get(recipe.neighbor.icon) if recipe.neighbor else None, "友邻头像")
201
185
  if avatar is not None:
202
186
  cx, cy, r = pad + art - 8, pad + art - 8, 26
@@ -5,7 +5,6 @@ from __future__ import annotations
5
5
  import random
6
6
  from typing import Dict, List, Sequence, Set, Tuple
7
7
 
8
- from ...collection import KIND_RECIPE
9
8
  from ...values import grade_text
10
9
  from ..common import Reply, ReplyEnv, render_card, usage
11
10
  from .data import Recipe, RecipeBook
@@ -161,7 +160,6 @@ async def _recipe_reply(book: RecipeBook, recipe: Recipe, env: ReplyEnv) -> Repl
161
160
  recipe,
162
161
  images,
163
162
  fonts=env.fonts,
164
- unlocked=env.is_collected(KIND_RECIPE, recipe.number),
165
163
  label="菜谱卡片",
166
164
  )
167
165
  return png if png is not None else recipe_text(book, recipe)
@@ -1,14 +1,13 @@
1
1
  """星海地图卡片:区域底图 + 点位详情。
2
2
 
3
3
  两张图都遵循布谷工具箱的深色星空主题,等级沿用站点配色
4
- (S 金 / A 紫 / B 蓝 / C 灰)。传入 ``collected`` 时会在图标上标绿勾、
5
- 在图例里显示收集进度。
4
+ (S 金 / A 紫 / B 蓝 / C 灰)。
6
5
  """
7
6
 
8
7
  from __future__ import annotations
9
8
 
10
9
  import math
11
- from typing import Dict, List, Optional, Sequence, Set, Tuple
10
+ from typing import Dict, List, Optional, Sequence, Tuple
12
11
 
13
12
  from ...draw import (
14
13
  BG_BOTTOM,
@@ -23,7 +22,6 @@ from ...draw import (
23
22
  Draw,
24
23
  DrawError,
25
24
  bold_text,
26
- check_mark,
27
25
  chip,
28
26
  draw_paragraph,
29
27
  finish,
@@ -58,9 +56,7 @@ def _map_kinds(data: StarSeaData, sea_map: SeaMap) -> List[str]:
58
56
  return kinds
59
57
 
60
58
 
61
- def _legend_meta(
62
- data: StarSeaData, point: SeaPoint, collected: Optional[Set[int]]
63
- ) -> str:
59
+ def _legend_meta(data: StarSeaData, point: SeaPoint) -> str:
64
60
  species = data.species_of(point)
65
61
  if not species:
66
62
  return point.type_name or "特殊点位"
@@ -68,11 +64,7 @@ def _legend_meta(
68
64
  for sp in species:
69
65
  if sp.kind_name not in kinds:
70
66
  kinds.append(sp.kind_name)
71
- meta = f"{'/'.join(kinds[:3])} · {len(species)} 种"
72
- if collected:
73
- done = sum(1 for sp in species if sp.id in collected)
74
- meta += f" · 已收 {done}/{len(species)}"
75
- return meta
67
+ return f"{'/'.join(kinds[:3])} · {len(species)} 种"
76
68
 
77
69
 
78
70
  def render_map_card(
@@ -82,7 +74,6 @@ def render_map_card(
82
74
  *,
83
75
  fonts: Optional[FontSet] = None,
84
76
  width: int = 1200,
85
- collected: Optional[Set[int]] = None,
86
77
  ) -> bytes:
87
78
  """渲染区域地图:底图 + 编号点位 + 图例。"""
88
79
  require_pillow()
@@ -175,7 +166,7 @@ def render_map_card(
175
166
  )
176
167
  draw.text(
177
168
  (x + 40, y + 27),
178
- fit_text(draw, _legend_meta(data, point, collected), meta_font, col_w - 52),
169
+ fit_text(draw, _legend_meta(data, point), meta_font, col_w - 52),
179
170
  font=meta_font,
180
171
  fill=DIM,
181
172
  )
@@ -229,7 +220,6 @@ def render_point_card(
229
220
  *,
230
221
  fonts: Optional[FontSet] = None,
231
222
  width: int = 1040,
232
- collected: Optional[Set[int]] = None,
233
223
  ) -> bytes:
234
224
  """渲染点位详情:头图 + 标题 + 按大类分组的图标墙。"""
235
225
  require_pillow()
@@ -299,9 +289,6 @@ def render_point_card(
299
289
  species_total = sum(len(lst) for _, lst, _ in groups)
300
290
  if species_total:
301
291
  meta = f"{species_total} 种可采集物 · {len(groups)} 个大类 · {sea_map.display_name}"
302
- if collected:
303
- done = sum(1 for sp in data.species_of(point) if sp.id in collected)
304
- meta += f" · 已收集 {done}/{species_total}"
305
292
  elif point.is_station and sea_map.encounters:
306
293
  meta = f"{point.type_name or '传送点'} · 本区可初次偶遇 {len(sea_map.encounters)} 位友邻"
307
294
  else:
@@ -347,7 +334,6 @@ def render_point_card(
347
334
  font_set=font_set,
348
335
  name_width=tile_w - 12,
349
336
  flower_state=flower_states.get(species.id),
350
- done=bool(collected and species.id in collected),
351
337
  )
352
338
  cursor += math.ceil(len(species_list) / columns) * tile_h + section_gap
353
339
  elif point.special:
@@ -427,7 +413,6 @@ def _draw_species_tile(
427
413
  font_set: FontSet,
428
414
  name_width: float,
429
415
  flower_state: Optional[int] = None,
430
- done: bool = False,
431
416
  ) -> None:
432
417
  color = grade_color(species.grade)
433
418
  icon = open_image(icon_bytes, species.label or "物种")
@@ -473,10 +458,6 @@ def _draw_species_tile(
473
458
  anchor="mm",
474
459
  )
475
460
 
476
- # 已收集:右上角绿勾
477
- if done:
478
- check_mark(draw, cx + radius * 0.72, cy - radius * 0.72, 12)
479
-
480
461
  # 名字(最多两行)
481
462
  name_font = font_set.get(16)
482
463
  for i, line in enumerate(wrap_text(draw, species.label, name_font, name_width, max_lines=2)):
@@ -2,9 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import List, Optional, Sequence, Tuple
5
+ from typing import List, Sequence, Tuple
6
6
 
7
- from ...collection import KIND_STARSEA
8
7
  from ...values import grade_text
9
8
  from ..common import Reply, ReplyEnv, command_start, render_card, usage
10
9
  from .data import SeaMap, SeaPoint, Species, StarSeaData
@@ -37,18 +36,12 @@ def map_list_text(data: StarSeaData) -> str:
37
36
  return "\n".join(lines)
38
37
 
39
38
 
40
- def map_text(
41
- data: StarSeaData, sea_map: SeaMap, collected: Optional[set] = None
42
- ) -> str:
39
+ def map_text(data: StarSeaData, sea_map: SeaMap) -> str:
43
40
  lines = [f"【{sea_map.display_name}】{sea_map.code} · {len(sea_map.points)} 个点位", ""]
44
41
  for point in sea_map.ordered_points():
45
42
  species = data.species_of(point)
46
43
  type_name = f" · {point.type_name}" if point.type_name else ""
47
- count = f"({len(species)} 种" if species else "("
48
- if species and collected:
49
- done = sum(1 for sp in species if sp.id in collected)
50
- count += f"·已收 {done}/{len(species)}"
51
- count += ")" if species else ""
44
+ count = f"({len(species)} 种)" if species else ""
52
45
  lines.append(f"· {point.name}{type_name}{count}")
53
46
  if sea_map.encounters:
54
47
  lines.append("")
@@ -76,21 +69,12 @@ def species_tag(species: Species) -> str:
76
69
  return f"{species.label}({meta})" if meta else species.label
77
70
 
78
71
 
79
- def point_text(
80
- data: StarSeaData,
81
- sea_map: SeaMap,
82
- point: SeaPoint,
83
- collected: Optional[set] = None,
84
- ) -> str:
72
+ def point_text(data: StarSeaData, sea_map: SeaMap, point: SeaPoint) -> str:
85
73
  groups = data.groups_of(point)
86
74
  species_total = sum(len(lst) for _, lst in groups)
87
75
  head = [f"【{point.name}】{point.type_name or '点位'}"]
88
76
  if groups:
89
- line = f"{sea_map.display_name} · {species_total} 种可采集物 · {len(groups)} 个大类"
90
- if collected:
91
- done = sum(1 for sp in data.species_of(point) if sp.id in collected)
92
- line += f" · 已收集 {done}/{species_total}"
93
- head.append(line)
77
+ head.append(f"{sea_map.display_name} · {species_total} 种可采集物 · {len(groups)} 个大类")
94
78
  elif point.is_station and sea_map.encounters:
95
79
  head.append(f"{point.type_name or '传送点'} · 本区可初次偶遇 {len(sea_map.encounters)} 位友邻")
96
80
  elif point.special:
@@ -199,24 +183,16 @@ def empty_text() -> str:
199
183
 
200
184
 
201
185
  async def _map_reply(data: StarSeaData, sea_map: SeaMap, env: ReplyEnv) -> Reply:
202
- collected = env.collected_ids(KIND_STARSEA)
203
186
  png = None
204
187
  if env.can_render:
205
188
  raw = await env.client.get_image(sea_map.image)
206
189
  png = await render_card(
207
- render_map_card,
208
- data,
209
- sea_map,
210
- raw,
211
- fonts=env.fonts,
212
- collected=collected or None,
213
- label="星海地图卡片",
190
+ render_map_card, data, sea_map, raw, fonts=env.fonts, label="星海地图卡片"
214
191
  )
215
- return png if png is not None else map_text(data, sea_map, collected or None)
192
+ return png if png is not None else map_text(data, sea_map)
216
193
 
217
194
 
218
195
  async def _point_reply(data: StarSeaData, sea_map: SeaMap, point: SeaPoint, env: ReplyEnv) -> Reply:
219
- collected = env.collected_ids(KIND_STARSEA)
220
196
  png = None
221
197
  if env.can_render:
222
198
  species = data.species_of(point)
@@ -231,10 +207,9 @@ async def _point_reply(data: StarSeaData, sea_map: SeaMap, point: SeaPoint, env:
231
207
  images.get(point.header),
232
208
  icons,
233
209
  fonts=env.fonts,
234
- collected=collected or None,
235
210
  label="星海点位卡片",
236
211
  )
237
- return png if png is not None else point_text(data, sea_map, point, collected or None)
212
+ return png if png is not None else point_text(data, sea_map, point)
238
213
 
239
214
 
240
215
  # ------------------------------------------------------------------ 命令
@@ -1,4 +1,4 @@
1
- """运行时单例:HTTP 客户端、字体、收集进度。
1
+ """运行时单例:HTTP 客户端、字体。
2
2
 
3
3
  插件里所有命令都从这里拿,避免每次请求都新建连接池。
4
4
  """
@@ -12,42 +12,25 @@ from typing import Optional
12
12
  from nonebot import get_plugin_config
13
13
 
14
14
  from .api import BuguClient, ImageCache
15
- from .collection import CollectionStore
16
15
  from .config import Config
17
16
  from .fonts import FontSet, resolve_fonts
18
17
 
19
18
  _client: Optional[BuguClient] = None
20
19
  _fonts: Optional[FontSet] = None
21
20
  _fonts_key: Optional[tuple] = None
22
- _store: Optional[CollectionStore] = None
23
21
 
24
22
 
25
23
  def get_config() -> Config:
26
24
  return get_plugin_config(Config)
27
25
 
28
26
 
29
- def _localstore_dir(kind: str) -> Optional[Path]:
27
+ def default_cache_dir() -> Path:
30
28
  try:
31
- from nonebot_plugin_localstore import get_plugin_cache_dir, get_plugin_data_dir
29
+ from nonebot_plugin_localstore import get_plugin_cache_dir
32
30
 
33
- base = get_plugin_data_dir() if kind == "data" else get_plugin_cache_dir()
34
- return base
31
+ return get_plugin_cache_dir() / "images"
35
32
  except Exception: # localstore 没装 / 不在插件上下文中
36
- return None
37
-
38
-
39
- def default_cache_dir() -> Path:
40
- base = _localstore_dir("cache")
41
- if base is not None:
42
- return base / "images"
43
- return Path(tempfile.gettempdir()) / "nonebot-plugin-bugu" / "images"
44
-
45
-
46
- def default_data_dir() -> Path:
47
- base = _localstore_dir("data")
48
- if base is not None:
49
- return base
50
- return Path(tempfile.gettempdir()) / "nonebot-plugin-bugu" / "data"
33
+ return Path(tempfile.gettempdir()) / "nonebot-plugin-bugu" / "images"
51
34
 
52
35
 
53
36
  def get_client(config: Optional[Config] = None) -> BuguClient:
@@ -94,16 +77,3 @@ def reset_fonts() -> None:
94
77
  _fonts = None
95
78
  _fonts_key = None
96
79
 
97
-
98
- def get_store(config: Optional[Config] = None) -> CollectionStore:
99
- global _store
100
- if _store is None:
101
- cfg = config or get_config()
102
- path = Path(cfg.bugu_collection_path) if cfg.bugu_collection_path else default_data_dir() / "collection.json"
103
- _store = CollectionStore(path)
104
- return _store
105
-
106
-
107
- def set_store(store: Optional[CollectionStore]) -> None:
108
- global _store
109
- _store = store
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-bugu"
3
- version = "0.2.1"
4
- description = "布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘、鲜花培育与收集进度"
3
+ version = "0.3.0"
4
+ description = "布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘与鲜花培育"
5
5
  authors = [{ name = "TonyLiangP2010405" }]
6
6
  license = "MIT"
7
7
  readme = "README.md"
@@ -1,166 +0,0 @@
1
- """收集进度(本地)。
2
-
3
- 站点自己的「我已获得 / 我已解锁」进度要邮箱 + 密码登录才能同步。
4
- 在 bot 里保存用户的站点密码是不合适的,所以这里做一份**本机进度**:
5
- 按 QQ 号分开,存在 localstore 的 data 目录里,和站点账号互不影响。
6
-
7
- 进度分三类:
8
-
9
- * ``starsea`` —— 星海物种,key 是物种 id
10
- * ``flower`` —— 鲜花,key 是花名
11
- * ``recipe`` —— 菜谱,key 是菜谱编号
12
- """
13
-
14
- from __future__ import annotations
15
-
16
- import asyncio
17
- import json
18
- from pathlib import Path
19
- from typing import Dict, Optional, Set
20
-
21
- from nonebot.log import logger
22
-
23
- KIND_STARSEA = "starsea"
24
- KIND_FLOWER = "flower"
25
- KIND_RECIPE = "recipe"
26
- KINDS = (KIND_STARSEA, KIND_FLOWER, KIND_RECIPE)
27
-
28
- KIND_LABELS = {
29
- KIND_STARSEA: "星海物种",
30
- KIND_FLOWER: "鲜花",
31
- KIND_RECIPE: "菜谱",
32
- }
33
-
34
-
35
- class CollectionStore:
36
- """按用户保存的收集进度,进程内缓存 + 原子落盘。"""
37
-
38
- def __init__(self, path: Optional[Path]) -> None:
39
- self.path = Path(path) if path is not None else None
40
- self._data: Dict[str, Dict[str, Set[str]]] = {}
41
- self._loaded = False
42
- self._lock: Optional[asyncio.Lock] = None
43
-
44
- # ------------------------------------------------------------ 读写
45
-
46
- def _guard(self) -> asyncio.Lock:
47
- if self._lock is None:
48
- self._lock = asyncio.Lock()
49
- return self._lock
50
-
51
- async def ensure_loaded(self) -> None:
52
- if self._loaded:
53
- return
54
- async with self._guard():
55
- if self._loaded:
56
- return
57
- self._load()
58
- self._loaded = True
59
-
60
- def _load(self) -> None:
61
- if self.path is None or not self.path.exists():
62
- return
63
- try:
64
- raw = json.loads(self.path.read_text(encoding="utf-8"))
65
- except (OSError, ValueError) as exc:
66
- logger.warning(f"布谷收集进度文件读取失败,先当作空进度:{exc}")
67
- return
68
- users = raw.get("users") if isinstance(raw, dict) else None
69
- if not isinstance(users, dict):
70
- return
71
- for user_id, kinds in users.items():
72
- if not isinstance(kinds, dict):
73
- continue
74
- bucket: Dict[str, Set[str]] = {kind: set() for kind in KINDS}
75
- for kind in KINDS:
76
- values = kinds.get(kind)
77
- if isinstance(values, list):
78
- bucket[kind] = {str(value) for value in values}
79
- self._data[str(user_id)] = bucket
80
-
81
- def _serialize(self) -> str:
82
- payload = {
83
- "version": 1,
84
- "users": {
85
- user_id: {kind: sorted(bucket[kind]) for kind in KINDS}
86
- for user_id, bucket in self._data.items()
87
- },
88
- }
89
- return json.dumps(payload, ensure_ascii=False, indent=1)
90
-
91
- def _save(self) -> None:
92
- if self.path is None:
93
- return
94
- try:
95
- self.path.parent.mkdir(parents=True, exist_ok=True)
96
- tmp = self.path.with_suffix(self.path.suffix + ".tmp")
97
- tmp.write_text(self._serialize(), encoding="utf-8")
98
- tmp.replace(self.path)
99
- except OSError as exc:
100
- logger.warning(f"布谷收集进度写入失败(本次仅内存生效):{exc}")
101
-
102
- def _bucket(self, user_id: str, *, create: bool = False) -> Optional[Dict[str, Set[str]]]:
103
- bucket = self._data.get(str(user_id))
104
- if bucket is None and create:
105
- bucket = {kind: set() for kind in KINDS}
106
- self._data[str(user_id)] = bucket
107
- return bucket
108
-
109
- # ------------------------------------------------------------ 查询
110
-
111
- def items(self, user_id: str, kind: str) -> Set[str]:
112
- bucket = self._bucket(user_id)
113
- return set(bucket.get(kind, set())) if bucket else set()
114
-
115
- def has(self, user_id: str, kind: str, key) -> bool:
116
- return str(key) in self.items(user_id, kind)
117
-
118
- def stats(self, user_id: str) -> Dict[str, int]:
119
- return {kind: len(self.items(user_id, kind)) for kind in KINDS}
120
-
121
- def total(self, user_id: str) -> int:
122
- return sum(self.stats(user_id).values())
123
-
124
- # ------------------------------------------------------------ 修改
125
-
126
- async def set(self, user_id: str, kind: str, key, value: bool) -> bool:
127
- await self.ensure_loaded()
128
- async with self._guard():
129
- bucket = self._bucket(user_id, create=True)
130
- assert bucket is not None
131
- if value:
132
- bucket[kind].add(str(key))
133
- else:
134
- bucket[kind].discard(str(key))
135
- self._save()
136
- return value
137
-
138
- async def toggle(self, user_id: str, kind: str, key) -> bool:
139
- """返回切换后的状态(True = 已收集)。"""
140
- await self.ensure_loaded()
141
- async with self._guard():
142
- bucket = self._bucket(user_id, create=True)
143
- assert bucket is not None
144
- text = str(key)
145
- if text in bucket[kind]:
146
- bucket[kind].discard(text)
147
- new_value = False
148
- else:
149
- bucket[kind].add(text)
150
- new_value = True
151
- self._save()
152
- return new_value
153
-
154
- async def clear(self, user_id: str, kind: Optional[str] = None) -> int:
155
- """清空某类(或全部)进度,返回清掉的条数。"""
156
- await self.ensure_loaded()
157
- async with self._guard():
158
- bucket = self._bucket(user_id)
159
- if bucket is None:
160
- return 0
161
- kinds = [kind] if kind in KINDS else list(KINDS)
162
- removed = sum(len(bucket[kind_name]) for kind_name in kinds)
163
- for kind_name in kinds:
164
- bucket[kind_name].clear()
165
- self._save()
166
- return removed
@@ -1,247 +0,0 @@
1
- """收集进度的命令逻辑。
2
-
3
- 三类进度:星海物种 / 鲜花 / 菜谱。进度存在 bot 本地(按 QQ 号),
4
- 和站点账号无关——站点同步要邮箱密码,插件不保存用户密码。
5
- """
6
-
7
- from __future__ import annotations
8
-
9
- from dataclasses import dataclass
10
- from typing import Dict, List, Sequence, Tuple
11
-
12
- from ..collection import KIND_FLOWER, KIND_LABELS, KIND_RECIPE, KIND_STARSEA
13
- from .common import Reply, ReplyEnv, usage
14
-
15
- # 命令里用的类型前缀(比 KIND_LABELS 短,方便手打)
16
- KIND_HINTS = {KIND_STARSEA: "星海", KIND_FLOWER: "鲜花", KIND_RECIPE: "菜谱"}
17
-
18
-
19
- @dataclass
20
- class Candidate:
21
- kind: str
22
- key: str
23
- label: str
24
- detail: str = ""
25
-
26
-
27
- async def _candidates(env: ReplyEnv, text: str, hint: str = "") -> List[Candidate]:
28
- """在三个图鉴里找这个名字,返回所有可能的条目(精确优先)。"""
29
- out: List[Candidate] = []
30
- want_starsea = hint in {"", "星海", "物种", "采集"}
31
- want_flower = hint in {"", "鲜花", "花"}
32
- want_recipe = hint in {"", "菜谱", "料理"}
33
-
34
- if want_starsea:
35
- data = await env.client.get_starsea()
36
- exact = [
37
- sp for sp in data.species.values() if text in (sp.name, sp.display_name)
38
- ] or [sp for sp in data.species.values() if text in sp.label]
39
- for species in exact:
40
- out.append(
41
- Candidate(
42
- KIND_STARSEA,
43
- str(species.id),
44
- species.label,
45
- f"{species.kind_name} · {species.grade or '?'}",
46
- )
47
- )
48
-
49
- if want_flower:
50
- book = await env.client.get_flowers()
51
- exact = [f for f in book.flowers if f.name == text] or [
52
- f for f in book.flowers if text in f.name
53
- ]
54
- for flower in exact:
55
- out.append(
56
- Candidate(
57
- KIND_FLOWER,
58
- flower.name,
59
- flower.name,
60
- f"{flower.species} · {flower.grade or '?'}",
61
- )
62
- )
63
-
64
- if want_recipe:
65
- book = await env.client.get_recipes()
66
- exact = [
67
- r
68
- for r in book.recipes
69
- if text in (r.display_name, r.number_text, str(r.number))
70
- ] or [r for r in book.recipes if text in r.display_name]
71
- for recipe in exact:
72
- out.append(
73
- Candidate(
74
- KIND_RECIPE,
75
- str(recipe.number),
76
- recipe.display_name,
77
- f"#{recipe.number_text}" + (f" · {recipe.type}" if recipe.type else ""),
78
- )
79
- )
80
-
81
- return out
82
-
83
-
84
- async def overview_text(env: ReplyEnv) -> str:
85
- stars = await env.client.get_starsea()
86
- recipes = await env.client.get_recipes()
87
- flowers = await env.client.get_flowers()
88
- totals = env.collected_totals
89
- lines = [
90
- "收藏进度(只存在本机,按 QQ 号区分)",
91
- "",
92
- f"星海物种:{totals.get(KIND_STARSEA, 0)} / {len(stars.species)}",
93
- f"鲜花:{totals.get(KIND_FLOWER, 0)} / {len(flowers.flowers)}",
94
- f"菜谱:{totals.get(KIND_RECIPE, 0)} / {len(recipes.recipes)}",
95
- "",
96
- usage(
97
- "收藏 <名字> —— 标记 / 取消,例如 收藏 疆星步甲",
98
- "收藏 星海 —— 看每个点位的收集进度",
99
- "收藏 鲜花 —— 看每个品种的收集进度",
100
- "收藏 菜谱 —— 看各类菜谱的收集进度",
101
- "收藏 清空 —— 清空自己的进度",
102
- ),
103
- ]
104
- return "\n".join(lines)
105
-
106
-
107
- async def starsea_progress_text(env: ReplyEnv) -> str:
108
- data = await env.client.get_starsea()
109
- collected = env.collected(KIND_STARSEA)
110
- total = len(data.species)
111
- done = sum(1 for sp in data.species.values() if str(sp.id) in collected)
112
- lines = [f"星海收集进度:{done} / {total}(按物种去重)", ""]
113
- for sea_map in data.maps:
114
- distinct: Dict[int, bool] = {}
115
- rows: List[Tuple[str, int, int]] = []
116
- for point in sea_map.ordered_points():
117
- species = data.species_of(point)
118
- if not species:
119
- continue
120
- point_done = 0
121
- for sp in species:
122
- got = str(sp.id) in collected
123
- distinct[sp.id] = distinct.get(sp.id, False) or got
124
- if got:
125
- point_done += 1
126
- if point_done:
127
- rows.append((point.name, point_done, len(species)))
128
- map_done = sum(1 for got in distinct.values() if got)
129
- lines.append(f"【{sea_map.display_name}】已收 {map_done} / {len(distinct)} 种")
130
- for name, point_done, point_total in rows:
131
- lines.append(f"· {name} {point_done}/{point_total}")
132
- if not rows:
133
- lines.append("· (还没记录)")
134
- if done == 0:
135
- lines.append("")
136
- lines.append("还没记录任何物种,发「收藏 <物种名>」试试。")
137
- return "\n".join(lines)
138
-
139
-
140
- async def flower_progress_text(env: ReplyEnv) -> str:
141
- book = await env.client.get_flowers()
142
- collected = env.collected(KIND_FLOWER)
143
- lines = [f"鲜花收集进度:{len(collected)} / {len(book.flowers)}", ""]
144
- for item in book.species:
145
- names = [flower.name for flower in book.flowers_of(item.name)]
146
- done = sum(1 for name in names if name in collected)
147
- lines.append(f"· {item.name} {done}/{len(names)}")
148
- return "\n".join(lines)
149
-
150
-
151
- async def recipe_progress_text(env: ReplyEnv) -> str:
152
- book = await env.client.get_recipes()
153
- collected = env.collected(KIND_RECIPE)
154
- lines = [f"菜谱收集进度:{len(collected)} / {len(book.recipes)}", ""]
155
- by_type: Dict[str, Tuple[int, int]] = {}
156
- for recipe in book.recipes:
157
- key = recipe.type or "未分类"
158
- total, done = by_type.get(key, (0, 0))
159
- by_type[key] = (total + 1, done + (1 if str(recipe.number) in collected else 0))
160
- for key, (total, done) in by_type.items():
161
- lines.append(f"· {key} {done}/{total}")
162
- return "\n".join(lines)
163
-
164
-
165
- def _choice_text(candidates: Sequence[Candidate], text: str) -> str:
166
- kinds = {candidate.kind for candidate in candidates}
167
- if len(kinds) > 1:
168
- lines = [f"「{text}」在多个图鉴里都有,按类型再发一次:"]
169
- for candidate in candidates:
170
- hint = KIND_HINTS.get(candidate.kind, candidate.kind)
171
- label = KIND_LABELS.get(candidate.kind, candidate.kind)
172
- lines.append(f"· 收藏 {hint} {candidate.label}({label} · {candidate.detail})")
173
- return "\n".join(lines)
174
-
175
- label = KIND_LABELS.get(candidates[0].kind, candidates[0].kind)
176
- lines = [f"{label}里匹配到 {len(candidates)} 个条目,写全一点:"]
177
- for candidate in candidates[:12]:
178
- lines.append(f"· {candidate.label}({candidate.detail})")
179
- return "\n".join(lines)
180
-
181
-
182
- async def toggle_text(env: ReplyEnv, candidates: Sequence[Candidate], text: str) -> Reply:
183
- if not candidates:
184
- return f"没找到「{text}」。可以发「收藏 星海」「收藏 鲜花」「收藏 菜谱」先看看图鉴。"
185
-
186
- if len({candidate.kind for candidate in candidates}) > 1:
187
- return _choice_text(candidates, text)
188
-
189
- if len(candidates) > 1:
190
- exact = [candidate for candidate in candidates if candidate.label == text]
191
- if len(exact) != 1:
192
- return _choice_text(candidates, text)
193
- candidates = exact
194
-
195
- candidate = candidates[0]
196
- assert env.store is not None
197
- new_state = await env.store.toggle(env.user_id, candidate.kind, candidate.key)
198
- label = KIND_LABELS.get(candidate.kind, candidate.kind)
199
- mark = "✓ 已标记收集" if new_state else "✗ 已取消收集"
200
- done = env.collected_totals.get(candidate.kind, 0)
201
- return (
202
- f"{mark}:{candidate.label}({label} · {candidate.detail})\n"
203
- f"{label}进度:{done} / {await _kind_total(env, candidate.kind)}"
204
- )
205
-
206
-
207
- async def _kind_total(env: ReplyEnv, kind: str) -> int:
208
- if kind == KIND_STARSEA:
209
- return len((await env.client.get_starsea()).species)
210
- if kind == KIND_FLOWER:
211
- return len((await env.client.get_flowers()).flowers)
212
- if kind == KIND_RECIPE:
213
- return len((await env.client.get_recipes()).recipes)
214
- return 0
215
-
216
-
217
- async def reply_collection(arg: str, env: ReplyEnv) -> Reply:
218
- arg = (arg or "").strip()
219
- if not arg:
220
- return await overview_text(env)
221
-
222
- parts = arg.split(None, 1)
223
- head = parts[0]
224
- rest = parts[1].strip() if len(parts) > 1 else ""
225
-
226
- if not rest:
227
- if head in {"星海", "物种", "采集", "星海物种"}:
228
- return await starsea_progress_text(env)
229
- if head in {"鲜花", "花"}:
230
- return await flower_progress_text(env)
231
- if head in {"菜谱", "料理"}:
232
- return await recipe_progress_text(env)
233
- if head in {"清空", "重置"}:
234
- assert env.store is not None
235
- removed = await env.store.clear(env.user_id)
236
- return f"已清空你的收藏进度(共 {removed} 项)。"
237
-
238
- hint = ""
239
- text = arg
240
- if head in {"星海", "物种", "采集", "星海物种"} and rest:
241
- hint, text = "星海", rest
242
- elif head in {"鲜花", "花"} and rest:
243
- hint, text = "鲜花", rest
244
- elif head in {"菜谱", "料理"} and rest:
245
- hint, text = "菜谱", rest
246
-
247
- return await toggle_text(env, await _candidates(env, text, hint), text)