Skip to main content

Tsugu Python Frontend

Project description

Chat Tsugu Py tmrn

✨ 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 是一个异步方法,用于直接处理用户输入的自然语言并返回查询结果:

  • 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

❌ 同步多线程支持

  • 4.0.0 后不再支持同步多线程,因为本人用不到。实现起来很简单,本包在导入时完成了 Alconna 的初始化,避免了多线程 context 错误,因此可以在多线程中使用 tsugu,欢迎有志人士一同完善。

⚙️ api settings

安装 tsugu 后可以直接导入 tsugu_api_coresettings 修改配置项。

from tsugu_api_core import settings

...

tsugu_api settings 详细内容


Project details


Release history Release notifications | RSS feed

This version

4.1.5

Download files

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

Source Distribution

tsugu-4.1.5.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

tsugu-4.1.5-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tsugu-4.1.5.tar.gz
Algorithm Hash digest
SHA256 8a4729c59d2ea9c9542ad615b7d9659255fa47adb6de3f6ea7b974b73c735c8f
MD5 2b4a6f2363b9f8505e341c9e2e0ba97b
BLAKE2b-256 efd625fc6ce29908c07e17944fae7b0b95d7e05d5907cd08d8410bcd7e5c5f43

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tsugu-4.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ec54bc5243a2ef40ec50a5acc1930c27eebfb6a78f63eeab95fc5dcaefdfd4
MD5 f97e7a908b9ccf663ed473a2a95aee20
BLAKE2b-256 957a7521b0fef7be81fa1a3b53b24b6cdaf1d1d31467954e414fed4511372547

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