<div align="center">
<h1 align="center"> Tsugu B3 </h1>
<div align="center">
</div>
✨<img src="./logo.jpg" width="30" width="30" height="30" alt="tsugu"/>✨
_✨ User (Natural language) -> ^^^^^ -> [Tsugu BanG Dream Bot](https://github.com/Yamamoto-2/tsugu-bangdream-bot?tab=readme-ov-file) ✨_
</div>
<p align="center">
<a href="https://github.com/Yamamoto-2/tsugu-bangdream-bot">
<img src="https://img.shields.io/badge/tsugubangdream bot - api-yellow" alt="license">
</a>
<a href="https://github.com/kumoSleeping/tsugu-python-frontend?tab=MIT-1-ov-file">
<img src="https://img.shields.io/github/license/kumoSleeping/tsugu-python-frontend" alt="license">
</a>
<a href="https://pypi.org/project/tsugu/">
<img src="https://img.shields.io/pypi/v/tsugu.svg" alt="license">
</a>
</p>
---
## 📦 Install
```shell
pip install tsugu
```
> API powered by <a href="https://github.com/WindowsSov8forUs/tsugu-api-python?tab=readme-ov-file">tsugu-api-python</a>
> Command matching provided by <a href="https://github.com/ArcletProject/Alconna">Alconna</a>
***
## 🚗 App
| 项目 | 说明 |
| --- | --- |
| [Tsugu QQ 官方机器人](https://bot.q.qq.com/s/b2vuxpu4g?id=102076262) | 主力项目 |
| Tomorin 私家机器人 | 私家车,基于标准用户数据库 |
| [一个 NoneBot 插件](https://github.com/zhaomaoniu/tsugu-bangdream-bot-py) | 无人维护,不如去用[这个](https://github.com/WindowsSov8forUs/nonebot-plugin-tsugu-bangdream-bot) |
|[lgr-py Tsugu](https://github.com/kumoSleeping/lgr-tsugu-py) | 无人维护,似了 |
## 📜 Feat
- 为改善用户体验,本包与 `koishi 插件` 在部分行为上略有不同。
- 默认不需要命令头后跟上完整的空格(可关闭)。
- `绑定玩家` `解除绑定` `刷新验证吗` 等自验证策略。
- 基于 `Alconna` 的真 “可选参数” 。
- 车站相关功能不主动支持绑定账号的配队信息,但被动渲染车站给出的配队信息。
- 参数错误时输出完整的命令帮助信息。
- 略有不同的车站屏蔽词策略。
- 增加 `上传车牌` 命令,但仍然支持自动从文本开头提取车牌。
- `主账号` 和 `解除绑定` 的不同行为。
- 争议功能
- 暂时支持 玩家状态 \<serverName\> 策略
- 暂不支持 shortcut类指令
- 暂不支持 `国服模式` `国服玩家状态` 等指令
- 而应该使用 `主服务器 国服` `玩家状态 国服` 等指令式响应。
- 暂不支持 Tsugu 内部车站互通,只通 `bangdori station` 。
- 为了适应官方 BOT 的特性,本包提供了隐式一些非通用方法。
- 当解除绑定用户数据库返回特定值时会被认定为安全模式,触发直接解除绑定操作。
## 📚 Async & Higher-Order Function
`cmd_generator` 是一个异步方法,用于直接处理用户输入的自然语言并处理,调用传入的 `send_func` 发送结果
- `message` (str):用户输入的自然语言
- `user_id` (str):用户的 `channel_id` 或 `user_id`,当 `platform` 为 `red` 、 `chronocat` 、 `onebot` 时,该值一般为用户 QQ 号
- `platform` (str):用户的平台(默认值:`red`)
- `send_func`(Awaitable):期望一个接受 `result` 参数的异步方法,用于发送结果,具体需要实现的方法请参考下方示例
```python
import asyncio
import base64
import io
from PIL import Image
from tsugu import cmd_generator
from loguru import logger
async def _test_send(result):
if isinstance(result, list):
if not result:
logger.error("没有返回数据")
return
for item in result:
if item["type"] == "string":
logger.success("\n" + item['string'])
elif item["type"] == "base64":
i = base64.b64decode(item["string"])
logger.warning(
"\n" + f"[图片: 图像大小: {len(i) / 1024:.2f}KB]"
)
img = Image.open(io.BytesIO(i))
img.show()
if isinstance(result, str):
logger.success("\n" + result)
asyncio.run(cmd_generator(message='查卡 ksm', user_id='114514', send_func=_test_send))
```
## ✏️ Config
>配置方式
- 通过环境变量
linux & macos
```zsh
export TSUGU_COMPACT=false
...
```
windows
```bat
set TSUGU_COMPACT=false
...
```
- 通过 `.env` 文件
```shell
TSUGU_COMPACT=false
...
```
> 可配置项
```zsh
# 命令头后是否必须跟上完整的空格才能匹配,例如 `查卡947` 与 `查卡 947` 。(默认值:false)
TSUGU_COMPACT=false
# 设置请求超时时间(默认值:120秒)
TSUGU_TIMEOUT=120
# 设置代理地址(默认值:空字符串)
TSUGU_PROXY=''
# 设置后端地址(默认值:http://tsugubot.com:8080)
TSUGU_BACKEND_URL=http://tsugubot.com:8080
# 设置是否使用后端代理(默认值:true)
TSUGU_BACKEND_PROXY=true
# 设置用户数据后端地址(默认值:http://tsugubot.com:8080)
TSUGU_USERDATA_BACKEND_URL=http://tsugubot.com:8080
# 设置是否使用用户数据后端代理(默认值:true)
TSUGU_USERDATA_BACKEND_PROXY=true
# 设置是否使用简易背景(默认值:true)
TSUGU_USE_EASY_BG=true
# 设置是否压缩返回数据(默认值:true)
TSUGU_COMPRESS=true
```
---
Raw data
{
"_id": null,
"home_page": "https://github.com/kumoSleeping/ChatTsuguPy",
"name": "tsugu",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "kumoSleeping",
"author_email": "zjr2992@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/30/6f/728d5ec3baaa2ba80c19315a1c49b3047ca9581dc788426fe677f2e2c1dd/tsugu-6.0.0.tar.gz",
"platform": null,
"description": "\n\n\n<div align=\"center\">\n\n\n<h1 align=\"center\"> Tsugu B3 </h1>\n\n\n<div align=\"center\">\n\n</div>\n\n\u2728<img src=\"./logo.jpg\" width=\"30\" width=\"30\" height=\"30\" alt=\"tsugu\"/>\u2728\n\n\n\n_\u2728 User (Natural language) -> ^^^^^ -> [Tsugu BanG Dream Bot](https://github.com/Yamamoto-2/tsugu-bangdream-bot?tab=readme-ov-file) \u2728_\n</div>\n\n<p align=\"center\">\n<a href=\"https://github.com/Yamamoto-2/tsugu-bangdream-bot\">\n <img src=\"https://img.shields.io/badge/tsugubangdream bot - api-yellow\" alt=\"license\">\n </a>\n\n<a href=\"https://github.com/kumoSleeping/tsugu-python-frontend?tab=MIT-1-ov-file\">\n <img src=\"https://img.shields.io/github/license/kumoSleeping/tsugu-python-frontend\" alt=\"license\">\n </a>\n<a href=\"https://pypi.org/project/tsugu/\">\n <img src=\"https://img.shields.io/pypi/v/tsugu.svg\" alt=\"license\">\n </a>\n</p>\n\n---\n\n## \ud83d\udce6 Install\n\n```shell\npip install tsugu\n```\n\n> API powered by <a href=\"https://github.com/WindowsSov8forUs/tsugu-api-python?tab=readme-ov-file\">tsugu-api-python</a>\n\n> Command matching provided by <a href=\"https://github.com/ArcletProject/Alconna\">Alconna</a>\n\n***\n\n## \ud83d\ude97 App\n| \u9879\u76ee | \u8bf4\u660e |\n| --- | --- |\n| [Tsugu QQ \u5b98\u65b9\u673a\u5668\u4eba](https://bot.q.qq.com/s/b2vuxpu4g?id=102076262) | \u4e3b\u529b\u9879\u76ee |\n| Tomorin \u79c1\u5bb6\u673a\u5668\u4eba | \u79c1\u5bb6\u8f66\uff0c\u57fa\u4e8e\u6807\u51c6\u7528\u6237\u6570\u636e\u5e93 |\n| [\u4e00\u4e2a NoneBot \u63d2\u4ef6](https://github.com/zhaomaoniu/tsugu-bangdream-bot-py) | \u65e0\u4eba\u7ef4\u62a4\uff0c\u4e0d\u5982\u53bb\u7528[\u8fd9\u4e2a](https://github.com/WindowsSov8forUs/nonebot-plugin-tsugu-bangdream-bot) |\n|[lgr-py Tsugu](https://github.com/kumoSleeping/lgr-tsugu-py) | \u65e0\u4eba\u7ef4\u62a4\uff0c\u4f3c\u4e86 |\n\n\n## \ud83d\udcdc Feat\n\n- \u4e3a\u6539\u5584\u7528\u6237\u4f53\u9a8c\uff0c\u672c\u5305\u4e0e `koishi \u63d2\u4ef6` \u5728\u90e8\u5206\u884c\u4e3a\u4e0a\u7565\u6709\u4e0d\u540c\u3002\n - \u9ed8\u8ba4\u4e0d\u9700\u8981\u547d\u4ee4\u5934\u540e\u8ddf\u4e0a\u5b8c\u6574\u7684\u7a7a\u683c\uff08\u53ef\u5173\u95ed\uff09\u3002\n - `\u7ed1\u5b9a\u73a9\u5bb6` `\u89e3\u9664\u7ed1\u5b9a` `\u5237\u65b0\u9a8c\u8bc1\u5417` \u7b49\u81ea\u9a8c\u8bc1\u7b56\u7565\u3002\n - \u57fa\u4e8e `Alconna` \u7684\u771f \u201c\u53ef\u9009\u53c2\u6570\u201d \u3002\n - \u8f66\u7ad9\u76f8\u5173\u529f\u80fd\u4e0d\u4e3b\u52a8\u652f\u6301\u7ed1\u5b9a\u8d26\u53f7\u7684\u914d\u961f\u4fe1\u606f\uff0c\u4f46\u88ab\u52a8\u6e32\u67d3\u8f66\u7ad9\u7ed9\u51fa\u7684\u914d\u961f\u4fe1\u606f\u3002\n - \u53c2\u6570\u9519\u8bef\u65f6\u8f93\u51fa\u5b8c\u6574\u7684\u547d\u4ee4\u5e2e\u52a9\u4fe1\u606f\u3002\n - \u7565\u6709\u4e0d\u540c\u7684\u8f66\u7ad9\u5c4f\u853d\u8bcd\u7b56\u7565\u3002\n - \u589e\u52a0 `\u4e0a\u4f20\u8f66\u724c` \u547d\u4ee4\uff0c\u4f46\u4ecd\u7136\u652f\u6301\u81ea\u52a8\u4ece\u6587\u672c\u5f00\u5934\u63d0\u53d6\u8f66\u724c\u3002\n - `\u4e3b\u8d26\u53f7` \u548c `\u89e3\u9664\u7ed1\u5b9a` \u7684\u4e0d\u540c\u884c\u4e3a\u3002\n- \u4e89\u8bae\u529f\u80fd\n - \u6682\u65f6\u652f\u6301 \u73a9\u5bb6\u72b6\u6001 \\<serverName\\> \u7b56\u7565\n - \u6682\u4e0d\u652f\u6301 shortcut\u7c7b\u6307\u4ee4\n - \u6682\u4e0d\u652f\u6301 `\u56fd\u670d\u6a21\u5f0f` `\u56fd\u670d\u73a9\u5bb6\u72b6\u6001` \u7b49\u6307\u4ee4\n - \u800c\u5e94\u8be5\u4f7f\u7528 `\u4e3b\u670d\u52a1\u5668 \u56fd\u670d` `\u73a9\u5bb6\u72b6\u6001 \u56fd\u670d` \u7b49\u6307\u4ee4\u5f0f\u54cd\u5e94\u3002\n - \u6682\u4e0d\u652f\u6301 Tsugu \u5185\u90e8\u8f66\u7ad9\u4e92\u901a\uff0c\u53ea\u901a `bangdori station` \u3002\n- \u4e3a\u4e86\u9002\u5e94\u5b98\u65b9 BOT \u7684\u7279\u6027\uff0c\u672c\u5305\u63d0\u4f9b\u4e86\u9690\u5f0f\u4e00\u4e9b\u975e\u901a\u7528\u65b9\u6cd5\u3002\n - \u5f53\u89e3\u9664\u7ed1\u5b9a\u7528\u6237\u6570\u636e\u5e93\u8fd4\u56de\u7279\u5b9a\u503c\u65f6\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u5b89\u5168\u6a21\u5f0f\uff0c\u89e6\u53d1\u76f4\u63a5\u89e3\u9664\u7ed1\u5b9a\u64cd\u4f5c\u3002\n\n\n\n## \ud83d\udcda Async & Higher-Order Function\n`cmd_generator` \u662f\u4e00\u4e2a\u5f02\u6b65\u65b9\u6cd5\uff0c\u7528\u4e8e\u76f4\u63a5\u5904\u7406\u7528\u6237\u8f93\u5165\u7684\u81ea\u7136\u8bed\u8a00\u5e76\u5904\u7406\uff0c\u8c03\u7528\u4f20\u5165\u7684 `send_func` \u53d1\u9001\u7ed3\u679c\n- `message` (str)\uff1a\u7528\u6237\u8f93\u5165\u7684\u81ea\u7136\u8bed\u8a00\n- `user_id` (str)\uff1a\u7528\u6237\u7684 `channel_id` \u6216 `user_id`\uff0c\u5f53 `platform` \u4e3a `red` \u3001 `chronocat` \u3001 `onebot` \u65f6\uff0c\u8be5\u503c\u4e00\u822c\u4e3a\u7528\u6237 QQ \u53f7\n- `platform` (str)\uff1a\u7528\u6237\u7684\u5e73\u53f0\uff08\u9ed8\u8ba4\u503c\uff1a`red`\uff09\n- `send_func`\uff08Awaitable\uff09\uff1a\u671f\u671b\u4e00\u4e2a\u63a5\u53d7 `result` \u53c2\u6570\u7684\u5f02\u6b65\u65b9\u6cd5\uff0c\u7528\u4e8e\u53d1\u9001\u7ed3\u679c\uff0c\u5177\u4f53\u9700\u8981\u5b9e\u73b0\u7684\u65b9\u6cd5\u8bf7\u53c2\u8003\u4e0b\u65b9\u793a\u4f8b\n\n\n```python\nimport asyncio\nimport base64\nimport io\nfrom PIL import Image\nfrom tsugu import cmd_generator\nfrom loguru import logger\n\n async def _test_send(result):\n if isinstance(result, list):\n if not result:\n logger.error(\"\u6ca1\u6709\u8fd4\u56de\u6570\u636e\")\n return\n for item in result:\n if item[\"type\"] == \"string\":\n logger.success(\"\\n\" + item['string'])\n elif item[\"type\"] == \"base64\":\n i = base64.b64decode(item[\"string\"])\n logger.warning(\n \"\\n\" + f\"[\u56fe\u7247: \u56fe\u50cf\u5927\u5c0f: {len(i) / 1024:.2f}KB]\"\n )\n img = Image.open(io.BytesIO(i))\n img.show()\n if isinstance(result, str):\n logger.success(\"\\n\" + result)\n\n\nasyncio.run(cmd_generator(message='\u67e5\u5361 ksm', user_id='114514', send_func=_test_send))\n\n```\n\n## \u270f\ufe0f Config\n\n>\u914d\u7f6e\u65b9\u5f0f\n\n- \u901a\u8fc7\u73af\u5883\u53d8\u91cf\n linux & macos\n ```zsh\n export TSUGU_COMPACT=false\n ...\n ```\n windows\n ```bat\n set TSUGU_COMPACT=false\n ...\n ```\n\n- \u901a\u8fc7 `.env` \u6587\u4ef6\n ```shell\n TSUGU_COMPACT=false\n ...\n ```\n\n> \u53ef\u914d\u7f6e\u9879\n\n```zsh\n# \u547d\u4ee4\u5934\u540e\u662f\u5426\u5fc5\u987b\u8ddf\u4e0a\u5b8c\u6574\u7684\u7a7a\u683c\u624d\u80fd\u5339\u914d\uff0c\u4f8b\u5982 `\u67e5\u5361947` \u4e0e `\u67e5\u5361 947` \u3002\uff08\u9ed8\u8ba4\u503c\uff1afalse\uff09\nTSUGU_COMPACT=false \n\n# \u8bbe\u7f6e\u8bf7\u6c42\u8d85\u65f6\u65f6\u95f4\uff08\u9ed8\u8ba4\u503c\uff1a120\u79d2\uff09\nTSUGU_TIMEOUT=120\n\n# \u8bbe\u7f6e\u4ee3\u7406\u5730\u5740\uff08\u9ed8\u8ba4\u503c\uff1a\u7a7a\u5b57\u7b26\u4e32\uff09\nTSUGU_PROXY=''\n\n# \u8bbe\u7f6e\u540e\u7aef\u5730\u5740\uff08\u9ed8\u8ba4\u503c\uff1ahttp://tsugubot.com:8080\uff09\nTSUGU_BACKEND_URL=http://tsugubot.com:8080\n\n# \u8bbe\u7f6e\u662f\u5426\u4f7f\u7528\u540e\u7aef\u4ee3\u7406\uff08\u9ed8\u8ba4\u503c\uff1atrue\uff09\nTSUGU_BACKEND_PROXY=true\n\n# \u8bbe\u7f6e\u7528\u6237\u6570\u636e\u540e\u7aef\u5730\u5740\uff08\u9ed8\u8ba4\u503c\uff1ahttp://tsugubot.com:8080\uff09\nTSUGU_USERDATA_BACKEND_URL=http://tsugubot.com:8080\n\n# \u8bbe\u7f6e\u662f\u5426\u4f7f\u7528\u7528\u6237\u6570\u636e\u540e\u7aef\u4ee3\u7406\uff08\u9ed8\u8ba4\u503c\uff1atrue\uff09\nTSUGU_USERDATA_BACKEND_PROXY=true\n\n# \u8bbe\u7f6e\u662f\u5426\u4f7f\u7528\u7b80\u6613\u80cc\u666f\uff08\u9ed8\u8ba4\u503c\uff1atrue\uff09\nTSUGU_USE_EASY_BG=true\n\n# \u8bbe\u7f6e\u662f\u5426\u538b\u7f29\u8fd4\u56de\u6570\u636e\uff08\u9ed8\u8ba4\u503c\uff1atrue\uff09\nTSUGU_COMPRESS=true\n```\n\n\n---\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Tsugu Python Frontend",
"version": "6.0.0",
"project_urls": {
"Homepage": "https://github.com/kumoSleeping/ChatTsuguPy"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aac0668b878ef6d67aada56c0198b3488654f3c2fef0594e20ed29c72f84507e",
"md5": "f17bec14cafad409f7355d00009dbf54",
"sha256": "ed0c7bf6381a0765aa80986e5ff6e9047528719b0478abc58148f60f0b5e3771"
},
"downloads": -1,
"filename": "tsugu-6.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f17bec14cafad409f7355d00009dbf54",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14308,
"upload_time": "2024-11-17T04:38:21",
"upload_time_iso_8601": "2024-11-17T04:38:21.371948Z",
"url": "https://files.pythonhosted.org/packages/aa/c0/668b878ef6d67aada56c0198b3488654f3c2fef0594e20ed29c72f84507e/tsugu-6.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "306f728d5ec3baaa2ba80c19315a1c49b3047ca9581dc788426fe677f2e2c1dd",
"md5": "9da741a1c9d9eede63c386526e635567",
"sha256": "b73f69289388d223e18f71f72238ee909e7885415fa43d7b2ecea44eda00bd63"
},
"downloads": -1,
"filename": "tsugu-6.0.0.tar.gz",
"has_sig": false,
"md5_digest": "9da741a1c9d9eede63c386526e635567",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 15847,
"upload_time": "2024-11-17T04:38:23",
"upload_time_iso_8601": "2024-11-17T04:38:23.053609Z",
"url": "https://files.pythonhosted.org/packages/30/6f/728d5ec3baaa2ba80c19315a1c49b3047ca9581dc788426fe677f2e2c1dd/tsugu-6.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-17 04:38:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kumoSleeping",
"github_project": "ChatTsuguPy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "tsugu"
}