llms.txt: machine-readable documentation index. Markdown version of this page is also available.

Simple Robot 5.x Help

Application

Application 是对一组注册的组件和插件们的统一运行环境。 组件和插件们总要依附在一个 Application 上。

simbot-core 模块提供了一个简单的普通实现: SimpleApplication, 下文将会以这个简单的普通实现为例进行说明。

创建与启动

启动时可用 config 设置应用选项,用 eventDispatcher 配置事件调度器, 并通过 install(...) 安装组件和插件。

launchApplication 接收应用工厂。核心库提供 Simple 工厂。

val app = launchApplication(Simple) { config { coroutineContext = Dispatchers.Default } eventDispatcher { addInterceptor { invoke() } addDispatchInterceptor { invoke() } } }

也可以把同样的配置传给 launchSimpleApplication { ... }。

在 Java 中使用 Simple.INSTANCE 作为应用工厂。

var applicationAsync = Applications.launchApplicationAsync(Simple.INSTANCE, appConfigurer -> { appConfigurer.config(config -> config.setCoroutineContext(Dispatchers.getDefault())); appConfigurer.eventDispatcher(config -> config.addInterceptor(EventInterceptors.async(context -> context.invoke()))); }); var future = applicationAsync.asFuture();
var application = Applications.launchApplicationBlocking(Simple.INSTANCE, appConfigurer -> { appConfigurer.config(config -> config.setCoroutineContext(Dispatchers.getDefault())); appConfigurer.eventDispatcher(config -> config.addInterceptor(EventInterceptors.block(context -> context.invoke()))); });
var applicationAsync = Applications.launchApplicationAsync(Simple.INSTANCE, appConfigurer -> { appConfigurer.config(config -> config.setCoroutineContext(Dispatchers.getDefault())); appConfigurer.eventDispatcher(config -> config.addInterceptor(EventInterceptors.async(context -> context.invoke()))); }); Mono.fromFuture(applicationAsync.asFuture()) .flatMap(app -> Mono.from(app.joinReactive())) .block();

构建完 Application 便可以开始注册事件处理器和 Bot 了。

取消与等待结束

调用 application.cancel() 或 application.cancel(reason) 终止应用。 核心库与 Spring Boot starter 的实现依次触发:

  1. ApplicationLaunchStage.RequestCancel :在取消应用的 Job 前执行。

  2. 取消应用的 Job, isActive 变为 false。

  3. ApplicationLaunchStage.Cancelled :在发起任务取消后、 cancel() 返回前执行。

阶段处理器应快速完成,避免长时间阻塞。直接取消 coroutineContext 中的 Job 不会触发这些阶段处理器。 Cancelled 触发时子任务可能仍在结束过程中;等待应用完全结束使用 join(), 也可以通过 isCompleted 或 onCompletion 感知完成状态。

application.cancel() application.join()

拦截器管理

每个应用持有一个 InterceptorManager ,应用安装的插件也能通过配置上下文取得这个管理器。用它可以注册、查询和注销 通用拦截器 ,例如为应用注册 消息发送拦截器。

事件调度和事件监听器的拦截器通过 事件调度器配置 或监听器的注册属性添加。

事件处理器的注册

有关事件处理器的相关描述可前往 事件监听与处理 章节阅读。

Bot的注册

有关Bot注册的相关描述可前往 Bot管理器 章节阅读。

19 November 2026