
Attachable to existing server instances, supports reverse WebSocket connections with multiple clients, modular imports to minimize footprint, and simple OneBot SDK integration.
LoliOneBot 是一个使用 KMP 实现的轻量 OneBot SDK
项目处于早期阶段, 可能会出现大幅度重构
🟩 应用层 (作为客户端连接OneBot实现)
🟩 服务层 (作为OneBot实现被客户端连接)
repositories {
mavenCentral()
}
dependencies {
// 把 ${version} 替换成最新版本
// 应用端 (大部分接入 OneBot 生态的应用)
implementation("io.github.cryptloli:loli-onebot-client:${version}")
implementation("io.github.cryptloli:loli-onebot-client-network-forward-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-client-network-reverse-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-kotlin-dsl:${version}")
// 实现端 (负责给 OneBot 生态应用提供服务的协议/hook适配端)
implementation("io.github.cryptloli:loli-onebot-server:${version}")
implementation("io.github.cryptloli:loli-onebot-server-network-forward-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-server-network-reverse-ws:${version}")
// forward-ws, 需要一个 ktor client 引擎
// https://ktor.io/docs/client-engines.html
implementation("io.ktor:ktor-client-java:${ktorVersion}")
// reverse-ws, 需要一个 ktor server 引擎
// https://ktor.io/docs/server-engines.html
implementation("io.ktor:ktor-server-cio:${ktorVersion}")
}这是一个简单的示范 适用于 kotlin/jvm
// reverse-ws
suspend fun main(vararg args: String) {
LoliOneBotClientReverseWS(object : OneBotWSReverseListener {
override suspend fun onAnyEvent(event: OneBotEvent) {
if (event is OneBotPrivateMessageEvent && event.rawMessage == "/ping") {
event.reply("Pong~")
}
}
}).createWSServerAndStart(CIO)
awaitCancellation()
}
// forward-ws
suspend fun main(vararg args: String) {
LoliOneBotClientForwardWS(object : OneBotWSReverseListener {
override suspend fun onAnyEvent(event: OneBotEvent) {
if (event is OneBotPrivateMessageEvent && event.rawMessage == "/ping") {
event.reply("Pong~")
}
}
}, "ws://localhost:6700/").connect(await = true)
}Q: 为什么必须手动添加一个 ktor 引擎?
A: 为了为使用者让出更大的自由空间
如果你发现了 bug 或者需要新的功能, 你可以创建一个新的 issue
我们也欢迎您提交 pull request
LoliOneBot 是一个使用 KMP 实现的轻量 OneBot SDK
项目处于早期阶段, 可能会出现大幅度重构
🟩 应用层 (作为客户端连接OneBot实现)
🟩 服务层 (作为OneBot实现被客户端连接)
repositories {
mavenCentral()
}
dependencies {
// 把 ${version} 替换成最新版本
// 应用端 (大部分接入 OneBot 生态的应用)
implementation("io.github.cryptloli:loli-onebot-client:${version}")
implementation("io.github.cryptloli:loli-onebot-client-network-forward-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-client-network-reverse-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-kotlin-dsl:${version}")
// 实现端 (负责给 OneBot 生态应用提供服务的协议/hook适配端)
implementation("io.github.cryptloli:loli-onebot-server:${version}")
implementation("io.github.cryptloli:loli-onebot-server-network-forward-ws:${version}")
implementation("io.github.cryptloli:loli-onebot-server-network-reverse-ws:${version}")
// forward-ws, 需要一个 ktor client 引擎
// https://ktor.io/docs/client-engines.html
implementation("io.ktor:ktor-client-java:${ktorVersion}")
// reverse-ws, 需要一个 ktor server 引擎
// https://ktor.io/docs/server-engines.html
implementation("io.ktor:ktor-server-cio:${ktorVersion}")
}这是一个简单的示范 适用于 kotlin/jvm
// reverse-ws
suspend fun main(vararg args: String) {
LoliOneBotClientReverseWS(object : OneBotWSReverseListener {
override suspend fun onAnyEvent(event: OneBotEvent) {
if (event is OneBotPrivateMessageEvent && event.rawMessage == "/ping") {
event.reply("Pong~")
}
}
}).createWSServerAndStart(CIO)
awaitCancellation()
}
// forward-ws
suspend fun main(vararg args: String) {
LoliOneBotClientForwardWS(object : OneBotWSReverseListener {
override suspend fun onAnyEvent(event: OneBotEvent) {
if (event is OneBotPrivateMessageEvent && event.rawMessage == "/ping") {
event.reply("Pong~")
}
}
}, "ws://localhost:6700/").connect(await = true)
}Q: 为什么必须手动添加一个 ktor 引擎?
A: 为了为使用者让出更大的自由空间
如果你发现了 bug 或者需要新的功能, 你可以创建一个新的 issue
我们也欢迎您提交 pull request