nonebot-plugin-bugu 0.2.0__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.
Files changed (35) hide show
  1. nonebot_plugin_bugu/__init__.py +31 -0
  2. nonebot_plugin_bugu/api.py +282 -0
  3. nonebot_plugin_bugu/collection.py +166 -0
  4. nonebot_plugin_bugu/commands.py +234 -0
  5. nonebot_plugin_bugu/config.py +91 -0
  6. nonebot_plugin_bugu/draw.py +406 -0
  7. nonebot_plugin_bugu/features/__init__.py +0 -0
  8. nonebot_plugin_bugu/features/collection.py +247 -0
  9. nonebot_plugin_bugu/features/common.py +100 -0
  10. nonebot_plugin_bugu/features/flowers/__init__.py +0 -0
  11. nonebot_plugin_bugu/features/flowers/data.py +167 -0
  12. nonebot_plugin_bugu/features/flowers/render.py +300 -0
  13. nonebot_plugin_bugu/features/flowers/reply.py +123 -0
  14. nonebot_plugin_bugu/features/neighbors/__init__.py +0 -0
  15. nonebot_plugin_bugu/features/neighbors/data.py +143 -0
  16. nonebot_plugin_bugu/features/neighbors/render.py +225 -0
  17. nonebot_plugin_bugu/features/neighbors/reply.py +149 -0
  18. nonebot_plugin_bugu/features/recipes/__init__.py +0 -0
  19. nonebot_plugin_bugu/features/recipes/data.py +313 -0
  20. nonebot_plugin_bugu/features/recipes/render.py +371 -0
  21. nonebot_plugin_bugu/features/recipes/reply.py +219 -0
  22. nonebot_plugin_bugu/features/recipes/search.py +151 -0
  23. nonebot_plugin_bugu/features/starsea/__init__.py +0 -0
  24. nonebot_plugin_bugu/features/starsea/data.py +267 -0
  25. nonebot_plugin_bugu/features/starsea/render.py +579 -0
  26. nonebot_plugin_bugu/features/starsea/reply.py +356 -0
  27. nonebot_plugin_bugu/features/starsea/search.py +271 -0
  28. nonebot_plugin_bugu/fonts.py +152 -0
  29. nonebot_plugin_bugu/runtime.py +109 -0
  30. nonebot_plugin_bugu/values.py +87 -0
  31. nonebot_plugin_bugu-0.2.0.dist-info/METADATA +257 -0
  32. nonebot_plugin_bugu-0.2.0.dist-info/RECORD +35 -0
  33. nonebot_plugin_bugu-0.2.0.dist-info/WHEEL +4 -0
  34. nonebot_plugin_bugu-0.2.0.dist-info/entry_points.txt +3 -0
  35. nonebot_plugin_bugu-0.2.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,152 @@
1
+ """中文字体查找。
2
+
3
+ 图片卡片里的字全靠这个模块:优先用配置里指定的字体,
4
+ 没配就在常见系统字体里挑一个能显示中文的(macOS / Linux / Windows 都覆盖)。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass
10
+ from pathlib import Path
11
+ from typing import Dict, List, Optional, Tuple
12
+
13
+ try: # 没装 Pillow 时插件仍要能导入,具体报错留给渲染阶段
14
+ from PIL import ImageFont
15
+ except ImportError: # pragma: no cover - 依赖已写在 pyproject 里
16
+ ImageFont = None # type: ignore[assignment]
17
+
18
+
19
+ class FontError(RuntimeError):
20
+ """找不到可用的中文字体。"""
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class FontChoice:
25
+ """一个字体文件 + ttc 里的索引。"""
26
+
27
+ path: str
28
+ index: int = 0
29
+
30
+ @property
31
+ def exists(self) -> bool:
32
+ return Path(self.path).is_file()
33
+
34
+
35
+ # (常规体, 粗体);粗体为 None 时用常规体加描边模拟
36
+ _CANDIDATES: List[Tuple[FontChoice, Optional[FontChoice]]] = [
37
+ # ---- macOS
38
+ (
39
+ FontChoice("/System/Library/Fonts/Hiragino Sans GB.ttc", 0),
40
+ FontChoice("/System/Library/Fonts/Hiragino Sans GB.ttc", 2),
41
+ ),
42
+ (
43
+ FontChoice("/System/Library/Fonts/PingFang.ttc", 0),
44
+ FontChoice("/System/Library/Fonts/PingFang.ttc", 1),
45
+ ),
46
+ (
47
+ FontChoice("/System/Library/Fonts/STHeiti Light.ttc", 1),
48
+ FontChoice("/System/Library/Fonts/STHeiti Medium.ttc", 1),
49
+ ),
50
+ (
51
+ FontChoice("/System/Library/Fonts/Supplemental/Songti.ttc", 3),
52
+ FontChoice("/System/Library/Fonts/Supplemental/Songti.ttc", 1),
53
+ ),
54
+ (FontChoice("/Library/Fonts/Arial Unicode.ttf", 0), None),
55
+ # ---- Linux(Noto / 文泉驿 / 文鼎)
56
+ (
57
+ FontChoice("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 0),
58
+ FontChoice("/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc", 0),
59
+ ),
60
+ (
61
+ FontChoice("/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", 0),
62
+ FontChoice("/usr/share/fonts/noto-cjk/NotoSansCJK-Bold.ttc", 0),
63
+ ),
64
+ (
65
+ FontChoice("/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc", 0),
66
+ FontChoice("/usr/share/fonts/truetype/noto/NotoSansCJK-Bold.ttc", 0),
67
+ ),
68
+ (
69
+ FontChoice("/usr/share/fonts/opentype/noto/NotoSansCJKsc-Regular.otf", 0),
70
+ FontChoice("/usr/share/fonts/opentype/noto/NotoSansCJKsc-Bold.otf", 0),
71
+ ),
72
+ (FontChoice("/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", 0), None),
73
+ (FontChoice("/usr/share/fonts/truetype/wqy/wqy-microhei.ttc", 0), None),
74
+ (FontChoice("/usr/share/fonts/truetype/arphic/uming.ttc", 0), None),
75
+ # ---- Windows
76
+ (
77
+ FontChoice("C:/Windows/Fonts/msyh.ttc", 0),
78
+ FontChoice("C:/Windows/Fonts/msyhbd.ttc", 0),
79
+ ),
80
+ (FontChoice("C:/Windows/Fonts/simhei.ttf", 0), None),
81
+ (FontChoice("C:/Windows/Fonts/simsun.ttc", 0), None),
82
+ ]
83
+
84
+
85
+ class FontSet:
86
+ """按字号取字体;粗体优先用真粗体,没有就描边模拟。"""
87
+
88
+ def __init__(
89
+ self,
90
+ regular: FontChoice,
91
+ bold: Optional[FontChoice] = None,
92
+ *,
93
+ faux_bold: bool = False,
94
+ ) -> None:
95
+ self.regular = regular
96
+ self.bold = bold or regular
97
+ self.faux_bold = faux_bold or bold is None
98
+ self._cache: Dict[Tuple[int, bool], object] = {}
99
+
100
+ def get(self, size: int, bold: bool = False):
101
+ if ImageFont is None: # pragma: no cover
102
+ raise FontError("未安装 Pillow,无法渲染图片")
103
+ key = (int(size), bool(bold))
104
+ cached = self._cache.get(key)
105
+ if cached is not None:
106
+ return cached
107
+ choice = self.bold if bold else self.regular
108
+ try:
109
+ font = ImageFont.truetype(choice.path, int(size), index=choice.index)
110
+ except OSError as exc: # 字体文件损坏 / 索引越界
111
+ raise FontError(f"加载字体失败:{choice.path}({exc})") from exc
112
+ self._cache[key] = font
113
+ return font
114
+
115
+ def stroke(self, bold: bool) -> int:
116
+ """粗体是模拟的才需要描边(真粗体返回 0)。"""
117
+ return 1 if (bold and self.faux_bold) else 0
118
+
119
+
120
+ def resolve_fonts(
121
+ *,
122
+ regular_path: str = "",
123
+ regular_index: int = 0,
124
+ bold_path: str = "",
125
+ bold_index: int = 0,
126
+ ) -> FontSet:
127
+ """确定用哪套字体;用户配置优先,否则自动探测。"""
128
+ if regular_path:
129
+ regular = FontChoice(regular_path, regular_index)
130
+ if not regular.exists:
131
+ raise FontError(f"配置的字体文件不存在:{regular_path}")
132
+ bold = FontChoice(bold_path, bold_index) if bold_path else None
133
+ if bold is not None and not bold.exists:
134
+ raise FontError(f"配置的粗体字体文件不存在:{bold_path}")
135
+ return FontSet(regular, bold, faux_bold=bold is None)
136
+
137
+ for regular, bold in _CANDIDATES:
138
+ if not regular.exists:
139
+ continue
140
+ if bold is not None and not bold.exists:
141
+ bold = None
142
+ return FontSet(regular, bold, faux_bold=bold is None)
143
+
144
+ raise FontError(
145
+ "没找到可用的中文字体,请在 .env 里设置 BUGU_FONT_PATH 指向一个中文字体文件"
146
+ )
147
+
148
+
149
+ def describe_fonts(fonts: FontSet) -> str:
150
+ """调试用:把当前字体说出来。"""
151
+ bold = fonts.bold.path if fonts.bold else "(模拟)"
152
+ return f"regular={fonts.regular.path}#{fonts.regular.index} bold={bold}"
@@ -0,0 +1,109 @@
1
+ """运行时单例:HTTP 客户端、字体、收集进度。
2
+
3
+ 插件里所有命令都从这里拿,避免每次请求都新建连接池。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import tempfile
9
+ from pathlib import Path
10
+ from typing import Optional
11
+
12
+ from nonebot import get_plugin_config
13
+
14
+ from .api import BuguClient, ImageCache
15
+ from .collection import CollectionStore
16
+ from .config import Config
17
+ from .fonts import FontSet, resolve_fonts
18
+
19
+ _client: Optional[BuguClient] = None
20
+ _fonts: Optional[FontSet] = None
21
+ _fonts_key: Optional[tuple] = None
22
+ _store: Optional[CollectionStore] = None
23
+
24
+
25
+ def get_config() -> Config:
26
+ return get_plugin_config(Config)
27
+
28
+
29
+ def _localstore_dir(kind: str) -> Optional[Path]:
30
+ try:
31
+ from nonebot_plugin_localstore import get_plugin_cache_dir, get_plugin_data_dir
32
+
33
+ base = get_plugin_data_dir() if kind == "data" else get_plugin_cache_dir()
34
+ return base
35
+ 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"
51
+
52
+
53
+ def get_client(config: Optional[Config] = None) -> BuguClient:
54
+ global _client
55
+ if _client is None:
56
+ cfg = config or get_config()
57
+ _client = BuguClient(
58
+ api_base=cfg.bugu_api_base,
59
+ timeout=cfg.bugu_request_timeout,
60
+ data_ttl=cfg.bugu_data_cache_ttl,
61
+ image_cache=ImageCache(default_cache_dir(), cfg.bugu_image_cache_ttl),
62
+ )
63
+ return _client
64
+
65
+
66
+ def set_client(client: Optional[BuguClient]) -> None:
67
+ """测试 / 热切换用。"""
68
+ global _client
69
+ _client = client
70
+
71
+
72
+ def get_fonts(config: Optional[Config] = None) -> FontSet:
73
+ global _fonts, _fonts_key
74
+ cfg = config or get_config()
75
+ key = (
76
+ cfg.bugu_font_path,
77
+ cfg.bugu_font_index,
78
+ cfg.bugu_bold_font_path,
79
+ cfg.bugu_bold_font_index,
80
+ )
81
+ if _fonts is None or _fonts_key != key:
82
+ _fonts = resolve_fonts(
83
+ regular_path=cfg.bugu_font_path,
84
+ regular_index=cfg.bugu_font_index,
85
+ bold_path=cfg.bugu_bold_font_path,
86
+ bold_index=cfg.bugu_bold_font_index,
87
+ )
88
+ _fonts_key = key
89
+ return _fonts
90
+
91
+
92
+ def reset_fonts() -> None:
93
+ global _fonts, _fonts_key
94
+ _fonts = None
95
+ _fonts_key = None
96
+
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
@@ -0,0 +1,87 @@
1
+ """字段兜底与通用小工具。
2
+
3
+ 接口里 null / 缺字段 / 类型不对的情况不少,统一在这里收敛,
4
+ 各个 ``data.py`` 抓到什么就用什么,不会因为上游改字段把插件打挂。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any, List, Optional
10
+
11
+ GRADE_TEXT = {"S": "金色", "A": "紫色", "B": "蓝色", "C": "普通"}
12
+ GRADE_RANK = {"S": 0, "A": 1, "B": 2, "C": 3}
13
+
14
+
15
+ def grade_text(grade: str) -> str:
16
+ return GRADE_TEXT.get((grade or "").upper(), "未知")
17
+
18
+
19
+ def grade_rank(grade: str) -> int:
20
+ return GRADE_RANK.get((grade or "").upper(), 4)
21
+
22
+
23
+ def absolute_url(base: str, url: Optional[str]) -> str:
24
+ if not url:
25
+ return ""
26
+ if url.startswith(("http://", "https://")):
27
+ return url
28
+ base = base.rstrip("/")
29
+ return base + url if url.startswith("/") else f"{base}/{url}"
30
+
31
+
32
+ def clean_text(value: Any, default: str = "") -> str:
33
+ """统一换行符、去掉首尾空白。"""
34
+ if value is None:
35
+ return default
36
+ text = value if isinstance(value, str) else str(value)
37
+ return text.replace("\r\n", "\n").replace("\r", "\n").strip()
38
+
39
+
40
+ def as_str(value: Any, default: str = "") -> str:
41
+ return default if value is None else str(value)
42
+
43
+
44
+ def as_int(value: Any, default: int = 0) -> int:
45
+ try:
46
+ return int(value)
47
+ except (TypeError, ValueError):
48
+ return default
49
+
50
+
51
+ def as_optional_int(value: Any) -> Optional[int]:
52
+ if value is None or value == "":
53
+ return None
54
+ try:
55
+ return int(value)
56
+ except (TypeError, ValueError):
57
+ return None
58
+
59
+
60
+ def as_float(value: Any, default: float = 0.0) -> float:
61
+ try:
62
+ return float(value)
63
+ except (TypeError, ValueError):
64
+ return default
65
+
66
+
67
+ def as_str_list(value: Any) -> List[str]:
68
+ if not isinstance(value, (list, tuple)):
69
+ return []
70
+ out: List[str] = []
71
+ for item in value:
72
+ text = as_str(item)
73
+ if text:
74
+ out.append(text)
75
+ return out
76
+
77
+
78
+ def as_int_list(value: Any) -> List[int]:
79
+ if not isinstance(value, (list, tuple)):
80
+ return []
81
+ out: List[int] = []
82
+ for item in value:
83
+ try:
84
+ out.append(int(item))
85
+ except (TypeError, ValueError):
86
+ continue
87
+ return out
@@ -0,0 +1,257 @@
1
+ Metadata-Version: 2.4
2
+ Name: nonebot-plugin-bugu
3
+ Version: 0.2.0
4
+ Summary: 布谷工具箱(星布谷地小助手):菜谱、星海地图、友邻备忘、鲜花培育与收集进度
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: nonebot,nonebot2,onebot,bugu,starsea,recipe,星布谷地,星海地图,菜谱
8
+ Author: TonyLiangP2010405
9
+ Requires-Python: >=3.9,<4.0
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Communications :: Chat
19
+ Requires-Dist: httpx (>=0.27.0)
20
+ Requires-Dist: nonebot-adapter-onebot (>=2.4.0)
21
+ Requires-Dist: nonebot-plugin-localstore (>=0.7.0)
22
+ Requires-Dist: nonebot2 (>=2.2.0)
23
+ Requires-Dist: pillow (>=10.0.0)
24
+ Project-URL: Homepage, https://github.com/TonyLiangP2010405/nonebot-plugin-bugu
25
+ Project-URL: Issues, https://github.com/TonyLiangP2010405/nonebot-plugin-bugu/issues
26
+ Project-URL: Repository, https://github.com/TonyLiangP2010405/nonebot-plugin-bugu
27
+ Description-Content-Type: text/markdown
28
+
29
+ # nonebot-plugin-bugu
30
+
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
32
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue)](pyproject.toml)
33
+ [![NoneBot2](https://img.shields.io/badge/NoneBot2-2.2%2B-5B8FF9)](https://nonebot.dev)
34
+
35
+ 星布谷地小助手 —— 把[布谷工具箱](https://bugu.nsun200512.cc)的四个模块搬进了 QQ:
36
+
37
+ | 模块 | 能干什么 |
38
+ | --- | --- |
39
+ | 🍳 **菜谱查询** | 121 道菜谱的食材 / 厨具 / 力气 / 特殊效果 / 获取途径,支持按食材、类型、厨具、效果、特征搜索 |
40
+ | 🗺 **星海地图** | 3 张地图 43 个点位,底图自动编号 + 图例;点位详情是带品质色的图标墙;还能按物种反查「在哪几个岛」 |
41
+ | 🧑‍🤝‍🧑 **友邻备忘** | 10 位友邻的立绘、资料、介绍和喜爱 / 好感 / 反感 / 关于词条与友邻能力 |
42
+ | 🌷 **鲜花培育** | 13 个品种 87 种花色的杂交配方表 + 花色图鉴(品质、颜色、产地) |
43
+ | ✅ **收集进度** | 按 QQ 号记录已收集的物种 / 鲜花 / 菜谱,卡片上直接打勾,进度只存在本机 |
44
+
45
+ ![区域地图](docs/map-card.png)
46
+
47
+ ![点位详情](docs/point-card.png)
48
+
49
+ ![菜谱卡片](docs/recipe-card.png)
50
+
51
+ ![友邻档案](docs/neighbor-card.png)
52
+
53
+ ![鲜花培育](docs/flower-card.png)
54
+
55
+ ## 安装
56
+
57
+ 需要 Python 3.9+ 和 NoneBot2(OneBot V11 适配器)。
58
+
59
+ ### 从源码安装(当前可用)
60
+
61
+ ```bash
62
+ git clone https://github.com/TonyLiangP2010405/nonebot-plugin-bugu
63
+ cd nonebot-plugin-bugu
64
+ poetry install
65
+ ```
66
+
67
+ 装到已有 bot 环境:
68
+
69
+ ```bash
70
+ pip install git+https://github.com/TonyLiangP2010405/nonebot-plugin-bugu
71
+ ```
72
+
73
+ ### 发布到 PyPI 后
74
+
75
+ ```bash
76
+ nb plugin install nonebot-plugin-bugu # nb-cli
77
+ pip install nonebot-plugin-bugu # pip
78
+ poetry add nonebot-plugin-bugu # poetry
79
+ ```
80
+
81
+ 加载方式:
82
+
83
+ ```python
84
+ import nonebot
85
+ from nonebot.adapters.onebot.v11 import Adapter
86
+
87
+ nonebot.init()
88
+ driver = nonebot.get_driver()
89
+ driver.register_adapter(Adapter)
90
+ nonebot.load_builtin_plugins()
91
+ nonebot.load_plugin("nonebot_plugin_bugu")
92
+ ```
93
+
94
+ ## 配置
95
+
96
+ 配置项写在 NoneBot 项目的 `.env` 里,全部有默认值,**不配也能直接用**。
97
+
98
+ | 配置项 | 默认值 | 说明 |
99
+ | --- | --- | --- |
100
+ | `BUGU_API_BASE` | `https://bugu.nsun200512.cc` | 数据站点地址 |
101
+ | `BUGU_REQUEST_TIMEOUT` | `15.0` | 单次请求超时(秒) |
102
+ | `BUGU_DATA_CACHE_TTL` | `21600` | 数据内存缓存时长(秒) |
103
+ | `BUGU_IMAGE_CACHE_TTL` | `2592000` | 底图 / 图标 / 立绘磁盘缓存时长(秒) |
104
+ | `BUGU_IMAGE_ENABLED` | `true` | 是否出图;关闭后只发文字 |
105
+ | `BUGU_COOLDOWN_SECONDS` | `3` | 同一用户两次出图的最小间隔(秒),`0` 不限制 |
106
+ | `BUGU_SEARCH_LIMIT` | `12` | 一次搜索最多列多少条 |
107
+ | `BUGU_FONT_PATH` | `(空)` | 中文字体路径,留空自动探测系统字体 |
108
+ | `BUGU_FONT_INDEX` | `0` | 字体索引(`.ttc` 集合文件用) |
109
+ | `BUGU_BOLD_FONT_PATH` | `(空)` | 粗体字体路径,留空用常规体加描边模拟 |
110
+ | `BUGU_BOLD_FONT_INDEX` | `0` | 粗体字体索引 |
111
+ | `BUGU_COLLECTION_PATH` | `(空)` | 收集进度文件路径,留空用 localstore 的 data 目录 |
112
+
113
+ ### 关于字体
114
+
115
+ 渲染中文需要中文字体,插件会按顺序自动探测:
116
+
117
+ - **macOS**:`Hiragino Sans GB` → `PingFang SC` → `STHeiti` → `Songti SC` → `Arial Unicode MS`
118
+ - **Linux**:`Noto Sans CJK` → `WenQuanYi Zen Hei / Micro Hei` → `AR PL UMing`
119
+ - **Windows**:`Microsoft YaHei` → `SimHei` → `SimSun`
120
+
121
+ 探测不到就用 `BUGU_FONT_PATH` 指定;连字体都没有时会自动改发文字版,不会报错。
122
+
123
+ ## 使用方法
124
+
125
+ 命令前缀跟随 NoneBot 的 `command_start`(默认 `/`)。
126
+
127
+ | 指令 | 权限 | 说明 |
128
+ | --- | --- | --- |
129
+ | `/布谷` | 所有人 | 全部指令一览 |
130
+ | `/菜谱 [菜名 / 编号]` | 所有人 | 不带参数看统计;带参数出菜谱卡片 |
131
+ | `/菜谱 随机` | 所有人 | 随手看一道 |
132
+ | `/菜谱查 <关键词>` | 所有人 | 搜索 / 筛选(关键词可混写) |
133
+ | `/星海 <任意词>` | 所有人 | 智能识别区域 / 点位 / 物种 |
134
+ | `/星海地图 [区域]` | 所有人 | 区域地图卡片,不带参数列所有区域 |
135
+ | `/星海点位 <点位名>` | 所有人 | 点位详情卡片 |
136
+ | `/星海查 <物种 / 大类>` | 所有人 | 跨区域搜索 |
137
+ | `/友邻 [名字] [分区]` | 所有人 | 友邻名单 / 档案卡;分区可填 喜爱 / 好感 / 反感 / 关于 / 介绍 |
138
+ | `/鲜花 [品种 / 花名]` | 所有人 | 品种列表 / 培育配方卡 / 单朵花详情 |
139
+ | `/收藏 [名字 / 类型]` | 所有人 | 标记收集进度 |
140
+ | `/布谷刷新` | 超级用户 | 强制刷新四个模块的数据并清空图片缓存 |
141
+
142
+ ### 菜谱搜索
143
+
144
+ 一个查询里可以同时混写食材、菜名、类型、厨具、效果、特征,规则和站点一致:
145
+
146
+ ```
147
+ /菜谱 炒鲜蔬 → 精确菜名出卡片
148
+ /菜谱 12 → 按编号出卡片
149
+ /菜谱查 苹果 → 「可用苹果烹饪」+「名称含苹果」两组
150
+ /菜谱查 煮锅 苹果 → 用苹果做的煮锅菜谱
151
+ /菜谱查 秘制 → 只看秘制菜谱
152
+ /菜谱查 甜点 煮锅 → 甜点特征 + 煮锅
153
+ ```
154
+
155
+ 支持的筛选值:菜品类型(简单 / 招牌 / 宴客 / 秘制 / 奇迹盛宴)、厨具(煮锅 / 烤箱 / 榨汁机)、
156
+ 特殊效果(大力播洒 / 大力敲伐 / 钓鱼之力……)、菜品特征(荤菜 / 素菜 / 主食 / 汤羹……)。
157
+
158
+ ### 星海地图
159
+
160
+ ```
161
+ /星海地图 → 三个区域列表
162
+ /星海地图 H83 → 禾夏 H83 区地图卡片(点位 1~15 编号 + 图例)
163
+ /星海点位 迷途小屋之屿 → 点位详情(昆虫 12 / 树木 3 / 鲜花 3 / 创想卡 1 / 种子 1)
164
+ /星海查 三色锦鲤 → 这个物种出现在哪几个点位
165
+ /星海 河鱼 → 智能识别
166
+ ```
167
+
168
+ 搜索支持物种名、大类(`鱼`→河鱼/海鱼,`生物`→昆虫/河鱼/海鱼/海岸生物,也认 `树`、`花`、`矿`、`特产`)和点位名。
169
+
170
+ ### 鲜花培育
171
+
172
+ ```
173
+ /鲜花 → 13 个品种和产地
174
+ /鲜花 百合 → 百合的 3 条配方 + 6 种花色
175
+ /鲜花 黄百合 → 单朵花:品质、颜色、产地、由谁培育、能培育出什么
176
+ ```
177
+
178
+ ## 收集进度
179
+
180
+ 站点自己的「我已获得 / 我已解锁」要邮箱 + 密码登录才能同步。
181
+ **在 bot 里保存用户的站点密码是不合适的**,所以插件做了一份本机进度:
182
+
183
+ - 按 QQ 号分开,存在 `localstore` 的 data 目录(`collection.json`)
184
+ - 三类进度互不影响:星海物种、鲜花、菜谱
185
+ - 标记后,点位卡片 / 鲜花卡片 / 菜谱卡片上会直接出现绿勾或「已解锁」
186
+ - 同名条目跨图鉴时(例如「紫罗兰」既是星海物种又是鲜花)会提示按类型再发一次:
187
+
188
+ ```
189
+ /收藏 疆星步甲 → 切换星海物种
190
+ /收藏 鲜花 紫罗兰 → 指明类型
191
+ /收藏 星海 → 每个点位的收集进度
192
+ /收藏 鲜花 / 菜谱 → 分类进度
193
+ /收藏 清空 → 清空自己的进度
194
+ ```
195
+
196
+ > 如果以后站点开放了 token 形式的公开进度接口,可以再考虑和站点账号打通。
197
+
198
+ ## 数据来源
199
+
200
+ - 站点:<https://bugu.nsun200512.cc>
201
+ - 接口:`/api/bootstrap`(菜谱)、`/api/starsea`(星海)、`/api/neighbors`(友邻)、`/api/flowers`(鲜花)
202
+ - 图片:底图 / 菜品 / 图标 / 立绘都从同站点下载并本地缓存
203
+
204
+ 本插件只做聊天查询,**数据版权归布谷工具箱所有**。站点更新后最迟等缓存过期(默认 6 小时),
205
+ 或者让超管发一次 `/布谷刷新`。
206
+
207
+ ## 常见问题
208
+
209
+ **Q:图片发不出去 / 只收到文字?**
210
+
211
+ 说明这次没渲染成功(字体缺失、图片下载失败等),插件会自动退化成文字版。
212
+ 看日志里「渲染失败」的提示,确认 Pillow 已安装、`BUGU_FONT_PATH` 可用。
213
+
214
+ **Q:会不会被站点限流?**
215
+
216
+ 四个接口都是按需拉取并缓存 6 小时,图片按 URL 缓存 30 天,正常使用打不了几发请求。
217
+ 遇到 429 会提示「请求太频繁」,等一会儿再试。
218
+
219
+ **Q:为什么收集进度不能和网页同步?**
220
+
221
+ 网页同步依赖账号密码,插件不保存用户密码。需要的只是「我收集了哪些」,
222
+ 本机记录已经够用,也不会因为换 bot 环境而泄露账号。
223
+
224
+ ## 开发
225
+
226
+ ```bash
227
+ poetry install
228
+ poetry run pytest
229
+ poetry run ruff check .
230
+ ```
231
+
232
+ 目录结构:
233
+
234
+ ```
235
+ nonebot_plugin_bugu/
236
+ ├── __init__.py # 插件元数据与加载
237
+ ├── config.py # 配置项
238
+ ├── api.py # 四个接口的客户端 + 内存 / 磁盘缓存
239
+ ├── values.py # 字段兜底与通用小工具
240
+ ├── draw.py # 共用绘制:画布、字体、折行、胶囊、页脚
241
+ ├── fonts.py # 中文字体探测
242
+ ├── collection.py # 收集进度存储(按 QQ 号)
243
+ ├── runtime.py # 单例:客户端 / 字体 / 进度
244
+ ├── commands.py # 命令注册与分发
245
+ └── features/
246
+ ├── common.py # ReplyEnv 等共用类型
247
+ ├── starsea/ # data / search / render / reply
248
+ ├── recipes/ # data / search / render / reply
249
+ ├── neighbors/ # data / render / reply
250
+ ├── flowers/ # data / render / reply
251
+ └── collection.py # 收藏命令逻辑
252
+ ```
253
+
254
+ ## 许可证
255
+
256
+ MIT
257
+
@@ -0,0 +1,35 @@
1
+ nonebot_plugin_bugu/__init__.py,sha256=fkKOYDSCy_sR5mGxHliKRCv413_681XG1I3mgAgrTmQ,1220
2
+ nonebot_plugin_bugu/api.py,sha256=MeHRbFSKrYvQdk7-rDPOAAbk8su5Q5A8clu-1R-3mtE,10424
3
+ nonebot_plugin_bugu/collection.py,sha256=zSRDQ0hyBnNhNVr7pgnknmirjoPwLHhCaX-jT5Mm5S4,5848
4
+ nonebot_plugin_bugu/commands.py,sha256=I_RxC--GGsKEPQp_J5a5OkFirzsbLG8vAXhMzHxHNKg,8895
5
+ nonebot_plugin_bugu/config.py,sha256=nHtUtUQhqkuc4biuh40aQ1Q_-rLK0UbHYNb7jMomnso,3076
6
+ nonebot_plugin_bugu/draw.py,sha256=mqKeXxky4k8MECOmBYIF-KifLUK5LnRWFU8Vx51Tbt8,12287
7
+ nonebot_plugin_bugu/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ nonebot_plugin_bugu/features/collection.py,sha256=KENu6Hpmf9m19p7Zz09baNq6Hm8rpGyBb28Cbx6MTGU,9534
9
+ nonebot_plugin_bugu/features/common.py,sha256=DvpuRDfClWx_0HnDewDxmjTMQ1UdEjapTtCy6FllzFk,3074
10
+ nonebot_plugin_bugu/features/flowers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ nonebot_plugin_bugu/features/flowers/data.py,sha256=jhiOE1sLC1qYKrKRdhWmrFkaP744ryEYD2DJU9tpXSg,5169
12
+ nonebot_plugin_bugu/features/flowers/render.py,sha256=Hr7upxNtx_9QbO0QGrzUQB75kt2puIdXpaWQVyf-XRE,8481
13
+ nonebot_plugin_bugu/features/flowers/reply.py,sha256=ktgCPNikFO6qwh-wV44_A7msyEoDIrN-YxKWJyE952M,4222
14
+ nonebot_plugin_bugu/features/neighbors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ nonebot_plugin_bugu/features/neighbors/data.py,sha256=Mnq-nW1qT056wltzNZy0UcrlTbJbfYlzgK1euz-30Bg,4357
16
+ nonebot_plugin_bugu/features/neighbors/render.py,sha256=IinCB-wfP5gvsQJG3MLQGdjiiVLnMDK8Y--0tM9oj2g,7060
17
+ nonebot_plugin_bugu/features/neighbors/reply.py,sha256=Y23Qi21zHxxWulil-CgGlOQyucRJ3HKDol-PphW35CU,4853
18
+ nonebot_plugin_bugu/features/recipes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ nonebot_plugin_bugu/features/recipes/data.py,sha256=T3Ex34gsjUdK_l46Rwi8b8a0nmVILzNht4RS4jLtK0I,10375
20
+ nonebot_plugin_bugu/features/recipes/render.py,sha256=I2fe-jIjQl2176FLH1r2y2Ryup8wu4Of3__lFGMe270,11586
21
+ nonebot_plugin_bugu/features/recipes/reply.py,sha256=rtOPGPwR_eff2Rkej6TUSUSxVXil7biS-2TaTspGbAY,7998
22
+ nonebot_plugin_bugu/features/recipes/search.py,sha256=HJuIkBl7Xk5cOJMjHukWOws0_pFjSxhRxs4N4Ucd3jc,4964
23
+ nonebot_plugin_bugu/features/starsea/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ nonebot_plugin_bugu/features/starsea/data.py,sha256=L7ccYvScIb4aR1_mKpgCOqZ2FaADqTIKjZDCG6oxMcs,8148
25
+ nonebot_plugin_bugu/features/starsea/render.py,sha256=Wfvh-AJBZWiI5VBnnYYFOCHGhH56ZoyOSa-SF-8Mg6I,18596
26
+ nonebot_plugin_bugu/features/starsea/reply.py,sha256=9qr5sEDGFJpucwDKWoU1qksYXvR5tgMrwbvXex7un8M,13362
27
+ nonebot_plugin_bugu/features/starsea/search.py,sha256=HYk6CumdalEGA8tf39I5EAdhsRx_hZRvzU69YIftlVU,8447
28
+ nonebot_plugin_bugu/fonts.py,sha256=HtfKm9VxZPwwkDPuFrSoRBwcJ3Ko-65DAWPWHjSSbRI,5435
29
+ nonebot_plugin_bugu/runtime.py,sha256=e2qfpHyVtkWNRCeNR-hPQuXB6SKpe9cIveAgsTa6wzE,3036
30
+ nonebot_plugin_bugu/values.py,sha256=GXvW0sVrj-HhydKiofpWJTDBZGEQ8IO0PJUsTucihWs,2253
31
+ nonebot_plugin_bugu-0.2.0.dist-info/METADATA,sha256=GaEkeT1X1bR4DreM-uxf0zY2ABsLWDo9mUA0rjBTNrY,10776
32
+ nonebot_plugin_bugu-0.2.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
33
+ nonebot_plugin_bugu-0.2.0.dist-info/entry_points.txt,sha256=lsGjVchOCmJ46wNvC0CtFR3Bw0HK7mJVKEBVzkxvsvs,58
34
+ nonebot_plugin_bugu-0.2.0.dist-info/licenses/LICENSE,sha256=rZSbU5FrLP_yiNLO7Gzu4DAJ_qRrA5X641LCwedRNus,1074
35
+ nonebot_plugin_bugu-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [nonebot.plugin]
2
+ nonebot_plugin_bugu=nonebot_plugin_bugu
3
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TonyLiangP2010405
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.