0.0.12 • Published 10 months ago
koishi-plugin-lovemilk-telemetry v0.0.12
koishi-plugin-lovemilk-telemetry
适用于 Lovemilk 系列插件的遥测插件
特别鸣谢
!IMPORTANT CyanChanges 对本项目的 BUG 修复 与 项目编写支持
EULA
使用本插件所提供服务的插件开发者必须向用户告知并在其同意 EULA 的情况下使用本插件所提供的服务
本插件的 EULA 可在 Koishi WebUI 的
/lovemilk-telemetry/EULA
路径下查看
使用方法
安装本插件
在插件市场中搜索loremilk-telemetry
并安装 或 使用如下命令进行安装 (以yarn
包管理器为例)
yarn add koishi-plugin-lovemilk-telemetry
在所需插件依赖本插件所提供的
loremilkTelemetry
服务
export const inject = [..., 'loremilkTelemetry']
合并类型
import { } from 'koishi-plugin-lovemilk-telemetry'
在
apply
中注册endpoint
export async function apply(ctx: Context, config: Config) {s
...
// config 也可以填写 ctx.config, 仅用于上报, 不做处理
// telemetryEndpoint 是 string 地址或者是 URL 对象, 如 `wss://api.lovemilk.top:5150/api/plugin/${name}/${version ?? 'null'}/telemetry`
// 其中 `${name}` 是插件名, `${version}` 是插件版本 (来着 `package.json`)
// 返回 Client 对象
const telemetryClient = ctx.lovemilkTelemetry.createClient(ctx, config, telemetryEndpoint)
...
}
!IMPORTANT 如果插件配置中含有隐私信息, 配置项名称请以
_
开头 (例如_githubToken
), 以_
开头的字段将在上报中被忽略
调用
telemetryClient.connect
函数建立 WebSocket 长链接
telemetryClient.connect()
调用
telemetryClient.send
函数发送数据
// in apply function
// name 是事件名称, 可以在 telemetry/types.ts 中查看
// data 是数据, 可以在 telemetry/types.ts 中查看
// ignoreResp? 是一个可选参数, 如果为 true, 则不等待服务端响应
// 返回 ServerResponse 或者 undefined
await telemetryClient.send(name, data, ignoreResp?))
!NOTE 本插件所提供的服务会自动处理插件注册的命令, 并上报, 无需手动发送 但是, 自动处理与开发环境的
hmr
不兼容, 重载插件请至 WebUI 手动重载或直接重启 Koishi BP 在开发环境下, 服务会每三秒自动重连, 而生产环境会遵循更复杂更适合的规则自动重连