Skip to content

entanex/koishi-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koishi-python

在 python 下运行 koishi 的实例

安装

pip install "koishi-python @ git+https://github.com/koishipy/koishi-python"

使用

from koishi import Context

ctx = Context({})

ctx.requires(
    "@koishijs/plugin-console",
    "@koishijs/plugin-sandbox",
    "@koishijs/plugin-server",
    config="koishi.yml",
)

ctx.command("echo <message:text>", "输出收到的信息", {"checkArgCount": True})\
    .action(lambda _, __, *args: args[0])

ctx.run()

config 指向 Koishi 配置文件。ctx.requires() 会读取其中的 plugins,并按 Koishi 的插件短名称匹配传入的 npm 包名。

# koishi.yml
plugins:
  console:
  sandbox:
  server:
    port: 5140

插件组、插件别名和 ~ 禁用前缀同样按 Koishi 配置格式解析;ctx.requires() 中仍需传入待安装的 npm 包名。

注意事项

  1. ctx.requires() 声明的 npm 包会先统一写入生成的 package.json,再通过一次 Yarn 安装
  2. 运行时内置 .yarn/releases/yarn-4.17.1.cjs,并在 .yarnrc.yml 中通过 yarnPath 固定使用它;用户环境只需提供 Node.js,无需安装 Yarn 或 Corepack。
  3. 目前默认安装 Koishi 和插件的最新版本;ctx.require() 仍可通过 version 指定版本。
  4. koishi 会在运行目录下建立 node_modulespackage.jsonyarn.lock.yarn.yarnrc.yml 的软链接;JavaScript 模块仍由 JSPyBridge 直接加载,不再生成额外入口文件。
  5. JSPyBridge 目前仍可能输出 property r/ffid is not registered 警告;该警告不影响 Koishi 启动。

About

Run Koishi in python

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 98.7%
  • Python 1.3%