Skip to main content

Tsugu Python Frontend

Project description

Chat Tsugu Py tsugu

✨ Python 编写的 TsuguBanGDreamBot 自然语言交互库 ✨

license license license


📦 安装

pip install tsugu --upgrade

API powered by tsugu-api-python

Command matching provided by Alconna


📚 异步支持

  • 4.0.0 后需要异步环境处理。

📖 使用

cmd_generator 是一个异步方法,用于直接处理用户输入的自然语言并返回查询结果:

  • 测试可用
import tsugu
import asyncio
print(asyncio.run(tsugu.cmd_generator('查活动', '114514')))
# 输出:[{'type': 'string', 'string': '参数 word 丢失\n查活动 <...word> \n根据活动名、乐队、活动ID等查询活动信息\n使用示例:\n查活动 绿 tsugu :返回所有属性加成为pure,且活动加成角色中包括羽泽鸫的活动列表\n查活动 177 :返回177号活动的信息'}]
  • 生产实操:以 satori-python + chronocat 为例
from tsugu import cmd_generator

@app.register_on(EventType.MESSAGE_CREATED)
async def on_message_(account: Account, event: Event):

    async def send_active_message(messages: dict):
        message = messages.get('message', None)
        if message:
            await account.send(event, E.quote(event.message.id).dumps() + message)

    if msg := cmd_select(event, prefix=['.']):
        rpl = await cmd_generator(message=msg, user_id=event.user.id,platform='red', message_id=event.message.id, active_send_func=send_active_message)
        if not rpl:
            pass
        else:
            modified_results = []
            for item in rpl:
                if item['type'] == 'string':
                    # 处理字符串类型的结果,可能是文本消息
                    text_message = item['string'].replace("<", "&lt;").replace(">", "&gt;")
                    modified_results.append(text_message)
                elif item['type'] == 'base64':
                    # 处理Base64编码的图像数据
                    base64_data = item['string']
                    # 将Base64数据包裹在^IMG=xxx^中并添加到文本中
                    image_tag = f'<img src="data:image/png;base64,{base64_data}"/>'

                    modified_results.append(image_tag)
            result_string = ''.join(modified_results)
            await account.send(event, E.quote(event.message.id).dumps() + result_string)

在常用的qqbot中,群号就是 channel_id
当你使用QQ号作为 user_id 时,platform 默认 red

✏️ 环境变量

Chat Tsugu Py 使用读取环境变量的方式改变一些配置

# 命令头后是否必须更上完整的空格才能匹配,例如 `查卡947` 与 `查卡 947` 。(默认值:false)
export TSUGU_COMPACT='false' 

# 设置请求超时时间(默认值:120秒)
export TSUGU_TIMEOUT=120

# 设置代理地址(默认值:空字符串)
export TSUGU_PROXY=''

# 设置后端地址(默认值:http://tsugubot.com:8080)
export TSUGU_BACKEND_URL='http://tsugubot.com:8080'

# 设置是否使用后端代理(默认值:true)
export TSUGU_BACKEND_PROXY='true'

# 设置用户数据后端地址(默认值:http://tsugubot.com:8080)
export TSUGU_USERDATA_BACKEND_URL='http://tsugubot.com:8080'

# 设置是否使用用户数据后端代理(默认值:true)
export TSUGU_USERDATA_BACKEND_PROXY='true'

# 设置是否使用简易背景(默认值:true)
export TSUGU_USE_EASY_BG='true'

# 设置是否压缩返回数据(默认值:true)
export TSUGU_COMPRESS='true'

🤖 特性

  • 为改善用户体验,本包与 koishi 插件 在部分行为上略有不同。

    • BOT 玩家状态绑定/解绑策略自验证策略
    • 基于 Alconna 的真 “可选参数” 。
  • 为了适应官方 BOT 的特性,本包提供了隐式一些非通用方法。

    • 当解除绑定用户数据库返回特定值时会被认定为安全模式,触发直接解除绑定操作。

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsugu-5.0.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

tsugu-5.0.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file tsugu-5.0.1.tar.gz.

File metadata

  • Download URL: tsugu-5.0.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for tsugu-5.0.1.tar.gz
Algorithm Hash digest
SHA256 23279d1221937ea342ab17b94fcd724f17392e9a32a12332eed555fc2c930836
MD5 df8df1cb16b180baf03b183b4578fac9
BLAKE2b-256 aa519215f70b25ec3e4ac0cd199e5b2d5bd8fdb41bbf4acff5dd8a9d477bf5fa

See more details on using hashes here.

File details

Details for the file tsugu-5.0.1-py3-none-any.whl.

File metadata

  • Download URL: tsugu-5.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for tsugu-5.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5eb4d69c29cf81ebd7b341e052d87a64d3c47391bcf852bdcd24c38d8c6da95
MD5 b619835c64192129bde474d1860330b8
BLAKE2b-256 944610d10e733d5b5989df759eff798cc8e0965d11e1111533fe3c72ec84de73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page