Skip to content

Latest commit

 

History

History
120 lines (101 loc) · 3.56 KB

README.md

File metadata and controls

120 lines (101 loc) · 3.56 KB
simbot logo

~ Simple Robot ~
Kritor Component

release release
stars forks watchers repo size issues last commit copying

Simple Robot Kritor 组件是一个将 Kritor 协议在 Simple Robot 标准API下实现的组件库, 并由此提供simbot中的各项能力。

Caution

WIP now.

使用

文档

Examples

使用simbot核心库

val application = launchSimpleApplication {
    useKritor() // 安装使用Kritor组件库
}

application.kritorBots {
    // 注册bot并启动
    retister(account = "", ticket = "") {
        // config...
    }.also { it.start() }
}

// 注册事件处理器
application.listeners {
    // 处理事件 ChatGroupMessageEvent
    // 这是simbot API定义的泛用类型
    process<ChatGroupMessageEvent> {
        // ...
    }

    // 指定处理 Kritor 组件内定义的各事件类型
    // 比如此处的 Kritor 群消息事件
    // Tips: KritorGroupMessageEvent 继承实现 ChatGroupMessageEvent
    process<KritorGroupMessageEvent> { event ->
        // 基于事件回复消息
        event.reply("Hello, ")
        // 基于 Group 实例发送消息
        event.content().send(Text { "World!" })
    }
}

使用Spring Boot starter

配置信息:

{
  "component": "simbot.kritor",
  "auth": {
    "account": "",
    "ticket": "",
    "channel": {
        "type": "address",
        "name": "localhost",
        "port": 8080
    }
  },
  "config": {
  }
}
@SpringBootApplication
@EnableSimbot // 启动simbot
class MainApp

// 默认配置下,simbot会自动扫描并加载配置的bot信息,
// 并默认地自动启动它们

fun main(args: Array<String>) {
    runApplication<MainApp>(*args)
}

/** 一些事件处理器的载体 */
@Component
class MyHandler {
    /** 监听处理 kritor 的群消息事件 */
    @Listener
    suspend fun onMessage(event: KritorGroupMessageEvent) {
        // 基于事件回复消息
        event.reply("Hello, ")
        // 基于 Group 实例发送消息
        event.content().send(Text { "World!" })
    }
}