### Basic simbot Application Setup with KOOK and QQ Channel Integration Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/README.md Demonstrates how to set up a basic simbot application, configure it to use KOOK and QQ Channel components, and register bots and event listeners. This example showcases the framework's asynchronous nature and event handling capabilities. ```Kotlin suspend fun main() { launchSimpleApplication { config() } .joinWith { module() } } fun ApplicationFactoryConfigurer<*, *, *>.config() { // 安装KOOK和QQ频道组件库 useKook() useQQGuild() } /** * 对已经构建完成的 `Application` 进行配置于应用 */ suspend fun Application.module() { registerBots() registerListeners() } /** * 注册所需的bot */ suspend fun Application.registerBots() { // ... 注册kook bot,并在此之后可处理到kook的相关事件 kookBots { register(...) { ... }.start() } // ... 注册QQ频道bot,并在此之后可处理到QQ频道的相关事件 qqGuildBots { register(...) { ... }.start() } } fun Application.registerListeners() { listeners { // 注册一个事件处理器 // ChatChannelMessageEvent 是由simbot API定义的泛用类型,代表所有子频道消息事件 // 其中就包括QQ频道的公域消息事件, 或者KOOK的频道消息事件 listen { println("context: $this") println("context.event: $event") // 返回事件处理结果 EventResult.empty() } // 再注册一个事件处理器 // 明确监听QQ频道的公域消息事件 // 使用 process 不需要返回值 process { println("context: $this") println("context.event: $event") } // 再注册一个事件处理器 // 明确监听KOOK的频道消息事件 // 使用 process 不需要返回值 process { println("context: $this") println("context.event: $event") } } } ``` -------------------------------- ### Install simbot-extension-continuous-session Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-extensions/simbot-extension-continuous-session/README.md Dependency declaration for including the continuous session extension in your Kotlin project. ```kotlin implementation("love.forte.simbot.extension:simbot-extension-continuous-session:$VERSION") ``` -------------------------------- ### Java-Friendly Suspend Function Example Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/docs/CONTRIBUTING_CN.md Illustrates how suspend functions in Kotlin can be made Java-friendly using the Kotlin Suspend Transform compiler plugin, providing a Java-compatible API. ```Kotlin // Original suspend function public suspend fun performAction(data: String): ResultType { // ... implementation ... return ResultType() } // Java-friendly counterpart (generated or manually created) // public fun performAction(data: String, callback: (ResultType) -> Unit) { // // ... implementation using coroutine scope and callback ... // } ``` -------------------------------- ### Simbot v4 Introduction and Core Features Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/README_en.md This snippet provides an overview of Simple Robot (simbot) v4, highlighting its KMP foundation, asynchronous event scheduling capabilities, and compatibility with Java and Spring Boot. It emphasizes the framework's goal of enabling faster and more efficient development of bot-style applications. ```markdown ## Summary **`Simple Robot`** v4 is a multi-platform Bot-style high- performance asynchronous event scheduling framework based on **KMP** (hereafter referred to as simbot). It provides a unified asynchronous API and easy-to-use style design, which can help you write bot-style event scheduling applications more quickly and efficiently. Currently, it is mainly used to interface with various types of bot application platforms/frameworks and provides part of the component library implementation. **`simbot4`** Developed via [Kotlin](https://kotlinlang.org/) language, Based on [KMP](https://kotlinlang.org/docs/multiplatform.html) for multi-platform support, and compatible with Java (**jdk11+**) and other JVM platform languages. And provides a lot of Java-friendly API and Spring Boot starter, to help you quickly develop . This repository is the repository for simbot v3 and v4, containing the definition of the simbot standard API, the implementation of the simbot core libraries, and the implementation of the Spring Boot starter and other core and basic content. > [!tip] > Visit the [GitHub Organisation Home](https://github.com/simple-robot/) > to learn more about the components, documentation, community and more! ## 文档 simbot4 reference documentation: [simbot.forte.love][doc-homepage] > [!note] > Also includes document address guides for previous versions Documentation Bootstrap & API Doc: [docs.simbot.forte.love](https://docs.simbot.forte.love) ## V3 Branch to [v3-dev](https://github.com/simple-robot/simpler-robot/tree/v3-dev) to see the development branch of simbot3. ``` -------------------------------- ### API Documentation Generation with Dokka Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/docs/CONTRIBUTING_CN.md Information on using Dokka to generate API documentation from source code comments, referencing the KDoc standards for detailed documentation. ```APIDOC Dokka: Description: A documentation generator for Kotlin projects. Usage: Generates API documentation from source code comments (KDoc). Configuration: Can be configured via Gradle or Maven plugins. Related: Kotlin Documentation Commenting Standards (KDoc) ``` -------------------------------- ### Kotlin Documentation Commenting Standards (KDoc) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/docs/CONTRIBUTING_CN.md Guidelines for writing documentation comments in Kotlin code, including which elements to document, language for comments, and standard tags like @param and @author. ```Kotlin /** * This is a detailed documentation comment for a public function. * It explains the purpose, parameters, and return value. * * @param paramName Description of the parameter. * @return Description of the return value. * @throws ExceptionType Description of when this exception is thrown. */ public fun myFunction(paramName: String): String { // function implementation return "result" } ``` -------------------------------- ### Simbot Documentation Links Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/README_en.md This snippet provides links to the official simbot documentation, including the main reference documentation and API documentation. It also mentions the availability of documentation for previous versions. ```markdown ## 文档 simbot4 reference documentation: [simbot.forte.love][doc-homepage] > [!note] > Also includes document address guides for previous versions Documentation Bootstrap & API Doc: [docs.simbot.forte.love](https://docs.simbot.forte.love) ``` -------------------------------- ### Add Developer Information in Kotlin Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/docs/CONTRIBUTING_CN.md This snippet shows how to add your developer information to the `P.kt` file in the `buildSrc` directory, which is used to configure project participants. ```Kotlin override val developers: List = developers { developer { ... } ... 此处添加您的信息 } ``` -------------------------------- ### Continuous Session Event Handling Logic Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-extensions/simbot-extension-continuous-session/README.md Illustrates the core logic for handling events within a continuous session. It shows how to obtain a session provider, push events to it, and receive results that dictate further processing. ```kotlin suspend fun inSession(event: Event, sessionContext: ContinuousSessionContext): EventResult { val key: ... // 字符串?还是 object? val sessionProvider = sessionContext.session(key) { // this: sessionReceiver // 异步中、可挂起 val e = await { it.toResult() } // event } // 向会话推送,然后得到一个结果? // 比如 // 不符合预期的结果 invalid // 成功的空结果 empty // 需要阻断后续事件处理的结果 truncate = true val result: EventResult = sessionProvider.push(event) // 主要逻辑在 session 中,这里只需要返回结果 return result } ``` -------------------------------- ### Kotlin Class to Builder Generation Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-processors/class-builder/README.md Demonstrates the transformation of a simple Kotlin data class into a corresponding builder class using the simbot-processor-class-builder. It shows how non-null properties are handled and the structure of the generated builder. ```kotlin class Person( val name: String, val age: Int ) { var size: Int? = null } ``` ```kotlin @BuilderFor(Person::class) class PersonBuilder { private lateinit var name: String private var age: Int by kotlin.properties.Delegates.notNull() private var size: Int? = null public fun name(name: String): PersonBuilder = apply { this.name = name } // other functions... public fun build(): Person { return Person( name = name, age = age, ).also { size?.also { p0 -> it.size = p0 } } } } ``` -------------------------------- ### Native Logging Implementation (println) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-logger/README.md On native targets, simbot-logger implements logging through simple standard output using Kotlin's println function, ensuring basic logging capabilities in compiled native applications. ```kotlin object NativeLogger { fun logInfo(message: String) { println(message) } } ``` -------------------------------- ### InputFile for Ktor Client File Uploads Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-commons/simbot-common-ktor-inputfile/README.md This module provides the `InputFile` type and associated extension and factory methods to simplify the process of sending local files as `MultiPartFormDataContent` with Ktor Client. On JVM, it supports construction from `java.io.File` and `java.nio.file.Path`. The dependency on `ktor-client-core` is compile-only on JVM. ```kotlin import io.ktor.client.request.* import io.ktor.client.request.forms.* import io.ktor.http.* import java.io.File import java.nio.file.Path // Example usage (conceptual, actual implementation details would be within the library): // Assuming InputFile is defined and has factory methods like: // fun InputFile(file: File): InputFile // fun InputFile(path: Path): InputFile // val fileToUpload: File = File("path/to/your/file.txt") // val inputFile: InputFile = InputFile(fileToUpload) // val pathToFile: Path = Paths.get("path/to/another/file.jpg") // val inputFileFromPath: InputFile = InputFile(pathToFile) // client.post("your_upload_url") { // setBody(MultiPartFormDataContent(formData { // append("file", inputFile, ContentType.Application.OctetStream) // })) // } ``` -------------------------------- ### Kotlin Code Style Conventions Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/docs/CONTRIBUTING_CN.md Common code style conventions for Kotlin projects, including spacing around operators, variable declarations, function parameters, and handling multi-line function parameters with annotations. ```Kotlin a += b // Space around operator a: Int // Space after colon foo(1, 2) // Space after comma in function call function name(a: Int, b: Int) // Space after comma in function definition function name( p1: Int, @Anno2 @Anno1 p2: String ) // Multi-line parameters with alignment and annotations ``` -------------------------------- ### Simbot v3 Development Branch Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/README_en.md This snippet directs users to the v3-dev branch of the repository for accessing the development version of simbot3. ```markdown ## V3 Branch to [v3-dev](https://github.com/simple-robot/simpler-robot/tree/v3-dev) to see the development branch of simbot3. ``` -------------------------------- ### SimbotLoggerConfiguration Reference Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-logger-slf4j2-impl/README.md Provides details on available configuration options for the simbot-logger SLF4J implementation. This Kotlin class outlines the properties and their meanings for customizing logger behavior. ```kotlin src/main/kotlin/love/forte/simbot/logger/slf4j2/SimbotLoggerConfiguration.kt ``` -------------------------------- ### KSP Processor Configuration Options Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-processors/simbot-processor-message-element-polymorphic-include/README.md Configuration options for the `simbot.processor.message-element-polymorphic-include` KSP processor. These options allow customization of the processor's behavior, such as enabling it, specifying the base class, controlling visibility, and defining output file details. ```properties ksp { // 是否启用 arg("simbot.processor.message-element-polymorphic-include.enable", "true") arg("simbot.processor.message-element-polymorphic-include.localOnly", "false") arg("simbot.processor.message-element-polymorphic-include.baseClass", "love.forte.simbot.message.Message.Element") arg("simbot.processor.message-element-polymorphic-include.visibility", "internal") // 默认 internal 可选: public, internal arg("simbot.processor.message-element-polymorphic-include.generateFunName", "includeMessageElementPolymorphic") arg("simbot.processor.message-element-polymorphic-include.outputPackage", "love.forte.simbot.message") // 默认为 null,如果不提供(不是空字符串哦)则与 baseClass 同包 arg("simbot.processor.message-element-polymorphic-include.outputFileName", "MessageElementPolymorphicInclude.generated") arg("simbot.processor.message-element-polymorphic-include.outputFileJvmName", "") // 默认 null arg("simbot.processor.message-element-polymorphic-include.outputFileJvmMultifile", "false") // 默认 false } ``` -------------------------------- ### JVM Logging Implementation (slf4j-api) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-logger/README.md On the JVM platform, simbot-logger delegates logging to slf4j-api. However, it does not provide an implementation for slf4j-api itself. Therefore, an additional slf4j-api implementation must be included, or the simbot-logger-slf4j-impl can be used. ```kotlin import org.slf4j.LoggerFactory object JvmLogger { private val logger = LoggerFactory.getLogger(JvmLogger::class.java) fun logInfo(message: String) { logger.info(message) } } ``` ```java import org.slf4j.LoggerFactory; import org.slf4j.Logger; public class JvmLogger { private static final Logger logger = LoggerFactory.getLogger(JvmLogger.class); public static void logInfo(String message) { logger.info(message); } } ``` -------------------------------- ### LGPLv3 License Text Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/README_en.md The full text of the GNU Lesser General Public License version 3, under which the Simple Robot project is distributed. ```text This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Continuous Session Context API Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-extensions/simbot-extension-continuous-session/README.md Defines the interface for interacting with a continuous session context, allowing for session retrieval and event pushing. ```APIDOC ContinuousSessionContext: session(key: Any, block: suspend SessionReceiver.() -> Unit): SessionProvider key: A unique identifier for the session. block: A suspend lambda that defines the session's behavior, including awaiting events. Returns: A SessionProvider to interact with the session. SessionProvider: push(event: Event): EventResult event: The event to push into the session. Returns: The result of processing the event within the session. EventResult: Represents the outcome of processing an event within a session. Possible values include: - invalid: The event is not valid for the current session state. - empty: The event was processed successfully, but no further action is needed. - truncate = true: The event was processed successfully, and subsequent event processing should be halted. SessionReceiver: await(predicate: (Event) -> Result): Event predicate: A function to filter and process incoming events. Returns: The awaited event that satisfies the predicate. ``` -------------------------------- ### Simbot Logger SLF4J Configuration Properties Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-logger-slf4j2-impl/README.md Defines logging levels and dispatcher modes for the simbot-logger SLF4J implementation. Supports global levels, package-specific levels, and console-specific levels. The dispatcher setting controls the logging thread management. ```properties # level 为默认全局等级 level=DEBUG # 代表前缀为 love.forte.foo1 的日志等级为 TRACE level.love.forte.foo1=TRACE # 代表 **控制台输出的日志** 前缀为 love.forte.foo2 时等级为 INFO。 # 某个特定的处理器(例如此处的 console 日志处理器)优先级高于全局配置。 console.level.love.forte.foo2=INFO # 日志处理的调度模式 # 默认:基于 disruptor 的高性能异步调度 dispatcher=DISRUPTOR # 或:同步处理,非异步 # dispatcher=SYNC # 或:普通的基于线程池的异步处理 # dispatcher=ASYNC ``` -------------------------------- ### JS Logging Implementation (console API) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-logger/README.md For the JavaScript platform, simbot-logger utilizes the browser's console API for logging output, providing a familiar interface for web development. ```javascript object JsLogger { fun logInfo(message: String) { console.info(message) } } ``` -------------------------------- ### Random ID Generation Performance Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/PERFORMANCE_TESTING.md Compares the performance of `randomID()` against `UUID.randomUUID` and different random number generators (`kotlin.Random.Default` vs. `ThreadLocalRandom`). The benchmarks were run using JMH version 1.33 on JDK 1.8.0_332. ```benchmark Benchmark Mode Cnt Score Error Units IdTest.randomIdByDefaultGenerate thrpt 25 70801412.214 ± 1498689.005 ops/s IdTest.randomIdByThreadLocalRandomGenerate thrpt 25 66505118.175 ± 730902.232 ops/s IdTest.randomUUIDGenerate thrpt 25 1435474.691 ± 39339.236 ops/s ``` -------------------------------- ### Time Duration Conversion Performance (JDK 17) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/PERFORMANCE_TESTING.md Evaluates the efficiency of converting time durations between `kotlin.time.Duration`, `java.time.Duration`, and `java.util.concurrent.TimeUnit` on JDK 17.0.3. The tests measure operations per millisecond for milli-to-second and second-to-milli conversions. ```benchmark Benchmark Mode Cnt Score Error Units DurationTest.MilliToSecond thrpt 2 355646.441 ops/ms DurationTest.MilliToSecond:javaDurationMilliToSecond thrpt 2 211252.355 ops/ms DurationTest.MilliToSecond:ktDurationMilliToSecond thrpt 2 42129.351 ops/ms DurationTest.MilliToSecond:timeUnitMilliToSecond thrpt 2 102264.734 ops/ms DurationTest.SecondToMilli thrpt 2 554247.894 ops/ms DurationTest.SecondToMilli:javaDurationSecondToMilli thrpt 2 223422.624 ops/ms DurationTest.SecondToMilli:ktDurationSecondToMilli thrpt 2 42339.539 ops/ms DurationTest.SecondToMilli:timeUnitSecondToMilli thrpt 2 288485.731 ops/ms ``` -------------------------------- ### Time Duration Conversion Performance (JDK 8) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/PERFORMANCE_TESTING.md Evaluates the efficiency of converting time durations between `kotlin.time.Duration`, `java.time.Duration`, and `java.util.concurrent.TimeUnit` on JDK 1.8.0_332. The tests measure operations per millisecond for milli-to-second and second-to-milli conversions. ```benchmark Benchmark Mode Cnt Score Error Units DurationTest.MilliToSecond thrpt 2 501943.887 ops/ms DurationTest.MilliToSecond:javaDurationMilliToSecond thrpt 2 173481.768 ops/ms DurationTest.MilliToSecond:ktDurationMilliToSecond thrpt 2 107571.847 ops/ms DurationTest.MilliToSecond:timeUnitMilliToSecond thrpt 2 220890.272 ops/ms DurationTest.SecondToMilli thrpt 2 536347.374 ops/ms DurationTest.SecondToMilli:javaDurationSecondToMilli thrpt 2 212098.647 ops/ms DurationTest.SecondToMilli:ktDurationSecondToMilli thrpt 2 104243.386 ops/ms DurationTest.SecondToMilli:timeUnitSecondToMilli thrpt 2 220005.341 ops/ms ``` -------------------------------- ### Duration Conversion Performance (JDK 17) Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/PERFORMANCE_TESTING.md Measures the performance of converting `java.time.Duration` and `TimeUnit` to `kotlin.time.Duration` on JDK 17.0.2. The benchmarks focus on conversions for minutes and seconds. ```benchmark Benchmark Mode Cnt Score Error Units DurationConvertTest.MinutesDuration thrpt 447133.994 ops/ms DurationConvertTest.MinutesDuration:javaMinutesDuration thrpt 76914.765 ops/ms DurationConvertTest.MinutesDuration:javaMinutesDurationSimbot thrpt 103878.816 ops/ms DurationConvertTest.MinutesDuration:minutesTimeUnit thrpt 266340.413 ops/ms DurationConvertTest.SecondsDuration thrpt 533031.432 ops/ms DurationConvertTest.SecondsDuration:javaSecondsDuration thrpt 77124.192 ops/ms DurationConvertTest.SecondsDuration:javaSecondsDurationSimbot thrpt 106764.854 ops/ms DurationConvertTest.SecondsDuration:secondsTimeUnit thrpt 349142.386 ops/ms ``` -------------------------------- ### K2 Feature Enable/Disable Time Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/PERFORMANCE_TESTING.md Records the time taken to enable and disable the K2 feature. This provides a simple measurement of the operational time for these two states. ```measurement enable: 1m 3s disable: 1m 57s ``` -------------------------------- ### Generate Polymorphic Include Function Source: https://github.com/simple-robot/simpler-robot/blob/v4-main/simbot-processors/simbot-processor-message-element-polymorphic-include/README.md Generates a Kotlin function that includes polymorphic subclasses for `Message.Element`. This function is typically used within a `PolymorphicModuleBuilder` to register serialization information for various message element types. ```kotlin internal fun PolymorphicModuleBuilder.includeElements() { subclass(...) subclass(...) subclass(...) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.