├── .editorconfig ├── .fleet └── settings.json ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── doc.yml │ └── report.yml ├── dependabot.yml ├── release.yml └── workflows │ ├── deploy-website.yml │ ├── publish-kdoc.yml │ ├── publish-release.yml │ ├── publish-snapshot.yml │ ├── qodana_code_quality.yml │ ├── test-branch-website.yml │ └── test-branch.yml ├── .gitignore ├── .idea └── .gitignore ├── .run ├── detekt.run.xml └── simbot-component-onebot [publishToMavenLocal].run.xml ├── .simbot ├── dokka-assets │ ├── css │ │ └── kdoc-style.css │ ├── logo-icon-light.svg │ └── logo-icon.svg ├── dokka-templates │ └── includes │ │ └── page_metadata.ftl ├── jetbrains.svg ├── logo-dark.svg └── logo.svg ├── CONTRIBUTING.md ├── COPYING ├── COPYING.LESSER ├── README.md ├── Writerside ├── c.list ├── cfg │ ├── buildprofiles.xml │ ├── glossary.xml │ └── head-script.html ├── images │ ├── logo-icon-dark.svg │ └── logo-icon.svg ├── ob.tree ├── topics │ ├── Home.md │ ├── OneBot11.md │ ├── modules.md │ ├── onebot11-OneBotBot.md │ ├── onebot11-OneBotFriend.md │ ├── onebot11-OneBotGroup.md │ ├── onebot11-OneBotMember.md │ ├── onebot11-actors.md │ ├── onebot11-bot-config.md │ ├── onebot11-event.md │ ├── onebot11-message.md │ ├── onebot11-quick-start.md │ ├── snippets.md │ ├── suspend-API-transform.md │ └── use-onebot11.md ├── v.list └── writerside.cfg ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── DokkaConfigs.kt │ ├── Env.kt │ ├── JVMConstants.kt │ ├── JsConfig.kt │ ├── JvmConfig.kt │ ├── P.kt │ ├── R.kt │ ├── simbot-onebot-changelog-generator.gradle.kts │ ├── simbot-onebot-dokka-multi-module.gradle.kts │ ├── simbot-onebot-dokka-partial-configure.gradle.kts │ ├── simbot-onebot-multiplatform-maven-publish.gradle.kts │ ├── simbot-onebot-nexus-publish.gradle.kts │ └── util │ ├── PropUtil.kt │ └── PublishConfigurableUtil.kt ├── config └── detekt │ └── detekt.yml ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── internal-processors ├── event-type-resolver-processor │ ├── README.md │ ├── build.gradle.kts │ └── src │ │ └── main │ │ ├── kotlin │ │ └── onebot11 │ │ │ └── internal │ │ │ └── processors │ │ │ └── eventtyperesolver │ │ │ └── EventTypeResolverProcessor.kt │ │ └── resources │ │ └── META-INF │ │ └── services │ │ └── com.google.devtools.ksp.processing.SymbolProcessorProvider └── include-component-message-elements-processor │ ├── README.md │ ├── build.gradle.kts │ └── src │ └── main │ ├── kotlin │ └── onebot11 │ │ └── internal │ │ └── processors │ │ └── includemessageelements │ │ └── IncludeMessageElementsProcessor.kt │ └── resources │ └── META-INF │ └── services │ └── com.google.devtools.ksp.processing.SymbolProcessorProvider ├── kotlin-js-store └── yarn.lock ├── qudana.yaml ├── settings.gradle.kts ├── simbot-component-onebot-common ├── api │ └── simbot-component-onebot-common.api ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── common │ │ ├── OneBot.kt │ │ ├── annotations │ │ ├── ApiOpts.kt │ │ ├── ComponentOpts.kt │ │ ├── EventOpts.kt │ │ └── Marks.kt │ │ └── component │ │ └── OneBotComponent.kt │ └── jvmMain │ └── java │ └── module-info.java └── simbot-component-onebot-v11 ├── simbot-component-onebot-v11-common ├── api │ └── simbot-component-onebot-v11-common.api ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── v11 │ │ └── common │ │ ├── api │ │ └── StatusResult.kt │ │ └── utils │ │ └── AvatarUtil.kt │ └── jvmMain │ └── java │ └── module-info.java ├── simbot-component-onebot-v11-core ├── api │ └── simbot-component-onebot-v11-core.api ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── v11 │ │ └── core │ │ ├── OneBot11.kt │ │ ├── OneBot11Usage.kt │ │ ├── actor │ │ ├── OneBotFriend.kt │ │ ├── OneBotGroup.kt │ │ ├── OneBotMember.kt │ │ ├── OneBotRole.kt │ │ ├── OneBotStranger.kt │ │ ├── OneBotStrangerAware.kt │ │ ├── SendLikeSupport.kt │ │ └── internal │ │ │ ├── AbstractSendSupport.kt │ │ │ ├── OneBotFriendImpl.kt │ │ │ ├── OneBotGroupImpl.kt │ │ │ ├── OneBotMemberImpl.kt │ │ │ └── OneBotStrangerImpl.kt │ │ ├── api │ │ ├── CanSendImageApi.kt │ │ ├── CanSendRecordApi.kt │ │ ├── CleanCacheApi.kt │ │ ├── DeleteMsgApi.kt │ │ ├── GetCookiesApi.kt │ │ ├── GetCredentialsApi.kt │ │ ├── GetCsrfTokenApi.kt │ │ ├── GetForwardMsgApi.kt │ │ ├── GetFriendListApi.kt │ │ ├── GetGroupHonorInfoApi.kt │ │ ├── GetGroupInfoApi.kt │ │ ├── GetGroupListApi.kt │ │ ├── GetGroupMemberInfoApi.kt │ │ ├── GetGroupMemberListApi.kt │ │ ├── GetImageApi.kt │ │ ├── GetLoginInfoApi.kt │ │ ├── GetMsgApi.kt │ │ ├── GetRecordApi.kt │ │ ├── GetStatusApi.kt │ │ ├── GetStrangerInfoApi.kt │ │ ├── GetVersionInfoApi.kt │ │ ├── OneBotApi.kt │ │ ├── OneBotApiExecutable.kt │ │ ├── OneBotApiRequests.kt │ │ ├── OneBotMessageOutgoing.kt │ │ ├── SendGroupMsgApi.kt │ │ ├── SendLikeApi.kt │ │ ├── SendMsgApi.kt │ │ ├── SendPrivateMsgApi.kt │ │ ├── SetFriendAddRequestApi.kt │ │ ├── SetGroupAddRequestApi.kt │ │ ├── SetGroupAdminApi.kt │ │ ├── SetGroupAnonymousApi.kt │ │ ├── SetGroupAnonymousBanApi.kt │ │ ├── SetGroupBanApi.kt │ │ ├── SetGroupCardApi.kt │ │ ├── SetGroupKickApi.kt │ │ ├── SetGroupLeaveApi.kt │ │ ├── SetGroupNameApi.kt │ │ ├── SetGroupSpecialTitleApi.kt │ │ ├── SetGroupWholeBanApi.kt │ │ ├── SetRestartApi.kt │ │ └── exceptions.kt │ │ ├── bot │ │ ├── OneBotBot.kt │ │ ├── OneBotBotConfiguration.kt │ │ ├── OneBotBotManager.kt │ │ ├── OneBotBotManagerUsage.kt │ │ ├── OneBotBotRequests.kt │ │ ├── OneBotBotSerializableConfiguration.kt │ │ └── internal │ │ │ ├── OneBotBotImpl.kt │ │ │ ├── OneBotBotManagerImpl.kt │ │ │ └── RawEventResolveResultImpl.kt │ │ ├── component │ │ ├── OneBot11Component.kt │ │ └── OneBot11ComponentUsage.kt │ │ ├── event │ │ ├── CustomEventResolveException.kt │ │ ├── CustomEventResolver.kt │ │ ├── CustomKotlinSerializationEventResolver.kt │ │ ├── EventResolveException.kt │ │ ├── ExperimentalCustomEventResolverApi.kt │ │ ├── OneBotEvent.kt │ │ ├── OneBotInternalEvent.kt │ │ ├── OneBotUnknownEvent.kt │ │ ├── OneBotUnsupportedEvent.kt │ │ ├── RawEventResolveResult.kt │ │ ├── internal │ │ │ ├── OneBotEventImpls.kt │ │ │ ├── message │ │ │ │ ├── OneBotGroupMessageEventImpl.kt │ │ │ │ └── OneBotPrivateMessageEventImpl.kt │ │ │ ├── messageinteraction │ │ │ │ ├── AbstractInteractionEventImpls.kt │ │ │ │ ├── AbstractReplySupportInteractionEvent.kt │ │ │ │ ├── AnonymousGroupMsgInteractionEventImpls.kt │ │ │ │ ├── DefaultGroupMsgInteractionEventImpls.kt │ │ │ │ ├── DefaultPrivateMsgInteractionEventImpls.kt │ │ │ │ ├── FriendInteractionEventImpls.kt │ │ │ │ ├── FriendMsgInteractionEventImpls.kt │ │ │ │ ├── GroupInteractionEventImpls.kt │ │ │ │ ├── MemberInteractionEventImpls.kt │ │ │ │ ├── NormalGroupMsgInteractionEventImpls.kt │ │ │ │ ├── NoticeGroupMsgInteractionEventImpls.kt │ │ │ │ └── PrivateMsgInteractionEventImpls.kt │ │ │ ├── meta │ │ │ │ └── OneBotMetaEventImpl.kt │ │ │ ├── notice │ │ │ │ ├── OneBotFriendAddEventImpl.kt │ │ │ │ ├── OneBotFriendRecallEventImpl.kt │ │ │ │ ├── OneBotGroupAdminEventImpl.kt │ │ │ │ ├── OneBotGroupBanEventImpl.kt │ │ │ │ ├── OneBotGroupChangeEventImpl.kt │ │ │ │ ├── OneBotGroupRecallEventImpl.kt │ │ │ │ ├── OneBotGroupUploadEventImpl.kt │ │ │ │ └── OneBotNotifyEventImpl.kt │ │ │ ├── request │ │ │ │ └── OneBotRequestEventImpl.kt │ │ │ └── stage │ │ │ │ └── OneBotBotStageEventImpl.kt │ │ ├── message │ │ │ ├── OneBotGroupMessageEvent.kt │ │ │ ├── OneBotMessageEvent.kt │ │ │ └── OneBotPrivateMessageEvent.kt │ │ ├── messageinteraction │ │ │ ├── OneBotInternalMessageInteractionEvent.kt │ │ │ ├── OneBotMessageEventInteractionEvent.kt │ │ │ ├── OneBotSegmentsInteractionMessage.kt │ │ │ └── OneBotSendSupportInteractionEvent.kt │ │ ├── meta │ │ │ ├── OneBotHeartbeatEvent.kt │ │ │ ├── OneBotLifecycleEvent.kt │ │ │ └── OneBotMetaEvent.kt │ │ ├── notice │ │ │ ├── OneBotFriendAddEvent.kt │ │ │ ├── OneBotFriendRecallEvent.kt │ │ │ ├── OneBotGroupAdminEvent.kt │ │ │ ├── OneBotGroupBanEvent.kt │ │ │ ├── OneBotGroupChangeEvent.kt │ │ │ ├── OneBotGroupRecallEvent.kt │ │ │ ├── OneBotGroupUploadEvent.kt │ │ │ ├── OneBotNoticeEvent.kt │ │ │ └── OneBotNotifyEvent.kt │ │ ├── request │ │ │ └── OneBotRequestEvent.kt │ │ └── stage │ │ │ └── OneBotBotStageEvent.kt │ │ ├── internal │ │ └── message │ │ │ ├── OneBotMessageContentImpl.kt │ │ │ └── OneBotMessageReceiptImpl.kt │ │ ├── message │ │ └── OneBotMessageExtensions.kt │ │ └── utils │ │ ├── EventPushLogs.kt │ │ ├── MessageResolvers.kt │ │ ├── MessageUtil.kt │ │ └── TimestampUtil.kt │ ├── commonTest │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── v11 │ │ └── core │ │ ├── ReplyAndMessageReferenceTests.kt │ │ ├── actor │ │ ├── OneBotGroupDeleteTests.kt │ │ └── OneBotMemberDeleteTests.kt │ │ ├── api │ │ ├── ApiRequestTests.kt │ │ ├── ApplicationSerializableConfigurationTests.kt │ │ ├── ApplicationUsageTests.kt │ │ ├── OneBotApiEmptySerializerTest.kt │ │ ├── OneBotMessageElementTests.kt │ │ └── OneBotMessageOutgoingTests.kt │ │ ├── bot │ │ ├── BotDecoderFromCustomComponentTests.kt │ │ ├── BotInitializationTests.kt │ │ └── DecoderJsonTests.kt │ │ ├── event │ │ ├── CustomEventResolverTests.kt │ │ └── ResolveRawEventToEventTests.kt │ │ └── utils │ │ └── ReplyMessageSegmentListTests.kt │ ├── jsMain │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── v11 │ │ └── core │ │ ├── api │ │ └── OneBotApiRequests.js.kt │ │ ├── bot │ │ └── OneBotBotManager.js.kt │ │ └── component │ │ └── OneBot11Component.js.kt │ ├── jvmMain │ ├── java │ │ └── module-info.java │ ├── kotlin │ │ └── love │ │ │ └── forte │ │ │ └── simbot │ │ │ └── component │ │ │ └── onebot │ │ │ └── v11 │ │ │ └── core │ │ │ ├── api │ │ │ └── OneBotApiRequests.jvm.kt │ │ │ ├── bot │ │ │ ├── OneBotBotManager.jvm.kt │ │ │ └── OneBotBotRequests.jvm.kt │ │ │ ├── component │ │ │ └── OneBot11Component.jvm.kt │ │ │ └── message │ │ │ └── OneBotMessageExtensions.jvm.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ ├── love.forte.simbot.component.ComponentFactoryProvider │ │ └── love.forte.simbot.plugin.PluginFactoryProvider │ ├── jvmTest │ ├── kotlin │ │ ├── GetFileApi.kt │ │ ├── LLOBApiTest.kt │ │ ├── LLOBWsTest.kt │ │ └── love │ │ │ └── forte │ │ │ └── simbot │ │ │ └── component │ │ │ └── onebot │ │ │ └── v11 │ │ │ └── core │ │ │ ├── ApiExecutableTests.kt │ │ │ ├── AppTest.kt │ │ │ ├── BotDefaultImageAdditionalTests.kt │ │ │ └── event │ │ │ ├── FriendSendInteractionTests.kt │ │ │ ├── GroupMessageEventInteractionTests.kt │ │ │ ├── GroupSendInteractionTests.kt │ │ │ ├── MemberSendInteractionTests.kt │ │ │ └── PrivateMessageEventInteractionTests.kt │ └── resources │ │ └── log4j2.xml │ └── nativeMain │ └── kotlin │ └── love │ └── forte │ └── simbot │ └── component │ └── onebot │ └── v11 │ └── core │ ├── api │ └── OneBotApiRequests.native.kt │ ├── bot │ └── OneBotBotManager.native.kt │ └── component │ └── OneBot11Component.native.kt ├── simbot-component-onebot-v11-event ├── api │ └── simbot-component-onebot-v11-event.api ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── love │ │ └── forte │ │ └── simbot │ │ └── component │ │ └── onebot │ │ └── v11 │ │ └── event │ │ ├── RawEvent.kt │ │ ├── RawEventDeserializationException.kt │ │ ├── UnknownEvent.kt │ │ ├── message │ │ ├── RawGroupMessageEvent.kt │ │ ├── RawMessageEvent.kt │ │ └── RawPrivateMessageEvent.kt │ │ ├── meta │ │ ├── RawHeartbeatEvent.kt │ │ ├── RawLifecycleEvent.kt │ │ └── RawMetaEvent.kt │ │ ├── notice │ │ ├── RawFriendAddEvent.kt │ │ ├── RawFriendRecallEvent.kt │ │ ├── RawGroupAdminEvent.kt │ │ ├── RawGroupBanEvent.kt │ │ ├── RawGroupDecreaseEvent.kt │ │ ├── RawGroupIncreaseEvent.kt │ │ ├── RawGroupRecallEvent.kt │ │ ├── RawGroupUploadEvent.kt │ │ ├── RawNoticeEvent.kt │ │ └── RawNotifyEvent.kt │ │ └── request │ │ ├── RawFriendRequestEvent.kt │ │ ├── RawGroupRequestEvent.kt │ │ └── RawRequestEvent.kt │ └── jvmMain │ └── java │ └── module-info.java └── simbot-component-onebot-v11-message ├── api └── simbot-component-onebot-v11-message.api ├── build.gradle.kts └── src ├── commonMain └── kotlin │ └── love │ └── forte │ └── simbot │ └── component │ └── onebot │ └── v11 │ └── message │ ├── Base64Encoder.kt │ ├── MessageElementResolvers.kt │ ├── OneBotMessageContent.kt │ ├── OneBotMessageElement.kt │ ├── OneBotMessageReceipt.kt │ └── segment │ ├── OneBotAnonymous.kt │ ├── OneBotAt.kt │ ├── OneBotContact.kt │ ├── OneBotDice.kt │ ├── OneBotFace.kt │ ├── OneBotForward.kt │ ├── OneBotImage.kt │ ├── OneBotJson.kt │ ├── OneBotLocation.kt │ ├── OneBotMessageSegment.kt │ ├── OneBotMusic.kt │ ├── OneBotPoke.kt │ ├── OneBotRecord.kt │ ├── OneBotReply.kt │ ├── OneBotRps.kt │ ├── OneBotShake.kt │ ├── OneBotShare.kt │ ├── OneBotText.kt │ ├── OneBotUnknownSegment.kt │ ├── OneBotVideo.kt │ ├── OneBotXml.kt │ └── StandardOneBotMessageSegments.kt ├── commonTest └── kotlin │ └── love │ └── forte │ └── simbot │ └── component │ └── onebot │ └── v11 │ └── message │ ├── ListElementSerializationTests.kt │ ├── MessageSegmentSerializationTests.kt │ ├── ResourceMessageBase64Tests.kt │ └── UnknownSegmentTests.kt ├── jsMain └── kotlin │ └── love │ └── forte │ └── simbot │ └── component │ └── onebot │ └── v11 │ └── message │ ├── MessageElementResolvers.js.kt │ └── segment │ └── StandardOneBotMessageSegments.js.kt ├── jvmMain ├── java │ └── module-info.java └── kotlin │ └── love │ └── forte │ └── simbot │ └── component │ └── onebot │ └── v11 │ └── message │ ├── MessageElementResolvers.jvm.kt │ └── segment │ └── StandardOneBotMessageSegments.jvm.kt └── nativeMain └── kotlin └── love └── forte └── simbot └── component └── onebot └── v11 └── message ├── MessageElementResolvers.native.kt └── segment └── StandardOneBotMessageSegments.native.kt /.fleet/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "backend.maxHeapSizeMb": 3500 3 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | 3 | contact_links: 4 | - name: 统一反馈处 5 | url: https://github.com/simple-robot/simpler-robot/issues/new/choose 6 | about: 通过simbot核心仓库统一反馈问题 7 | 8 | - name: 社区 9 | url: https://github.com/orgs/simple-robot/discussions 10 | about: simbot的GitHub交流讨论区 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/doc.yml: -------------------------------------------------------------------------------- 1 | name: "📃文档反馈" 2 | description: "反馈与文档相关的问题反馈" 3 | labels: [ "文档" ] 4 | assignees: [ "ForteScarlet" ] 5 | # https://docs.github.com/cn/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | ## 须知 11 | 在进行问题反馈前,请**确认**以下内容: 12 | 1. 我确认目前的 [Issues](https://github.com/simple-robot/simbot-component-onebot/issues?q=is%3Aissue+label%3A%E6%96%87%E6%A1%A3) 中没有类似内容。 13 | 2. 我已确认所述内容不涉及任何个人隐私或其他敏感信息,遵守相关地区法律法规。 14 | 15 |
16 | 17 | 18 | - type: dropdown 19 | id: type 20 | attributes: 21 | label: 反馈内容类型 22 | options: 23 | - 网站 24 | - API文档 25 | - 其他 26 | validations: 27 | required: true 28 | 29 | - type: textarea 30 | id: links 31 | attributes: 32 | label: 相关链接 33 | description: 提供可用的相关链接 34 | 35 | - type: textarea 36 | id: description 37 | attributes: 38 | label: 内容描述 39 | description: 描述你的反馈内容 40 | validations: 41 | required: true 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/report.yml: -------------------------------------------------------------------------------- 1 | name: "🔥问题反馈" 2 | description: "直接向本仓库反馈问题或提出一个贡献申请" 3 | assignees: [ "ForteScarlet" ] 4 | # https://docs.github.com/cn/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | ## 须知 10 | 在进行问题反馈前,请**确认**以下内容: 11 | 1. 我确认目前的 [issues](https://github.com/simple-robot/simbot-component-onebot/issues?q=is%3Aissue+label%3Abug%3F) 中没有类似内容。 12 | 2. 我已确认所述内容不涉及任何个人隐私或其他敏感信息,遵守相关地区法律法规。 13 | 14 |
15 | 16 | - type: dropdown 17 | id: will-contribute 18 | attributes: 19 | label: 是否会提供贡献? 20 | description: 如果此条议题是你打算提供代码贡献作为前提,那么标记它,来告诉我们与其他开发者,以避免产生可能的重复劳动 21 | options: 22 | - 否 23 | - 是 24 | - 不确定 25 | default: 0 26 | validations: 27 | required: true 28 | 29 | - type: textarea 30 | id: version 31 | attributes: 32 | label: 版本信息 33 | description: 核心库、组件库、以及其他可能涉及到的依赖库的版本信息。 34 | placeholder: | 35 | 例如: 36 | simbot-component-onebot: va.b.c 37 | simbot-core: v999 38 | 39 | - type: dropdown 40 | id: language 41 | attributes: 42 | label: 涉及的编程语言 43 | description: 如果没有或无对应选项则选择'其他'后在后续描述中补充说明 44 | options: 45 | - Java 46 | - Kotlin 47 | - 其他 48 | validations: 49 | required: true 50 | 51 | - type: dropdown 52 | id: build-tool 53 | attributes: 54 | label: 项目构建工具 55 | description: 如果没有或无对应选项则选择'其他'后在后续描述中补充说明 56 | options: 57 | - Maven 58 | - Gradle 59 | - 其他 60 | validations: 61 | required: true 62 | 63 | - type: textarea 64 | id: description 65 | attributes: 66 | label: 内容描述 67 | description: 描述你的反馈内容。(注意日志、代码等特殊内容格式,确保易于阅读) 68 | validations: 69 | required: true 70 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gradle 4 | directory: / 5 | target-branch: "dev/main" 6 | schedule: 7 | interval: daily 8 | labels: 9 | - dependencies 10 | assignees: 11 | - ForteScarlet 12 | open-pull-requests-limit: 10 13 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - 'for-release' 5 | - 'ignore-in-release' 6 | categories: 7 | - title: '⚠️ 不兼容变更' 8 | labels: 9 | - '不兼容' 10 | - title: '🔧 Bug Fix' 11 | labels: 12 | - 'bug' 13 | - title: '⚙️ 修补缺陷' 14 | labels: 15 | - '缺陷' 16 | - title: '🎉 新特性' 17 | labels: 18 | - '特性' 19 | - title: '✨ 优化' 20 | labels: 21 | - '优化' 22 | - title: '📦 依赖更新' 23 | labels: 24 | - 'dependencies' 25 | - title: '👀 其他变更' 26 | labels: 27 | - '*' 28 | -------------------------------------------------------------------------------- /.github/workflows/publish-kdoc.yml: -------------------------------------------------------------------------------- 1 | name: Publish KDoc 2 | on: 3 | workflow_dispatch: 4 | 5 | 6 | env: 7 | JAVA_VERSION: 21 8 | JAVA_DISTRIBUTION: zulu 9 | GRADLE_VERSION: 8.5 10 | IS_CI: true 11 | GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} 12 | GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} 13 | GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} 14 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 15 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 16 | GRADLE_OPTS: "-XX:MaxMetaspaceSize=2g -Dfile.encoding=UTF-8" 17 | 18 | jobs: 19 | deploy-doc: 20 | name: Deploy KDoc 21 | runs-on: ubuntu-latest 22 | steps: 23 | # 检出仓库代码 24 | - uses: actions/checkout@v4 25 | with: 26 | persist-credentials: false 27 | fetch-depth: 0 28 | # setup Java 29 | - uses: actions/setup-java@v4 30 | with: 31 | distribution: ${{ env.JAVA_DISTRIBUTION }} 32 | java-version: ${{ env.JAVA_VERSION }} 33 | 34 | - name: Generate documentation 35 | uses: gradle/actions/setup-gradle@v3 36 | with: 37 | gradle-version: ${{ env.GRADLE_VERSION }} 38 | arguments: | 39 | dokkaGenerate 40 | --info 41 | --warning-mode all 42 | -x test 43 | --build-cache 44 | -Porg.gradle.jvmargs="-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" 45 | 46 | - name: Push to doc repository 47 | uses: peaceiris/actions-gh-pages@v3 48 | with: 49 | personal_token: ${{ secrets.PUSH_TOKEN }} 50 | external_repository: simple-robot-library/simbot3-api-docs 51 | publish_branch: kdoc-deploy/component-onebot 52 | publish_dir: ./build/dokka/html 53 | # deploy to sub dir 54 | destination_dir: components/onebot 55 | 56 | -------------------------------------------------------------------------------- /.github/workflows/qodana_code_quality.yml: -------------------------------------------------------------------------------- 1 | name: Qodana 2 | on: 3 | workflow_dispatch: 4 | pull_request_target: 5 | push: 6 | branches: 7 | - dev/main 8 | - master 9 | - main 10 | 11 | jobs: 12 | qodana: 13 | if: ${{ !startsWith(github.head_ref, 'dependabot/') }} 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: write 17 | pull-requests: write 18 | checks: write 19 | steps: 20 | - uses: actions/checkout@v4 21 | with: 22 | ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit 23 | fetch-depth: 0 # a full history is required for pull request analysis 24 | - name: 'Qodana Scan' 25 | uses: JetBrains/qodana-action@v2024.2 26 | with: 27 | upload-result: true 28 | github-token: ${{ secrets.FORLIY_ACCESS_TOKEN }} 29 | env: 30 | QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} # read the steps about it below 31 | # GITHUB_TOKEN: ${{ secrets.FORLIY_ACCESS_TOKEN }} 32 | -------------------------------------------------------------------------------- /.github/workflows/test-branch-website.yml: -------------------------------------------------------------------------------- 1 | name: Test Branch 2 | on: 3 | pull_request: 4 | branches: 5 | - 'dev/**' 6 | paths: 7 | - 'Writerside/**' 8 | - '.github/workflows/deploy-website.yml' 9 | 10 | concurrency: 11 | group: test-branch-website-${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | # Name of module and id separated by a slash 16 | INSTANCE: Writerside/ob 17 | INSTANCE_NAME: ob 18 | # Replace HI with the ID of the instance in capital letters 19 | ARTIFACT: webHelpOB2-all.zip 20 | # Writerside docker image version 21 | DOCKER_VERSION: 241.16003 22 | 23 | jobs: 24 | test-website-build: 25 | runs-on: ubuntu-latest 26 | outputs: 27 | config_json: ${{ steps.output-config-json.outputs.config_json }} 28 | 29 | steps: 30 | - name: Checkout repository 31 | uses: actions/checkout@v4 32 | 33 | - name: Build Writerside docs using Docker 34 | uses: JetBrains/writerside-github-action@v4 35 | with: 36 | instance: ${{ env.INSTANCE }} 37 | artifact: ${{ env.ARTIFACT }} 38 | docker-version: ${{ env.DOCKER_VERSION }} 39 | 40 | - name: Upload documentation 41 | uses: actions/upload-artifact@v3 42 | with: 43 | name: docs 44 | path: | 45 | artifacts/${{ env.ARTIFACT }} 46 | artifacts/report.json 47 | retention-days: 7 48 | 49 | - name: Unzip artifact 50 | run: unzip -O UTF-8 -qq artifacts/${{ env.ARTIFACT }} -d dir 51 | 52 | - name: Output documentation config.json 53 | id: output-config-json 54 | run: | 55 | echo "config_json=$(cat dir/config.json)" >> $GITHUB_OUTPUT 56 | 57 | # Add the job below and artifacts/report.json on Upload documentation step above if you want to fail the build when documentation contains errors 58 | test-website-test: 59 | # Requires build job results 60 | needs: test-website-build 61 | runs-on: ubuntu-latest 62 | 63 | steps: 64 | - name: Download artifacts 65 | uses: actions/download-artifact@v1 66 | with: 67 | name: docs 68 | path: artifacts 69 | 70 | - name: Test documentation 71 | uses: JetBrains/writerside-checker-action@v1 72 | with: 73 | instance: ${{ env.INSTANCE }} 74 | -------------------------------------------------------------------------------- /.github/workflows/test-branch.yml: -------------------------------------------------------------------------------- 1 | name: Test Branch 2 | on: 3 | pull_request: 4 | branches: 5 | - 'dev/**' 6 | paths: 7 | - '**.java' 8 | - '**.kt' 9 | - '**.kts' 10 | - '*/src/*/kotlin/**' 11 | - '*/src/*/java/**' 12 | - '*/src/*/resource/**' 13 | - 'gradle/**' 14 | 15 | concurrency: 16 | group: test-branch-${{ github.workflow }}-${{ github.ref }} 17 | cancel-in-progress: true 18 | 19 | env: 20 | IS_CI: true 21 | GRADLE_OPTS: "-Dfile.encoding=UTF-8" 22 | 23 | jobs: 24 | build-test: 25 | name: Build and test 26 | strategy: 27 | matrix: 28 | os: [ macos-latest, windows-latest, ubuntu-latest ] 29 | runs-on: ${{ matrix.os }} 30 | steps: 31 | # https://github.com/actions/checkout/issues/242#issuecomment-627501270 32 | # fix `Filename too long` 👆 33 | - name: git configure long path 34 | run: git config --global core.longpaths true 35 | - uses: actions/checkout@v4 36 | - uses: actions/setup-java@v4 37 | with: 38 | distribution: 'zulu' 39 | java-version: 21 40 | cache: 'gradle' 41 | 42 | - uses: gradle/actions/setup-gradle@v3 43 | 44 | - name: Run all tests 45 | run: gradle assemble build allTests --info --warning-mode all 46 | 47 | - name: Upload test reports 48 | uses: actions/upload-artifact@v4 49 | if: ${{ always() }} 50 | with: 51 | name: test-reports-${{ matrix.os }} 52 | path: '**/build/reports/tests' 53 | retention-days: 7 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### IntelliJ IDEA ### 8 | .idea 9 | .idea/modules.xml 10 | .idea/jarRepositories.xml 11 | .idea/compiler.xml 12 | .idea/libraries/ 13 | *.iws 14 | *.iml 15 | *.ipr 16 | out/ 17 | !**/src/main/**/out/ 18 | !**/src/test/**/out/ 19 | 20 | ### Eclipse ### 21 | .apt_generated 22 | .classpath 23 | .factorypath 24 | .project 25 | .settings 26 | .springBeans 27 | .sts4-cache 28 | bin/ 29 | !**/src/main/**/bin/ 30 | !**/src/test/**/bin/ 31 | 32 | ### NetBeans ### 33 | /nbproject/private/ 34 | /nbbuild/ 35 | /dist/ 36 | /nbdist/ 37 | /.nb-gradle/ 38 | 39 | ### VS Code ### 40 | .vscode/ 41 | 42 | ### Mac OS ### 43 | .DS_Store 44 | 45 | .kotlin 46 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.run/detekt.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | true 20 | false 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /.run/simbot-component-onebot [publishToMavenLocal].run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 16 | 21 | 23 | true 24 | true 25 | false 26 | false 27 | 28 | 29 | -------------------------------------------------------------------------------- /.simbot/dokka-assets/css/kdoc-style.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * Project https://github.com/simple-robot/simpler-robot 5 | * Email ForteScarlet@163.com 6 | * 7 | * This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * Lesser GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the Lesser GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | :root { 25 | --dokka-logo-image-url: url('../images/logo-icon-light.svg'); 26 | } 27 | -------------------------------------------------------------------------------- /.simbot/dokka-templates/includes/page_metadata.ftl: -------------------------------------------------------------------------------- 1 | <#macro display> 2 | ${pageName} 3 | <@template_cmd name="pathToRoot"> 4 | 5 | 6 | 7 | 8 | 17 | 18 | 19 | 26 | 27 | -------------------------------------------------------------------------------- /Writerside/c.list: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Writerside/cfg/buildprofiles.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | ruby 7 | logo-icon-dark.svg 8 | logo-icon.svg 9 | https://github.com/simple-robot/simbot-component-onebot/ 10 | GitHub 11 | https://github.com/simple-robot/simbot-component-onebot/ 12 | true 13 | https://github.com/simple-robot/simbot-component-onebot/tree/dev/main/Writerside/ 14 | true 15 | zh-CN 16 | false 17 | head-script.html 18 | VLLZ4JZE8Z 19 | ob-doc 20 | e60d9ee16618a0ad3a338ecc73cb840e 21 | https://simple-robot.github.io/simbot-component-onebot 22 | 23 | 24 | 25 | 26 | false 27 | 28 | 29 | 30 | 31 |
32 | %copyright-year% Forte Scarlet. 33 | simbot官网手册 34 | 文档引导站 35 | 社区 36 | 反馈 37 | 组织库 38 | 核心库仓库 39 | 40 | 41 |
42 |
43 | -------------------------------------------------------------------------------- /Writerside/cfg/glossary.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Simple Robot v4 的简称,通常用于统称"simbot4标准API"和"simbot4核心库" 5 | 组件:针对一组一个或多个「组件标识」和「插件」的统称。 6 | 7 | -------------------------------------------------------------------------------- /Writerside/cfg/head-script.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | 18 | 26 | -------------------------------------------------------------------------------- /Writerside/ob.tree: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Writerside/topics/Home.md: -------------------------------------------------------------------------------- 1 | # 欢迎! 2 | 3 | 4 | release 5 | 6 | 7 | 8 | 9 | 这里是 10 | [**Simple Robot v4**](https://github.com/simple-robot/simpler-robot/tree/v4-dev) 11 | 的 12 | [OneBot组件](https://github.com/simple-robot/simbot-component-onebot/) 13 | 应用手册! 14 | 15 | ## 概述 16 | 17 | Simple Robot OneBot 组件是一个将 18 | [OneBot11协议](https://github.com/botuniverse/onebot-11) 19 | 在 20 | [Simple Robot](http://github.com/simple-robot/simpler-robot) 标准API下实现的组件库, 21 | 并由此提供simbot中的各项能力。 22 | 23 | 借助simbot核心库提供的能力,它可以支持很多高级功能和封装,比如组件协同、Spring支持等, 24 | 助你快速开发 OneBot 客户端应用! 25 | 26 | 序列化和网络请求相关分别基于 [Kotlin serialization](https://github.com/Kotlin/kotlinx.serialization) 27 | 和 [Ktor](https://ktor.io/)。 28 | 29 | 30 | ### 了解 **Simple Robot** 31 | 32 | - [Simple Robot 应用手册](https://simbot.forte.love) 33 | - [Simple Robot 组织库](https://github.com/simple-robot) 34 | 35 | ### API文档 36 | 37 | - [API文档引导站](https://docs.simbot.forte.love) 38 | 39 | ## 反馈与协助! 40 | 41 | 我们欢迎并期望着您的 42 | [反馈](https://github.com/simple-robot/simbot-component-onebot/issues) 43 | 或 44 | [协助](https://github.com/simple-robot/simbot-component-onebot/pulls), 45 | 感谢您的贡献与支持! 46 | 47 | ``` 48 | This program is free software: you can redistribute it and/or 49 | modify it under the terms of the GNU Lesser General 50 | Public License as published by the Free Software Foundation, 51 | either version 3 of the License, or (at your option) 52 | any later version. 53 | 54 | This program is distributed in the hope that it will be useful, 55 | but WITHOUT ANY WARRANTY; without even the implied 56 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 57 | See the GNU Lesser General Public License for more details. 58 | 59 | You should have received a copy of the GNU Lesser General Public 60 | License along with this program. 61 | If not, see . 62 | ``` 63 | -------------------------------------------------------------------------------- /Writerside/topics/OneBot11.md: -------------------------------------------------------------------------------- 1 | # OneBot11 2 | 3 | 4 | 5 | OneBot组件是一个对 6 | [OneBot11协议](https://github.com/botuniverse/onebot-11) 7 | 的**客户端**实现。 8 | 9 | ## 交互方式 10 | 11 | OneBot组件选择使用 12 | [正向 HTTP](https://github.com/botuniverse/onebot-11/blob/master/communication/http.md) 13 | 作为API交互方式、 14 | [正向 WebSocket](https://github.com/botuniverse/onebot-11/blob/master/communication/ws.md) 15 | 作为事件订阅的方式。 16 | 17 | 简单来说,就是不论是API交互还是事件订阅,都由OneBot组件作为**主动方**:主动发起HTTP请求、主动发起WebSocket连接。 18 | 19 | ### 反向? 20 | 21 | 如果你真的想要通过反向HTTP来接收事件推送,那么你需要自行搭建 HTTP 服务端,然后使用 `OneBotBot.push` 手动推送原始事件的JSON字符串。 22 | 你可以前往参考 23 | `OneBotBot` 的 24 | 。 25 | -------------------------------------------------------------------------------- /Writerside/topics/modules.md: -------------------------------------------------------------------------------- 1 | # 模块概述 2 | 3 | 4 | 5 | ## 公共模块 6 | 7 | OneBot组件为所有协议实现的模块提供了一些共享内容的模块, 8 | 命名为 `simbot-component-onebot-common`。 9 | 10 | 此模块中会定义一些通用的类型或注解等。 11 | 对于普通开发者来讲可以不用过多关注,此模块由其他组件模块引用并使用。 12 | 13 | ## OneBot11 14 | 15 | 在OneBot组件中,我们提供了针对 [OneBot11](https://github.com/botuniverse/onebot-11) 16 | 协议的组件实现模块,它们的坐标以 `simbot-component-onebot-v11` 作为开头: 17 | 18 | 19 |
  • simbot-component-onebot-v11-common 20 | 21 | 在OneBot11协议的实现模块中进行共享的模块。 22 | 对于普通开发者来讲可以不用过多关注,此模块由其他组件模块引用并使用。 23 |
  • 24 |
  • simbot-component-onebot-v11-core 25 | 26 | OneBot11协议作为一个simbot组件的实现模块。通常会是你**真正使用**的模块。 27 |
  • 28 |
  • simbot-component-onebot-v11-event 29 | 30 | 对OneBot11协议中的[原始事件](https://github.com/botuniverse/onebot-11/tree/master/event) 31 | 类型提供定义的模块, 32 | 被 `simbot-component-onebot-v11-core` 引用并依赖。 33 | 34 | 35 | 36 | 需要注意的是这里的事件并不是simbot中的**事件**,而仅仅是一种数据类实现, 37 | 是对原始事件的JSON结构的基本映射。 38 | 39 |
  • 40 |
  • simbot-component-onebot-v11-message 41 | 42 | 对OneBot11协议中的[原始消息段](https://github.com/botuniverse/onebot-11/blob/master/message/segment.md) 43 | 类型提供定义的模块。 44 | 45 | 这里定义的大部分类型都是针对消息段的数据类实现, 46 | 是对它们的JSON结构的基本映射, 47 | 被 `simbot-component-onebot-v11-core` 引用并依赖。 48 | 49 |
  • 50 |
    51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Writerside/topics/onebot11-actors.md: -------------------------------------------------------------------------------- 1 | # 行为对象 2 | 3 | 4 | 5 | 行为对象,指的是实现了simbot标准API中 `Actor` 接口的类型, 6 | 例如 `OneBotMember`、`OneBotGroup` 等, 7 | 它们与 `OneBotBot` 存在某种关系、并具有很多行为性的API。 8 | 9 | 它们通常被定义在 `simbot-component-onebot-v11-core` 10 | 模块中的 `love.forte.simbot.component.onebot.v11.core.actor` 11 | 包路径下。 12 | 13 | ## CoroutineScope 14 | 15 | 所有行为对象均实现 `Actor`,而 `Actor` 则实现 `CoroutineScope`, 16 | 因此所有的行为对象均可作为一个协程作用域。 17 | 18 | 例如: 19 | 20 | ```kotlin 21 | val group: OneBotGroup = ... 22 | 23 | // 异步任务 24 | group.launch { ... } 25 | ``` 26 | 27 | 它们的协程上下文来自其各自所属的 `OneBotBot`,但是其中不包含 `Job`。 28 | 29 | ## 异步API&响应式/预处理API 30 | 31 | 参考 32 |
    33 | 。 34 | -------------------------------------------------------------------------------- /Writerside/topics/onebot11-quick-start.md: -------------------------------------------------------------------------------- 1 | # 开始使用 2 | 3 | 开始使用OneBot11协议组件。 4 | 5 | 6 | 7 | ## 前期准备 8 | 9 | ### OneBot11协议服务端 10 | 11 | OneBot组件是一个OneBot协议的**客户端**实现, 12 | 因此在使用之前,你需要安装、下载、启动一个支持OneBot11协议的**服务端**。 13 | 14 | 15 | 16 | 鉴于OneBot协议的主要应用场景的特殊性, 17 | 大多数服务端的实现库都**不建议、不允许**公开讨论、宣传有关它们的信息(尤其是影响力较大的简中互联网网站), 18 | 因此此处将 **不做列举**。 19 | 20 | 你可以选择去GitHub等开源网站搜索各种实现库, 21 | 或者可以前往 [社群](https://simbot.forte.love/communities.html) 22 | 向其他人寻求帮助。 23 | 24 | 25 | 26 | 27 | ### Java 28 | 29 | 如果你打算使用 Java,请确保你的Java版本至少为 **Java11**,因为 30 | simbot4 31 | 在JVM平台上最低要求Java11。 32 | 33 | 如果你打算配合使用Spring Boot v3.x版本,确保Java版本至少为 **Java17**。 34 | 35 | ### Kotlin 36 | 37 | 如果打算使用Kotlin,建议使用 Kotlin 2.0 以上版本。 38 | 具体的最低推荐版本以最新的 [simbot4版本](%simbot4-release%) 中的Kotlin版本为准。 39 | 40 | ### Kotlin multiplatform 41 | 42 | 如果打算使用Kotlin的其他非JVM平台或多平台,需要注意组件库中由于引入了Ktor(v2.x), 43 | 因此暂时无法使用Ktor Client不支持的平台(例如 `wasm-js`)。 44 | 45 | > Ktor Client 支持平台可参考 [官方文档](https://ktor.io/docs/client-supported-platforms.html) 46 | -------------------------------------------------------------------------------- /Writerside/topics/suspend-API-transform.md: -------------------------------------------------------------------------------- 1 | # 挂起API桥接 2 | 3 | 4 | 5 | 6 | 7 | 有关更多Java友好的内容, 8 | 请参考 [simbot4应用手册](https://simbot.forte.love/java-friendly.html) 9 | 。 10 | 11 | 12 | 13 | 当使用Java时,挂起API会被桥接为三种风格的API: 14 | 15 | 16 | 17 | 18 | 通常是 `xxxBlocking` 或 `getXxx`。 19 | 返回值类型与源挂起API的类型一致。 20 | 21 | 22 | 23 | 通常是 `xxxAsync`。 24 | 调用时即启动异步任务,并返回 `CompletableFuture`。 25 | 26 | 27 | 28 | 29 | 通常是 `xxxReserve`。 30 | 31 | 返回类型为 `SuspendReserve`, 32 | 需要通过 `transform(...)` 提供一个转化器来真正执行逻辑并处理结果。 33 | `SuspendReserves` 中的静态API提供了一些预设的转化器。 34 | 35 | 通常用于转化为响应式的结果,例如 `Mono`: 36 | 37 | ```Java 38 | var reserve = xxxReserve(...); 39 | // 转化为 Mono。 40 | reserve.transform( 41 | SuspendReserve.mono() 42 | ).subscribe(); 43 | ``` 44 | 45 | 46 | 47 | 48 | 49 | 50 | 在使用异步API或响应式API时,注意异步结果的处理,例如异常处理。 51 | 在搜索引擎中查询它们的结果类型 52 | (例如`CompletableFuture`) 了解更多, 53 | 或参阅 [核心库说明](https://simbot.forte.love/java-friendly.html#阻塞与异步) 54 | 中的小贴士。 55 | 56 | -------------------------------------------------------------------------------- /Writerside/v.list: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Writerside/writerside.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | LOWER_CASE_DASHES_INTERNATIONAL 10 | 11 | 12 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | 19 | plugins { 20 | `kotlin-dsl` 21 | } 22 | 23 | repositories { 24 | mavenCentral() 25 | gradlePluginPortal() 26 | mavenLocal() 27 | } 28 | 29 | val kotlinVersion: String = libs.versions.kotlin.get() 30 | 31 | dependencies { 32 | implementation(kotlin("gradle-plugin", kotlinVersion)) 33 | implementation(kotlin("serialization", kotlinVersion)) 34 | implementation(libs.dokka.plugin) 35 | 36 | // see https://github.com/gradle-nexus/publish-plugin 37 | implementation("io.github.gradle-nexus:publish-plugin:2.0.0") 38 | 39 | // simbot suspend transform gradle common 40 | implementation(libs.simbot.gradle) 41 | 42 | // suspend transform 43 | implementation(libs.suspend.transform.gradle) 44 | 45 | // gradle common 46 | implementation(libs.bundles.gradle.common) 47 | } 48 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | // https://stackoverflow.com/questions/67795324/gradle7-version-catalog-how-to-use-it-with-buildsrc 19 | dependencyResolutionManagement { 20 | versionCatalogs { 21 | create("libs") { 22 | from(files("../gradle/libs.versions.toml")) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Env.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | object Env { 19 | const val IS_SNAPSHOT = "SIMBOT_IS_SNAPSHOT" 20 | const val SNAPSHOT_ONLY = "SIMBOT_SNAPSHOT_ONLY" 21 | const val RELEASES_ONLY = "SIMBOT_RELEASES_ONLY" 22 | const val IS_CI = "IS_CI" 23 | 24 | } 25 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/JVMConstants.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | object JVMConstants { 19 | const val KT_JVM_TARGET_VALUE = 11 20 | const val KT_JVM_TARGET = "11" 21 | } 22 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/JsConfig.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl 19 | 20 | 21 | fun KotlinJsTargetDsl.configJs() { 22 | nodejs() 23 | binaries.library() 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/R.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | import love.forte.gradle.common.core.property.systemProp 19 | import love.forte.gradle.common.core.repository.Repositories 20 | import love.forte.gradle.common.core.repository.SimpleCredentials 21 | import love.forte.gradle.common.publication.SonatypeContact 22 | import org.slf4j.LoggerFactory 23 | 24 | val logger = LoggerFactory.getLogger("Sonatype Userinfo") 25 | 26 | private val sonatypeUserInfo by lazy { 27 | val userInfo = love.forte.gradle.common.publication.sonatypeUserInfoOrNull 28 | 29 | val username = systemProp(SonatypeContact.SONATYPE_USERNAME) ?: return@lazy null 30 | val password = systemProp(SonatypeContact.SONATYPE_PASSWORD) ?: return@lazy null 31 | logger.info("sonatype.username: {}", username) 32 | logger.info("sonatype.password: {}", password) 33 | 34 | if (userInfo == null) { 35 | logger.warn("sonatype.username or sonatype.password is null, cannot config nexus publishing.") 36 | } 37 | 38 | userInfo 39 | } 40 | 41 | val sonatypeUsername: String? get() = sonatypeUserInfo?.username 42 | val sonatypePassword: String? get() = sonatypeUserInfo?.password 43 | 44 | val ReleaseRepository by lazy { 45 | Repositories.Central.Default.copy(SimpleCredentials(sonatypeUsername, sonatypePassword)) 46 | } 47 | val SnapshotRepository by lazy { 48 | Repositories.Snapshot.Default.copy(SimpleCredentials(sonatypeUsername, sonatypePassword)) 49 | } 50 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/simbot-onebot-nexus-publish.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-telegram. 5 | * 6 | * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. 15 | * If not, see . 16 | */ 17 | 18 | import love.forte.gradle.common.core.project.setup 19 | import love.forte.gradle.common.core.repository.Repositories 20 | import java.time.Duration 21 | 22 | plugins { 23 | id("io.github.gradle-nexus.publish-plugin") 24 | } 25 | 26 | setup(P.ComponentOneBot) 27 | 28 | val userInfo = love.forte.gradle.common.publication.sonatypeUserInfoOrNull 29 | 30 | if (userInfo == null) { 31 | logger.warn("sonatype.username or sonatype.password is null, cannot config nexus publishing.") 32 | } 33 | 34 | nexusPublishing { 35 | packageGroup.set(P.ComponentOneBot.group) 36 | repositoryDescription.set(P.ComponentOneBot.description) 37 | useStaging = project.provider { !project.version.toString().endsWith("SNAPSHOT", ignoreCase = true) } 38 | 39 | transitionCheckOptions { 40 | maxRetries = 1000 41 | delayBetween = Duration.ofSeconds(2) 42 | } 43 | 44 | repositories { 45 | sonatype { 46 | snapshotRepositoryUrl.set(uri(Repositories.Snapshot.URL)) 47 | username.set(userInfo?.username) 48 | password.set(userInfo?.password) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/util/PropUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import org.gradle.api.Project 21 | import org.gradle.kotlin.dsl.extra 22 | 23 | /** 24 | * 尝试从 [System.getProperty] 和 [System.getenv] 中获取指定属性。 25 | * 优先使用 [System.getProperty]。 26 | */ 27 | fun systemProp(propKey: String, envKey: String = propKey): String? = 28 | System.getProperty(propKey) ?: System.getenv(envKey) 29 | 30 | 31 | fun Project.getProp(key: String): Any? = if (extra.has(key)) extra.get(key) else null 32 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/util/PublishConfigurableUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import Env 21 | import isSnapshot 22 | 23 | data class PublishConfigurableResult( 24 | val isSnapshotOnly: Boolean, 25 | val isReleaseOnly: Boolean, 26 | val isPublishConfigurable: Boolean = when { 27 | isSnapshotOnly -> isSnapshot() 28 | isReleaseOnly -> !isSnapshot() 29 | else -> true 30 | }, 31 | ) 32 | 33 | 34 | fun checkPublishConfigurable(): PublishConfigurableResult { 35 | val isSnapshotOnly = 36 | (System.getProperty("snapshotOnly") ?: System.getenv(Env.SNAPSHOT_ONLY))?.equals("true", true) == true 37 | val isReleaseOnly = 38 | (System.getProperty("releaseOnly") ?: System.getenv(Env.RELEASES_ONLY))?.equals("true", true) == true 39 | 40 | return PublishConfigurableResult(isSnapshotOnly, isReleaseOnly) 41 | } 42 | 43 | inline fun checkPublishConfigurable(block: PublishConfigurableResult.() -> Unit) { 44 | val v = checkPublishConfigurable() 45 | if (v.isPublishConfigurable) { 46 | v.block() 47 | } 48 | } 49 | 50 | 51 | inline val isCi: Boolean get() = systemProp(Env.IS_CI).toBoolean() 52 | 53 | inline val isLinux: Boolean get() = systemProp("os.name")?.contains("Linux", true) ?: false 54 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | kotlin.native.ignoreDisabledTargets=true 3 | kotlin.js.generate.executable.default=false 4 | 5 | # Such dependencies are not applicable for Kotlin/Native, consider changing the dependency type to 'implementation' or 'api'. 6 | # To disable this warning, set the kotlin.native.ignoreIncorrectDependencies=true project property 7 | # 8 | # 2024/12/04 Update: w: The `kotlin.native.ignoreIncorrectDependencies` deprecated property is used in your build. 9 | # Please, stop using it as it is unsupported and may apply no effect to your build. 10 | # kotlin.native.ignoreIncorrectDependencies=true 11 | 12 | # 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. You can use -Xexpect-actual-classes flag to suppress this warning. Also see: https://youtrack.jetbrains.com/issue/KT-61573 13 | # "-Xexpect-actual-classes" 14 | org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=1G -Dfile.encoding=UTF-8 15 | 16 | # https://kotlinlang.org/docs/native-improving-compilation-time.html#gradle-configuration 17 | #org.gradle.workers.max=8 18 | org.gradle.parallel=true 19 | org.gradle.caching=true 20 | 21 | # ksp2 22 | # https://github.com/google/ksp/blob/main/docs/ksp2.md 23 | # TODO 24 | # issues: 25 | ## NPE: FAILURE: Build failed with an exception. 26 | ## 27 | ## * What went wrong: 28 | ## Execution failed for task ':simbot-component-onebot-v11:simbot-component-onebot-v11-message:kspCommonMainKotlinMetadata'. 29 | ## > A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction 30 | ## > null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl 31 | ## https://github.com/google/ksp/issues/1929 32 | ksp.useKSP2=false 33 | 34 | # https://kotlinlang.org/docs/multiplatform-publish-lib.html#host-requirements 35 | kotlin.native.enableKlibsCrossCompilation=true 36 | 37 | # Dokka V2 38 | ## https://kotlinlang.org/docs/dokka-migration.html#enable-the-new-dokka-gradle-plugin 39 | org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled 40 | #org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers 41 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simple-robot/simbot-component-onebot/01cc4198434c1a799341d06a33429e3f1cefff31/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Mar 21 17:22:56 CST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /internal-processors/event-type-resolver-processor/README.md: -------------------------------------------------------------------------------- 1 | 用于生成:'根据Event的两个子类型定位一个具体的事件类型的解析API' 的处理器。 2 | 3 | ```kotlin 4 | // 生成 👇 5 | 6 | fun resolveEventSerializer(postType: String, subType: String): KSerializer? { 7 | return when (postType) { 8 | "message" -> when (subType) { 9 | "private" -> PrivateMessageEvent.serializer() 10 | "group" -> GroupMessageEvent.serializer() 11 | else -> null 12 | } 13 | // "" -> ... 14 | // "" -> ... 15 | // "" -> ... 16 | else -> null 17 | } 18 | } 19 | 20 | fun resolveEventType(postType: String, subType: String): KClass? { 21 | return ... 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /internal-processors/event-type-resolver-processor/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 19 | 20 | plugins { 21 | kotlin("jvm") 22 | } 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | kotlin { 29 | jvmToolchain(11) 30 | compilerOptions { 31 | javaParameters = true 32 | jvmTarget.set(JvmTarget.JVM_11) 33 | } 34 | } 35 | 36 | configJavaCompileWithModule() 37 | 38 | dependencies { 39 | // implementation(project(":annotations")) 40 | api(libs.ksp) 41 | api(libs.kotlinPoet.ksp) 42 | api(libs.simbot.common.annotations) 43 | testImplementation(kotlin("test-junit5")) 44 | } 45 | 46 | tasks.getByName("test") { 47 | useJUnitPlatform() 48 | } 49 | 50 | -------------------------------------------------------------------------------- /internal-processors/event-type-resolver-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider: -------------------------------------------------------------------------------- 1 | onebot11.internal.processors.eventtyperesolver.EventTypeResolverProcessorProvider 2 | -------------------------------------------------------------------------------- /internal-processors/include-component-message-elements-processor/README.md: -------------------------------------------------------------------------------- 1 | 用于生成注入所有组件内消息元素实现的序列化信息的处理器。 2 | -------------------------------------------------------------------------------- /internal-processors/include-component-message-elements-processor/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 19 | 20 | plugins { 21 | kotlin("jvm") 22 | } 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | kotlin { 29 | jvmToolchain(11) 30 | compilerOptions { 31 | javaParameters = true 32 | jvmTarget.set(JvmTarget.JVM_11) 33 | } 34 | } 35 | 36 | configJavaCompileWithModule() 37 | 38 | dependencies { 39 | // implementation(project(":annotations")) 40 | api(libs.ksp) 41 | api(libs.kotlinPoet.ksp) 42 | api(libs.simbot.common.annotations) 43 | testImplementation(kotlin("test-junit5")) 44 | } 45 | 46 | tasks.getByName("test") { 47 | useJUnitPlatform() 48 | } 49 | 50 | -------------------------------------------------------------------------------- /internal-processors/include-component-message-elements-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider: -------------------------------------------------------------------------------- 1 | onebot11.internal.processors.includemessageelements.IncludeMessageElementsProcessorProvider 2 | -------------------------------------------------------------------------------- /qudana.yaml: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------------------------------# 2 | # Qodana analysis is configured by qodana.yaml file # 3 | # https://www.jetbrains.com/help/qodana/qodana-yaml.html # 4 | #-------------------------------------------------------------------------------# 5 | version: "1.0" 6 | 7 | #Specify inspection profile for code analysis 8 | profile: 9 | name: qodana.starter 10 | 11 | #Enable inspections 12 | #include: 13 | # - name: 14 | 15 | #Disable inspections 16 | #exclude: 17 | # - name: 18 | # paths: 19 | # - 20 | 21 | projectJDK: azul-21 #(Applied in CI/CD pipeline) 22 | 23 | #Execute shell command before Qodana execution (Applied in CI/CD pipeline) 24 | #bootstrap: sh ./prepare-qodana.sh 25 | 26 | #Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) 27 | #plugins: 28 | # - id: #(plugin id can be found at https://plugins.jetbrains.com) 29 | 30 | #Specify Qodana linter for analysis (Applied in CI/CD pipeline) 31 | linter: jetbrains/qodana-jvm-community:2024.2 32 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | pluginManagement { 18 | repositories { 19 | mavenCentral() 20 | gradlePluginPortal() 21 | mavenLocal() 22 | } 23 | } 24 | 25 | plugins { 26 | id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" 27 | } 28 | 29 | rootProject.name = "simbot-component-onebot" 30 | 31 | include(":internal-processors:include-component-message-elements-processor") 32 | include(":internal-processors:event-type-resolver-processor") 33 | 34 | include(":simbot-component-onebot-common") 35 | 36 | include(":simbot-component-onebot-v11:simbot-component-onebot-v11-common") 37 | include(":simbot-component-onebot-v11:simbot-component-onebot-v11-event") 38 | include(":simbot-component-onebot-v11:simbot-component-onebot-v11-message") 39 | include(":simbot-component-onebot-v11:simbot-component-onebot-v11-core") 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/api/simbot-component-onebot-common.api: -------------------------------------------------------------------------------- 1 | public abstract interface annotation class love/forte/simbot/component/onebot/common/annotations/ApiResultConstructor : java/lang/annotation/Annotation { 2 | } 3 | 4 | public abstract interface annotation class love/forte/simbot/component/onebot/common/annotations/ExperimentalOneBotAPI : java/lang/annotation/Annotation { 5 | } 6 | 7 | public abstract interface annotation class love/forte/simbot/component/onebot/common/annotations/InternalOneBotAPI : java/lang/annotation/Annotation { 8 | } 9 | 10 | public abstract interface annotation class love/forte/simbot/component/onebot/common/annotations/OneBotInternalImplementationsOnly : java/lang/annotation/Annotation { 11 | } 12 | 13 | public abstract interface annotation class love/forte/simbot/component/onebot/common/annotations/SourceEventConstructor : java/lang/annotation/Annotation { 14 | } 15 | 16 | public abstract interface class love/forte/simbot/component/onebot/common/component/OneBotComponent : love/forte/simbot/component/Component { 17 | } 18 | 19 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | import love.forte.gradle.common.core.project.setup 19 | import love.forte.gradle.common.kotlin.multiplatform.applyTier123 20 | import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi 21 | 22 | plugins { 23 | kotlin("multiplatform") 24 | id("org.jetbrains.dokka") 25 | } 26 | 27 | setup(P.ComponentOneBot) 28 | configJavaCompileWithModule("simbot.component.onebot.common") 29 | apply(plugin = "simbot-onebot-multiplatform-maven-publish") 30 | 31 | kotlin { 32 | explicitApi() 33 | applyDefaultHierarchyTemplate() 34 | 35 | @OptIn(ExperimentalKotlinGradlePluginApi::class) 36 | compilerOptions { 37 | optIn.addAll( 38 | "love.forte.simbot.annotations.InternalSimbotAPI", 39 | "love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI" 40 | ) 41 | } 42 | 43 | configKotlinJvm() 44 | 45 | js(IR) { 46 | configJs() 47 | } 48 | 49 | applyTier123() 50 | 51 | sourceSets { 52 | commonMain.dependencies { 53 | implementation(libs.simbot.api) 54 | api(libs.simbot.common.annotations) 55 | } 56 | 57 | commonTest.dependencies { 58 | api(libs.simbot.core) 59 | api(kotlin("test")) 60 | } 61 | 62 | jvmTest.dependencies { 63 | implementation(libs.log4j.api) 64 | implementation(libs.log4j.core) 65 | implementation(libs.log4j.slf4j2) 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/OneBot.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common 19 | 20 | import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI 21 | 22 | /** 23 | * An OneBot object. 24 | */ 25 | @InternalOneBotAPI 26 | public object OneBot 27 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/annotations/ApiOpts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common.annotations 19 | 20 | /** 21 | * 标记在作为 `OneBotApi` 的响应体数据类的构造上, 22 | * 并做出如下警告: 23 | * 这是用作 `OneBotApi` 返回值的类型,它应当仅通过序列化器构造。 24 | * 作为数据类,它可能无法保证兼容性,请避免直接构造它。 25 | */ 26 | @Target(AnnotationTarget.CONSTRUCTOR) 27 | @Retention(AnnotationRetention.BINARY) 28 | @RequiresOptIn( 29 | message = "这是用作OneBotApi返回值的类型," + 30 | "它应当仅通过序列化器构造。" + 31 | "作为数据类,它可能无法保证兼容性,请避免直接构造它。", 32 | level = RequiresOptIn.Level.ERROR 33 | ) 34 | @MustBeDocumented 35 | public annotation class ApiResultConstructor 36 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/annotations/ComponentOpts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common.annotations 19 | 20 | /** 21 | * 标记为仅用于OneBot组件内部使用的API,可能会随时变更、删除 22 | */ 23 | @Retention(AnnotationRetention.BINARY) 24 | @RequiresOptIn( 25 | message = "仅用于OneBot组件内部使用的API,可能会随时变更、删除", 26 | level = RequiresOptIn.Level.ERROR 27 | ) 28 | @Target( 29 | AnnotationTarget.CLASS, 30 | AnnotationTarget.ANNOTATION_CLASS, 31 | AnnotationTarget.PROPERTY, 32 | AnnotationTarget.FUNCTION, 33 | AnnotationTarget.CONSTRUCTOR, 34 | AnnotationTarget.FIELD, 35 | AnnotationTarget.PROPERTY_SETTER, 36 | AnnotationTarget.PROPERTY_GETTER, 37 | ) 38 | @MustBeDocumented 39 | public annotation class InternalOneBotAPI 40 | 41 | /** 42 | * 标记为OneBot组件中仍处于实验阶段的API,可能会随时变更、删除 43 | */ 44 | @Retention(AnnotationRetention.BINARY) 45 | @RequiresOptIn( 46 | message = "OneBot组件中仍处于实验阶段的API,可能会随时变更、删除", 47 | level = RequiresOptIn.Level.ERROR 48 | ) 49 | @Target( 50 | AnnotationTarget.CLASS, 51 | AnnotationTarget.ANNOTATION_CLASS, 52 | AnnotationTarget.PROPERTY, 53 | AnnotationTarget.FUNCTION, 54 | AnnotationTarget.CONSTRUCTOR, 55 | AnnotationTarget.FIELD, 56 | ) 57 | @MustBeDocumented 58 | public annotation class ExperimentalOneBotAPI 59 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/annotations/EventOpts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common.annotations 19 | 20 | /** 21 | * 标记在 `Event` 的某个具体实现数据类的构造上, 22 | * 并做出如下警告: 23 | * 这是用作 `Event` 的类型(或与之相关),它应当仅通过序列化器构造。 24 | * 作为数据类,它可能无法保证兼容性,请避免直接构造它。 25 | */ 26 | @Target(AnnotationTarget.CONSTRUCTOR) 27 | @Retention(AnnotationRetention.BINARY) 28 | @RequiresOptIn( 29 | message = "这是用作OneBot `Event` 的类型(或与之相关)," + 30 | "它应当仅通过序列化器构造。" + 31 | "作为数据类,它可能无法保证兼容性,请避免直接构造它。", 32 | level = RequiresOptIn.Level.ERROR 33 | ) 34 | @MustBeDocumented 35 | public annotation class SourceEventConstructor 36 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/annotations/Marks.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common.annotations 19 | 20 | /** 21 | * 一个标记性注解,标记一个类型 (通常是一个抽象类或接口) 22 | * 或函数应当仅由**内部实现**, 23 | * 对外实现不稳定且不保证兼容性。 24 | * 25 | */ 26 | @Retention(AnnotationRetention.SOURCE) 27 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) 28 | @MustBeDocumented 29 | public annotation class OneBotInternalImplementationsOnly 30 | 31 | // TODO be SubclassOptInRequired ? 32 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/component/OneBotComponent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.common.component 19 | 20 | import love.forte.simbot.component.Component 21 | 22 | 23 | /** 24 | * 一个作为 OneBot 组件 [Component] 实现的父级类型。 25 | * @author ForteScarlet 26 | */ 27 | public interface OneBotComponent : Component 28 | -------------------------------------------------------------------------------- /simbot-component-onebot-common/src/jvmMain/java/module-info.java: -------------------------------------------------------------------------------- 1 | module simbot.component.onebot.common { 2 | requires kotlin.stdlib; 3 | requires simbot.api; 4 | requires static simbot.common.annotations; 5 | exports love.forte.simbot.component.onebot.common.component; 6 | exports love.forte.simbot.component.onebot.common.annotations; 7 | } 8 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-common/api/simbot-component-onebot-v11-common.api: -------------------------------------------------------------------------------- 1 | public final class love/forte/simbot/component/onebot/v11/common/api/StatusResult { 2 | public static final field Companion Llove/forte/simbot/component/onebot/v11/common/api/StatusResult$Companion; 3 | public final fun component1 ()Ljava/lang/Boolean; 4 | public final fun component2 ()Z 5 | public fun equals (Ljava/lang/Object;)Z 6 | public final fun getGood ()Z 7 | public final fun getOnline ()Ljava/lang/Boolean; 8 | public fun hashCode ()I 9 | public fun toString ()Ljava/lang/String; 10 | } 11 | 12 | public synthetic class love/forte/simbot/component/onebot/v11/common/api/StatusResult$$serializer : kotlinx/serialization/internal/GeneratedSerializer { 13 | public static final field INSTANCE Llove/forte/simbot/component/onebot/v11/common/api/StatusResult$$serializer; 14 | public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; 15 | public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; 16 | public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Llove/forte/simbot/component/onebot/v11/common/api/StatusResult; 17 | public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; 18 | public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V 19 | public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Llove/forte/simbot/component/onebot/v11/common/api/StatusResult;)V 20 | public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; 21 | } 22 | 23 | public final class love/forte/simbot/component/onebot/v11/common/api/StatusResult$Companion { 24 | public final fun serializer ()Lkotlinx/serialization/KSerializer; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/common/api/StatusResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.common.api 19 | 20 | import kotlinx.serialization.Serializable 21 | import love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor 22 | import love.forte.simbot.component.onebot.common.annotations.SourceEventConstructor 23 | 24 | 25 | /** 26 | * 用于心跳事件中 `status` 属性和 27 | * `get_status` API 中响应数据的状态结果。 28 | * 29 | * [`get_status`-获取运行状态](https://github.com/botuniverse/onebot-11/blob/master/api/public.md#get_status-获取运行状态) 30 | * 31 | * status 在定义中存在 “OneBot 实现自行添加的其它内容” 的扩展字段。 32 | * 这些内容可以考虑从事件的原始字符串或API响应的原始字符串中自行解析, 33 | * 它的不确定性导致其难以直接通过 Kotlin Serialization 对其进行定义。 34 | * 35 | * @property online 当前 QQ 在线,`null` 表示无法查询到在线状态 36 | * @property good 状态符合预期,意味着各模块正常运行、功能正常,且 QQ 在线 37 | * 38 | * @author ForteScarlet 39 | */ 40 | @Serializable 41 | public data class StatusResult 42 | @ApiResultConstructor 43 | @SourceEventConstructor 44 | internal constructor( 45 | public val online: Boolean? = null, 46 | public val good: Boolean = false, 47 | ) 48 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/common/utils/AvatarUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | @file:JvmName("AvatarUtil") 19 | 20 | package love.forte.simbot.component.onebot.v11.common.utils 21 | 22 | import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI 23 | import kotlin.jvm.JvmName 24 | 25 | /** 26 | * 得到 `s=640` 的QQ头像。 27 | * 28 | * @param id QQ号 29 | */ 30 | @InternalOneBotAPI 31 | public fun qqAvatar640(id: String): String = 32 | "https://q1.qlogo.cn/g?b=qq&nk=$id&s=640" 33 | 34 | /** 35 | * 得到 `s=100` 的QQ头像。 36 | * 37 | * @param id QQ号 38 | */ 39 | @InternalOneBotAPI 40 | public fun qqAvatar100(id: String): String = 41 | "https://q1.qlogo.cn/g?b=qq&nk=$id&s=100" 42 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-common/src/jvmMain/java/module-info.java: -------------------------------------------------------------------------------- 1 | module simbot.component.onebot11v.common { 2 | requires kotlin.stdlib; 3 | requires simbot.component.onebot.common; 4 | requires static simbot.common.annotations; 5 | requires transitive kotlinx.serialization.core; 6 | 7 | exports love.forte.simbot.component.onebot.v11.common.api; 8 | exports love.forte.simbot.component.onebot.v11.common.utils; 9 | } 10 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotStranger.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.actor 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.literal 22 | import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly 23 | import love.forte.simbot.component.onebot.v11.common.utils.qqAvatar640 24 | import love.forte.simbot.component.onebot.v11.core.api.GetStrangerInfoApi 25 | import love.forte.simbot.definition.User 26 | 27 | 28 | /** 29 | * 一个陌生人。 30 | * 通常是通过 [GetStrangerInfoApi] 31 | * 得到的信息。 32 | * 33 | * @author ForteScarlet 34 | */ 35 | @OneBotInternalImplementationsOnly 36 | public interface OneBotStranger : User { 37 | override val id: ID 38 | override val name: String 39 | 40 | override val avatar: String 41 | get() = qqAvatar640(id.literal) 42 | 43 | /** 44 | * 年龄。 45 | * 如果无法获取则有可能会被填充一个默认值。 46 | */ 47 | public val age: Int 48 | 49 | /** 50 | * 性别。`male` 或 `female` 或 `unknown` 51 | */ 52 | public val sex: String 53 | } 54 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotStrangerAware.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.actor 19 | 20 | import love.forte.simbot.suspendrunner.ST 21 | 22 | 23 | /** 24 | * 可以感知(查询到) [OneBotStranger] 的类型。 25 | * 由可以被表示为一个 OneBot 中的用户的类型实现: 26 | * 27 | * - [OneBotFriend] 28 | * - [OneBotMember] 29 | * 30 | * @see OneBotFriend 31 | * @see OneBotMember 32 | * 33 | * @author ForteScarlet 34 | */ 35 | public interface OneBotStrangerAware { 36 | /** 37 | * 查询并得到对应的 [OneBotStranger] 信息。 38 | * 39 | * @throws Throwable 任何请求API过程中可能产生的异常 40 | */ 41 | @ST 42 | public suspend fun toStranger(): OneBotStranger 43 | } 44 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/SendLikeSupport.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.actor 19 | 20 | import love.forte.simbot.suspendrunner.ST 21 | 22 | 23 | /** 24 | * 25 | * 支持发送好友赞行为的接口定义。 26 | * 27 | * @author ForteScarlet 28 | */ 29 | public interface SendLikeSupport { 30 | /** 31 | * 发送好友赞。 32 | * 33 | * @param times 次数。 34 | * 一般来说一人一天最多赞10次, 35 | * 但是这将交由OneBot服务端进行校验和处理。 36 | * @throws Throwable 任何请求API过程可能产生的异常 37 | */ 38 | @ST 39 | public suspend fun sendLike(times: Int) 40 | } 41 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/internal/OneBotStrangerImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.actor.internal 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotStranger 22 | import love.forte.simbot.component.onebot.v11.core.api.GetStrangerInfoResult 23 | import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl 24 | import kotlin.coroutines.CoroutineContext 25 | 26 | 27 | /** 28 | * 29 | * @author ForteScarlet 30 | */ 31 | internal class OneBotStrangerImpl( 32 | override val coroutineContext: CoroutineContext, 33 | private val source: GetStrangerInfoResult 34 | ) : OneBotStranger { 35 | 36 | override val id: ID 37 | get() = source.userId 38 | 39 | override val name: String 40 | get() = source.nickname 41 | 42 | override val age: Int 43 | get() = source.age 44 | 45 | override val sex: String 46 | get() = source.sex 47 | 48 | override fun toString(): String = 49 | "OneBotStranger(source=$source)" 50 | } 51 | 52 | internal fun GetStrangerInfoResult.toStranger( 53 | bot: OneBotBotImpl, 54 | coroutineContext: CoroutineContext = bot.subContext, 55 | ): OneBotStrangerImpl = 56 | OneBotStrangerImpl(coroutineContext, this) 57 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/CleanCacheApi.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.api 19 | 20 | import kotlin.Any 21 | import kotlin.String 22 | import kotlin.Unit 23 | import kotlin.jvm.JvmStatic 24 | import kotlinx.serialization.DeserializationStrategy 25 | import kotlinx.serialization.builtins.serializer 26 | 27 | /** 28 | * [`clean_cache`-清理缓存](https://github.com/botuniverse/onebot-11/blob/master/api/public.md#clean_cache-清理缓存) 29 | * 30 | * @author ForteScarlet 31 | */ 32 | public class CleanCacheApi private constructor() : OneBotApi { 33 | override val action: String 34 | get() = ACTION 35 | 36 | override val resultDeserializer: DeserializationStrategy 37 | get() = Unit.serializer() 38 | 39 | override val apiResultDeserializer: DeserializationStrategy> 40 | get() = OneBotApiResult.emptySerializer() 41 | 42 | override val body: Any? 43 | get() = null 44 | 45 | public companion object Factory { 46 | private const val ACTION: String = "clean_cache" 47 | 48 | private val INSTANCE: CleanCacheApi = CleanCacheApi() 49 | 50 | /** 51 | * 构建一个 [CleanCacheApi]. 52 | */ 53 | @JvmStatic 54 | public fun create(): CleanCacheApi = INSTANCE 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/exceptions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.api 19 | 20 | import io.ktor.http.* 21 | 22 | /** 23 | * 与 OneBot 的 Api 相关的异常。 24 | */ 25 | public open class OneBotApiException : RuntimeException { 26 | public constructor() : super() 27 | public constructor(message: String?) : super(message) 28 | public constructor(message: String?, cause: Throwable?) : super(message, cause) 29 | public constructor(cause: Throwable?) : super(cause) 30 | } 31 | 32 | /** 33 | * OneBotApi 请求的响应结果状态码不是成功状态 (即不是2xx) 34 | */ 35 | @Suppress("MemberVisibilityCanBePrivate") 36 | public open class OneBotApiResponseNotSuccessException( 37 | public val status: HttpStatusCode, 38 | message: String? = "status: $status", cause: Throwable? = null, 39 | ) : OneBotApiException(message, cause) 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/RawEventResolveResultImpl.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.bot.internal 2 | 3 | import kotlinx.serialization.json.JsonObject 4 | import love.forte.simbot.common.id.LongID 5 | import love.forte.simbot.component.onebot.v11.core.event.ExperimentalCustomEventResolverApi 6 | import love.forte.simbot.component.onebot.v11.core.event.RawEventResolveResult 7 | import love.forte.simbot.component.onebot.v11.event.RawEvent 8 | 9 | /** 10 | * 一个事件文本被进行解析后的主要内容。 11 | * 12 | * @author ForteScarlet 13 | */ 14 | @ExperimentalCustomEventResolverApi 15 | internal data class RawEventResolveResultImpl( 16 | override val text: String, 17 | override val json: JsonObject, 18 | override val postType: String, 19 | override val subType: String?, 20 | override val time: Long?, 21 | override val selfId: LongID?, 22 | override val rawEvent: RawEvent?, 23 | override val reason: Throwable? 24 | ) : RawEventResolveResult 25 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/component/OneBot11ComponentUsage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | 19 | @file:JvmName("OneBot11ComponentUsage") 20 | 21 | package love.forte.simbot.component.onebot.v11.core.component 22 | 23 | import love.forte.simbot.application.ApplicationBuilder 24 | import love.forte.simbot.application.ApplicationFactoryConfigurer 25 | import love.forte.simbot.common.function.ConfigurerFunction 26 | import kotlin.jvm.JvmName 27 | 28 | /** 29 | * 在 [ApplicationBuilder] 中安装使用 [OneBot11Component]。 30 | * 31 | * usage: 32 | * ```kotlin 33 | * simbotApplication(Foo) { 34 | * useOneBot11Component() 35 | * // 或 36 | * useOneBot11Component { ... } 37 | * } 38 | * ``` 39 | * 40 | * 相当于: 41 | * ```kotlin 42 | * simbotApplication(Foo) { 43 | * install(OneBot11Component) { ... } 44 | * } 45 | * ``` 46 | * 47 | * @see OneBot11Component 48 | * 49 | */ 50 | public fun ApplicationFactoryConfigurer<*, *, *>.useOneBot11Component( 51 | configurator: ConfigurerFunction? = null 52 | ) { 53 | if (configurator != null) { 54 | install(OneBot11Component, configurator) 55 | } else { 56 | install(OneBot11Component) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/CustomEventResolveException.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | /** 4 | * 当 [CustomEventResolver] 发生异常时, 5 | * 异常会被收集到 [CustomEventResolveException.suppressedExceptions] 中, 6 | * 并被最终输出。 7 | * 8 | * @since 1.8.0 9 | * 10 | * @author ForteScarlet 11 | */ 12 | public open class CustomEventResolveException : RuntimeException { 13 | public constructor() : super() 14 | public constructor(cause: Throwable?) : super(cause) 15 | public constructor(message: String?) : super(message) 16 | public constructor(message: String?, cause: Throwable?) : super(message, cause) 17 | } 18 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/CustomEventResolver.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | import kotlinx.serialization.json.Json 4 | import love.forte.simbot.component.onebot.v11.core.OneBot11 5 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 6 | import love.forte.simbot.event.Event 7 | 8 | /** 9 | * 自定义事件解析器。根据得到的初步解析结果,将事件内容解析为一个 [Event]。 10 | * 11 | * 当存在多个自定义解析器,则会在**首次**得到非 `null` 结果时终止处理。 12 | * 13 | * 如果处理链上得到的全部都为 `null`,则会在 [RawEventResolveResult.rawEvent] 14 | * 不为 `null` 的情况下尝试解析为标准事件。如果无法解析,则最终会被解析为 15 | * [love.forte.simbot.component.onebot.v11.event.UnknownEvent] 和对应的 16 | * [OneBotUnknownEvent]。 17 | * 18 | * ### 异常 19 | * 20 | * 如果 [resolve] 产生异常,此异常会被暂时记录,并继续尝试使用其他解析器。 21 | * 如果最终所有的 [CustomEventResolver] 都无法得到有效的结果,则: 22 | * - 如果 [RawEventResolveResult.rawEvent] 不为 `null`,则会尝试解析为标准事件。 23 | * - 如果解析成功,则记录的异常会以 **异常日志** 的形式输出。 24 | * - 如果解析失败,则会使用 [OneBotUnsupportedEvent] 进行包装,记录的异常会以 **异常日志** 的形式输出。 25 | * - 如果 [RawEventResolveResult.rawEvent] 为 `null`,则会使用 [OneBotUnknownEvent] 进行包装, 26 | * 记录的异常会以被整合并填充到 [love.forte.simbot.component.onebot.v11.event.UnknownEvent.reason] 中, 27 | * 并以 **异常日志** 的形式输出。 28 | * 29 | * @see CustomEventResolveException 30 | * @since 1.8.0 31 | * @author ForteScarlet 32 | */ 33 | @ExperimentalCustomEventResolverApi 34 | public fun interface CustomEventResolver { 35 | 36 | /** 37 | * 根据提供的内容信息,解析得到一个 [Event]。 38 | * 39 | * @return 解析结果。如果跳过解析则返回 `null`。 40 | * @throws Exception 解析过程可能出现的异常。 41 | */ 42 | @Throws(Exception::class) 43 | public fun resolve(context: Context): Event? 44 | 45 | /** 46 | * 提供给 [CustomEventResolver.resolve] 进行处理的内容。 47 | */ 48 | public interface Context { 49 | /** 50 | * 当前的 [OneBotBot] 对象。 51 | */ 52 | public val bot: OneBotBot 53 | 54 | /** 55 | * 可用于解析JSON的解析器。 56 | * 57 | * @see OneBot11.DefaultJson 58 | */ 59 | public val json: Json 60 | 61 | /** 62 | * 对原始事件内容的初步解析结果。 63 | */ 64 | public val rawEventResolveResult: RawEventResolveResult 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/CustomKotlinSerializationEventResolver.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | import kotlinx.serialization.DeserializationStrategy 4 | import love.forte.simbot.event.Event 5 | 6 | /** 7 | * 基于 Kotlin Serialization 反序列化器的 [CustomEventResolver]。 8 | * @since 1.8.0 9 | * @author ForteScarlet 10 | */ 11 | @ExperimentalCustomEventResolverApi 12 | public fun interface CustomKotlinSerializationEventResolver : CustomEventResolver { 13 | 14 | /** 15 | * 根据 [context] 得到一个 [DeserializationStrategy]。 16 | */ 17 | public fun serializer(context: CustomEventResolver.Context): DeserializationStrategy? 18 | 19 | override fun resolve(context: CustomEventResolver.Context): Event? { 20 | return serializer(context)?.let { 21 | return context.json.decodeFromJsonElement(it, context.rawEventResolveResult.json) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/EventResolveException.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | /** 4 | * 事件解析异常 5 | * 6 | * @since 1.8.0 7 | * @author ForteScarlet 8 | */ 9 | public open class EventResolveException : RuntimeException { 10 | public constructor() : super() 11 | public constructor(cause: Throwable?) : super(cause) 12 | public constructor(message: String?) : super(message) 13 | public constructor(message: String?, cause: Throwable?) : super(message, cause) 14 | } 15 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/ExperimentalCustomEventResolverApi.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | /** 4 | * 尚在实验中的自定义事件解析器API,可能在未来进行重大改动或被移除。 5 | * 6 | * @since 1.8.0 7 | * 8 | * @author ForteScarlet 9 | */ 10 | @RequiresOptIn( 11 | "尚在实验中的自定义事件解析器API,可能在未来进行重大改动或被移除。", 12 | RequiresOptIn.Level.WARNING, 13 | ) 14 | public annotation class ExperimentalCustomEventResolverApi 15 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/OneBotInternalEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event 19 | 20 | import love.forte.simbot.event.FuzzyEventTypeImplementation 21 | import love.forte.simbot.event.InternalEvent 22 | import love.forte.simbot.event.InternalInterceptionException 23 | 24 | 25 | /** 26 | * OneBot组件中实现 [InternalEvent] 的内部事件类型。 27 | * 28 | * 内部事件通常与真实的事件无关,是一些用于内部流转的通知或拦截事件。 29 | * 30 | * @since 1.6.0 31 | * 32 | * @author ForteScarlet 33 | */ 34 | @SubclassOptInRequired(FuzzyEventTypeImplementation::class) 35 | public interface OneBotInternalEvent : OneBotCommonEvent, InternalEvent 36 | 37 | 38 | public open class OneBotInternalInterceptionException : InternalInterceptionException { 39 | public constructor() : super() 40 | public constructor(message: String?) : super(message) 41 | public constructor(message: String?, cause: Throwable?) : super(message, cause) 42 | public constructor(cause: Throwable?) : super(cause) 43 | } 44 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/OneBotUnknownEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event 19 | 20 | import love.forte.simbot.annotations.FragileSimbotAPI 21 | import love.forte.simbot.common.id.ID 22 | import love.forte.simbot.common.id.UUID 23 | import love.forte.simbot.component.onebot.v11.event.UnknownEvent 24 | import love.forte.simbot.event.FuzzyEventTypeImplementation 25 | 26 | 27 | /** 28 | * OneBot组件对一个未知事件 [UnknownEvent] 的包装。 29 | * 30 | * 与 [OneBotUnsupportedEvent] 不同的是, 31 | * [OneBotUnknownEvent] 的事件类型明确为 [UnknownEvent], 32 | * 它是在 OneBot 协议本身上的“未知”,也就是指无法解析事件的报文。 33 | * 34 | * @author ForteScarlet 35 | */ 36 | @FragileSimbotAPI 37 | @OptIn(FuzzyEventTypeImplementation::class) 38 | public data class OneBotUnknownEvent( 39 | override val sourceEventRaw: String?, 40 | override val sourceEvent: UnknownEvent 41 | ) : OneBotEvent { 42 | /** 43 | * 一个无意义的随机ID。 44 | */ 45 | override val id: ID = UUID.random() 46 | } 47 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/RawEventResolveResult.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | import kotlinx.serialization.json.JsonObject 4 | import love.forte.simbot.common.id.LongID 5 | import love.forte.simbot.component.onebot.v11.event.RawEvent 6 | 7 | /** 8 | * 一个原始事件文本被解析后的基本结果。 9 | * 10 | * @since 1.8.0 11 | * @author ForteScarlet 12 | */ 13 | @ExperimentalCustomEventResolverApi 14 | public interface RawEventResolveResult { 15 | /** 16 | * 原始的事件JSON字符串文本。 17 | */ 18 | public val text: String 19 | 20 | /** 21 | * 经过解析后的 [JsonObject]。 22 | */ 23 | public val json: JsonObject 24 | 25 | /** 26 | * [json] 的 `post_type` 属性。 27 | * 在OneBot协议中这个属性的必须的,用于对事件进行首层分类。 28 | */ 29 | public val postType: String 30 | 31 | /** 32 | * [json] 的 `sub_type` 属性。 33 | * 在OneBot标准协议中这个属性始终存在,且获取它的 JSON KEY 34 | * 等同于 `$postType_type`。 35 | * 以标准事件为例子, 36 | * ```json 37 | * { 38 | * "post_type": "message", 39 | * "message_type": "private" 40 | * } 41 | * ``` 42 | * 当 `post_type` 为 `message` 时,`sub_type` 即代表 `message_type`,则其值为 `private`。 43 | */ 44 | public val subType: String? 45 | 46 | /** 47 | * jsonObject 的 `time` 属性。 48 | */ 49 | public val time: Long? 50 | 51 | /** 52 | * jsonObject 的 `self_id` 属性。是一个长整型ID。 53 | */ 54 | public val selfId: LongID? 55 | 56 | /** 57 | * 如果能被标准事件类型成功解析,则此处为被解析出来的标准事件,否则为 `null`。 58 | */ 59 | public val rawEvent: RawEvent? 60 | 61 | /** 62 | * 如果 [rawEvent] 是因为某些异常(例如序列化异常)才导致无法解析得到 `null` 的, 63 | * 则此处为解析时的异常。 64 | */ 65 | public val reason: Throwable? 66 | } 67 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/OneBotEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal 19 | 20 | import love.forte.simbot.component.onebot.v11.core.event.OneBotEvent 21 | 22 | internal fun OneBotEvent.eventToString( 23 | eventName: String 24 | ): String = 25 | "$eventName(source=$sourceEvent, raw='$sourceEventRaw')" 26 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/messageinteraction/DefaultPrivateMsgInteractionEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.messageinteraction 19 | 20 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 21 | import love.forte.simbot.component.onebot.v11.core.event.message.OneBotPrivateMessageEvent 22 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotSegmentsInteractionMessage 23 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotPrivateMessageEventPostReplyEvent 24 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotPrivateMessageEventPreReplyEvent 25 | import love.forte.simbot.message.MessageReceipt 26 | 27 | 28 | internal class OneBotDefaultPrivateMessageEventPreReplyEventImpl( 29 | override val bot: OneBotBot, 30 | override val content: OneBotPrivateMessageEvent, 31 | message: OneBotSegmentsInteractionMessage, 32 | ) : AbstractMessagePreSendEventImpl(message), OneBotPrivateMessageEventPreReplyEvent 33 | 34 | internal class OneBotDefaultPrivateMessageEventPostReplyEventImpl( 35 | override val bot: OneBotBot, 36 | override val content: OneBotPrivateMessageEvent, 37 | override val receipt: MessageReceipt, 38 | override val message: OneBotSegmentsInteractionMessage, 39 | ) : AbstractMessagePostSendEventImpl(), OneBotPrivateMessageEventPostReplyEvent 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/messageinteraction/FriendInteractionEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.messageinteraction 19 | 20 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotFriend 21 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 22 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotFriendPostSendEvent 23 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotFriendPreSendEvent 24 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotSegmentsInteractionMessage 25 | import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt 26 | 27 | internal class OneBotFriendPreSendEventImpl( 28 | override val content: OneBotFriend, 29 | override val bot: OneBotBot, 30 | message: OneBotSegmentsInteractionMessage 31 | ) : AbstractMessagePreSendEventImpl(message), OneBotFriendPreSendEvent 32 | 33 | internal class OneBotFriendPostSendEventImpl( 34 | override val content: OneBotFriend, 35 | override val bot: OneBotBot, 36 | override val receipt: OneBotMessageReceipt, 37 | override val message: OneBotSegmentsInteractionMessage, 38 | ) : AbstractMessagePostSendEventImpl(), OneBotFriendPostSendEvent 39 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/messageinteraction/FriendMsgInteractionEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.messageinteraction 19 | 20 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 21 | import love.forte.simbot.component.onebot.v11.core.event.message.OneBotFriendMessageEvent 22 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotSegmentsInteractionMessage 23 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotFriendMessageEventPostReplyEvent 24 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotFriendMessageEventPreReplyEvent 25 | import love.forte.simbot.message.MessageReceipt 26 | 27 | 28 | internal class OneBotFriendMessageEventPreReplyEventImpl( 29 | override val bot: OneBotBot, 30 | override val content: OneBotFriendMessageEvent, 31 | message: OneBotSegmentsInteractionMessage, 32 | ) : AbstractMessagePreSendEventImpl(message), OneBotFriendMessageEventPreReplyEvent 33 | 34 | internal class OneBotFriendMessageEventPostReplyEventImpl( 35 | override val bot: OneBotBot, 36 | override val content: OneBotFriendMessageEvent, 37 | override val receipt: MessageReceipt, 38 | override val message: OneBotSegmentsInteractionMessage, 39 | ) : AbstractMessagePostSendEventImpl(), OneBotFriendMessageEventPostReplyEvent 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/messageinteraction/GroupInteractionEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.messageinteraction 19 | 20 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup 21 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 22 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotGroupPostSendEvent 23 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotGroupPreSendEvent 24 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotSegmentsInteractionMessage 25 | import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt 26 | 27 | internal class OneBotGroupPreSendEventImpl( 28 | override val content: OneBotGroup, 29 | override val bot: OneBotBot, 30 | message: OneBotSegmentsInteractionMessage 31 | ) : AbstractMessagePreSendEventImpl(message), OneBotGroupPreSendEvent 32 | 33 | internal class OneBotGroupPostSendEventImpl( 34 | override val content: OneBotGroup, 35 | override val bot: OneBotBot, 36 | override val receipt: OneBotMessageReceipt, 37 | override val message: OneBotSegmentsInteractionMessage 38 | ) : AbstractMessagePostSendEventImpl(), OneBotGroupPostSendEvent 39 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/messageinteraction/MemberInteractionEventImpls.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.messageinteraction 19 | 20 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember 21 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 22 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotMemberPostSendEvent 23 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotMemberPreSendEvent 24 | import love.forte.simbot.component.onebot.v11.core.event.messageinteraction.OneBotSegmentsInteractionMessage 25 | import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt 26 | 27 | 28 | internal class OneBotMemberPreSendEventImpl( 29 | override val content: OneBotMember, 30 | override val bot: OneBotBot, 31 | message: OneBotSegmentsInteractionMessage 32 | ) : AbstractMessagePreSendEventImpl(message), OneBotMemberPreSendEvent 33 | 34 | internal class OneBotMemberPostSendEventImpl( 35 | override val content: OneBotMember, 36 | override val bot: OneBotBot, 37 | override val receipt: OneBotMessageReceipt, 38 | override val message: OneBotSegmentsInteractionMessage, 39 | ) : AbstractMessagePostSendEventImpl(), OneBotMemberPostSendEvent 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotFriendAddEventImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.notice 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.StringID.Companion.ID 22 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 23 | import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString 24 | import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotFriendAddEvent 25 | import love.forte.simbot.component.onebot.v11.event.notice.RawFriendAddEvent 26 | 27 | 28 | /** 29 | * 30 | * @author ForteScarlet 31 | */ 32 | internal class OneBotFriendAddEventImpl( 33 | override val sourceEventRaw: String?, 34 | override val sourceEvent: RawFriendAddEvent, 35 | override val bot: OneBotBot 36 | ) : OneBotFriendAddEvent { 37 | override val id: ID 38 | get() = with(sourceEvent) { 39 | "$postType-$noticeType-$userId-$time" 40 | }.ID 41 | 42 | override fun toString(): String = 43 | eventToString("OneBotFriendAddEvent") 44 | } 45 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotFriendRecallEventImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.notice 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.StringID.Companion.ID 22 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotFriend 23 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 24 | import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString 25 | import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotFriendRecallEvent 26 | import love.forte.simbot.component.onebot.v11.event.notice.RawFriendRecallEvent 27 | 28 | 29 | /** 30 | * 31 | * @author ForteScarlet 32 | */ 33 | internal class OneBotFriendRecallEventImpl( 34 | override val sourceEventRaw: String?, 35 | override val sourceEvent: RawFriendRecallEvent, 36 | override val bot: OneBotBot 37 | ) : OneBotFriendRecallEvent { 38 | override val id: ID 39 | get() = with(sourceEvent) { 40 | "$postType-$noticeType-$userId-$messageId-$time" 41 | }.ID 42 | 43 | override suspend fun content(): OneBotFriend { 44 | return bot.contactRelation.contact(sourceEvent.userId) 45 | ?: error("Friend with id ${sourceEvent.userId} not found") 46 | } 47 | 48 | override fun toString(): String = 49 | eventToString("OneBotFriendRecallEvent") 50 | } 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupRecallEventImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.notice 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.StringID.Companion.ID 22 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup 23 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 24 | import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString 25 | import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupRecallEvent 26 | import love.forte.simbot.component.onebot.v11.event.notice.RawGroupRecallEvent 27 | 28 | 29 | /** 30 | * 31 | * @author ForteScarlet 32 | */ 33 | internal class OneBotGroupRecallEventImpl( 34 | override val sourceEventRaw: String?, 35 | override val sourceEvent: RawGroupRecallEvent, 36 | override val bot: OneBotBot 37 | ) : OneBotGroupRecallEvent { 38 | override val id: ID 39 | get() = with(sourceEvent) { 40 | "$postType-$noticeType-$groupId-$userId-$messageId-$time" 41 | }.ID 42 | 43 | override suspend fun content(): OneBotGroup { 44 | return bot.groupRelation.group(groupId) 45 | ?: error("Group with id $groupId not found") 46 | } 47 | 48 | override fun toString(): String = 49 | eventToString("OneBotGroupRecallEvent") 50 | } 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupUploadEventImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.notice 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.StringID.Companion.ID 22 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup 23 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 24 | import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString 25 | import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupUploadEvent 26 | import love.forte.simbot.component.onebot.v11.event.notice.RawGroupUploadEvent 27 | 28 | 29 | /** 30 | * 31 | * @author ForteScarlet 32 | */ 33 | internal class OneBotGroupUploadEventImpl( 34 | override val sourceEventRaw: String?, 35 | override val sourceEvent: RawGroupUploadEvent, 36 | override val bot: OneBotBot 37 | ) : OneBotGroupUploadEvent { 38 | override val id: ID 39 | get() = with(sourceEvent) { 40 | "$postType-$noticeType-$groupId-$userId-$time" 41 | }.ID 42 | 43 | override suspend fun content(): OneBotGroup { 44 | return bot.groupRelation.group(groupId) 45 | ?: error("Group with id $groupId not found") 46 | } 47 | 48 | override fun toString(): String = 49 | eventToString("OneBotGroupUploadEvent") 50 | } 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/stage/OneBotBotStageEventImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.internal.stage 19 | 20 | import love.forte.simbot.annotations.ExperimentalSimbotAPI 21 | import love.forte.simbot.common.id.ID 22 | import love.forte.simbot.common.id.UUID 23 | import love.forte.simbot.common.time.Timestamp 24 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 25 | import love.forte.simbot.component.onebot.v11.core.event.stage.OneBotBotRegisteredEvent 26 | import love.forte.simbot.component.onebot.v11.core.event.stage.OneBotBotStartedEvent 27 | 28 | internal class OneBotBotRegisteredEventImpl( 29 | override val bot: OneBotBot 30 | ) : OneBotBotRegisteredEvent { 31 | override val id: ID = UUID.random() 32 | 33 | @OptIn(ExperimentalSimbotAPI::class) 34 | override val time: Timestamp = Timestamp.now() 35 | 36 | override fun toString(): String = 37 | "OneBotBotRegisteredEvent(bot=$bot)" 38 | } 39 | 40 | internal class OneBotBotStartedEventImpl( 41 | override val bot: OneBotBot 42 | ) : OneBotBotStartedEvent { 43 | override val id: ID = UUID.random() 44 | 45 | @OptIn(ExperimentalSimbotAPI::class) 46 | override val time: Timestamp = Timestamp.now() 47 | 48 | override fun toString(): String = 49 | "OneBotBotStartedEvent(bot=$bot)" 50 | } 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/meta/OneBotHeartbeatEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.meta 19 | 20 | import love.forte.simbot.component.onebot.v11.common.api.StatusResult 21 | import love.forte.simbot.component.onebot.v11.event.meta.RawHeartbeatEvent 22 | import love.forte.simbot.component.onebot.v11.event.meta.RawMetaEvent 23 | import love.forte.simbot.event.FuzzyEventTypeImplementation 24 | import kotlin.time.Duration 25 | import kotlin.time.Duration.Companion.milliseconds 26 | 27 | 28 | /** 29 | * [心跳事件](https://github.com/botuniverse/onebot-11/blob/master/event/meta.md#心跳) 30 | * 31 | * @see RawMetaEvent 32 | * 33 | * @author ForteScarlet 34 | */ 35 | @OptIn(FuzzyEventTypeImplementation::class) 36 | public interface OneBotHeartbeatEvent : OneBotMetaEvent { 37 | override val sourceEvent: RawHeartbeatEvent 38 | 39 | /** 40 | * 状态信息 41 | */ 42 | public val status: StatusResult 43 | get() = sourceEvent.status 44 | 45 | /** 46 | * 到下次心跳的间隔,单位毫秒 47 | */ 48 | public val intervalMilliseconds: Long 49 | get() = sourceEvent.interval 50 | } 51 | 52 | /** 53 | * 到下次心跳的间隔 54 | * 55 | * @see OneBotHeartbeatEvent.intervalMilliseconds 56 | */ 57 | public inline val OneBotHeartbeatEvent.interval: Duration 58 | get() = intervalMilliseconds.milliseconds 59 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/meta/OneBotLifecycleEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.meta 19 | 20 | import love.forte.simbot.component.onebot.v11.event.meta.RawLifecycleEvent 21 | import love.forte.simbot.event.FuzzyEventTypeImplementation 22 | 23 | 24 | /** 25 | * [生命周期](https://github.com/botuniverse/onebot-11/blob/master/event/meta.md#生命周期) 26 | * 27 | * @see RawLifecycleEvent 28 | * 29 | * @author ForteScarlet 30 | */ 31 | @OptIn(FuzzyEventTypeImplementation::class) 32 | public interface OneBotLifecycleEvent : OneBotMetaEvent { 33 | override val sourceEvent: RawLifecycleEvent 34 | 35 | /** 36 | * 事件子类型,分别表示 OneBot 启用、停用、WebSocket 连接成功. 37 | * 可能的值: `enable`、`disable`、`connect`. 38 | */ 39 | public val subType: String 40 | get() = sourceEvent.subType 41 | } 42 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/meta/OneBotMetaEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.meta 19 | 20 | import love.forte.simbot.component.onebot.v11.core.event.OneBotBotEvent 21 | import love.forte.simbot.component.onebot.v11.event.meta.RawMetaEvent 22 | import love.forte.simbot.event.FuzzyEventTypeImplementation 23 | 24 | 25 | /** 26 | * OneBot中的元事件类型。 27 | * @author ForteScarlet 28 | */ 29 | @SubclassOptInRequired(FuzzyEventTypeImplementation::class) 30 | public interface OneBotMetaEvent : OneBotBotEvent { 31 | override val sourceEvent: RawMetaEvent 32 | } 33 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/notice/OneBotFriendAddEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.notice 19 | 20 | import love.forte.simbot.common.id.LongID 21 | import love.forte.simbot.component.onebot.v11.event.notice.RawFriendAddEvent 22 | import love.forte.simbot.event.FuzzyEventTypeImplementation 23 | 24 | 25 | /** 26 | * 好友新增事件。 27 | * 28 | * @see RawFriendAddEvent 29 | */ 30 | @OptIn(FuzzyEventTypeImplementation::class) 31 | public interface OneBotFriendAddEvent : OneBotNoticeEvent { 32 | override val sourceEvent: RawFriendAddEvent 33 | 34 | /** 35 | * 此好友的ID 36 | */ 37 | public val userId: LongID 38 | get() = sourceEvent.userId 39 | 40 | // friend? or content()? 41 | } 42 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/notice/OneBotFriendRecallEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.notice 19 | 20 | import love.forte.simbot.common.id.ID 21 | import love.forte.simbot.common.id.LongID 22 | import love.forte.simbot.component.onebot.v11.core.actor.OneBotFriend 23 | import love.forte.simbot.component.onebot.v11.event.notice.RawFriendRecallEvent 24 | import love.forte.simbot.event.ContactEvent 25 | import love.forte.simbot.event.FuzzyEventTypeImplementation 26 | import love.forte.simbot.suspendrunner.STP 27 | 28 | 29 | /** 30 | * 好友消息撤回事件 31 | * @see RawFriendRecallEvent 32 | * @author ForteScarlet 33 | */ 34 | @OptIn(FuzzyEventTypeImplementation::class) 35 | public interface OneBotFriendRecallEvent : OneBotNoticeEvent, ContactEvent { 36 | override val sourceEvent: RawFriendRecallEvent 37 | 38 | /** 39 | * 消息ID 40 | */ 41 | public val messageId: ID 42 | get() = sourceEvent.messageId 43 | 44 | /** 45 | * 消息发送人的ID 46 | */ 47 | public val authorId: LongID 48 | get() = sourceEvent.userId 49 | 50 | /** 51 | * 好友 52 | * 53 | * @throws Exception 54 | */ 55 | @STP 56 | override suspend fun content(): OneBotFriend 57 | } 58 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/notice/OneBotNoticeEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.notice 19 | 20 | import love.forte.simbot.component.onebot.v11.core.event.OneBotBotEvent 21 | import love.forte.simbot.component.onebot.v11.event.notice.RawNoticeEvent 22 | import love.forte.simbot.event.FuzzyEventTypeImplementation 23 | 24 | 25 | /** 26 | * 通知事件 27 | * 28 | * @see RawNoticeEvent 29 | * 30 | * @author ForteScarlet 31 | */ 32 | @SubclassOptInRequired(FuzzyEventTypeImplementation::class) 33 | public interface OneBotNoticeEvent : OneBotBotEvent { 34 | override val sourceEvent: RawNoticeEvent 35 | } 36 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/stage/OneBotBotStageEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.event.stage 19 | 20 | import love.forte.simbot.bot.BotManager 21 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 22 | import love.forte.simbot.component.onebot.v11.core.event.OneBotInternalEvent 23 | import love.forte.simbot.event.BotRegisteredEvent 24 | import love.forte.simbot.event.BotStageEvent 25 | import love.forte.simbot.event.BotStartedEvent 26 | import love.forte.simbot.event.FuzzyEventTypeImplementation 27 | 28 | 29 | /** 30 | * OneBot组件中对 [BotStageEvent] 事件的实现类型。 31 | * 32 | * @author ForteScarlet 33 | */ 34 | @SubclassOptInRequired(FuzzyEventTypeImplementation::class) 35 | public interface OneBotBotStageEvent : BotStageEvent, OneBotInternalEvent { 36 | override val bot: OneBotBot 37 | } 38 | 39 | /** 40 | * 当一个 Bot 已经在某个 [BotManager] 中被注册后的事件。 41 | * 42 | * @author ForteScarlet 43 | */ 44 | @OptIn(FuzzyEventTypeImplementation::class) 45 | public interface OneBotBotRegisteredEvent : OneBotBotStageEvent, BotRegisteredEvent 46 | 47 | /** 48 | * 当一个 Bot **首次** 启动成功后的事件。 49 | * 50 | * @author ForteScarlet 51 | */ 52 | @OptIn(FuzzyEventTypeImplementation::class) 53 | public interface OneBotBotStartedEvent : OneBotBotStageEvent, BotStartedEvent 54 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/internal/message/OneBotMessageReceiptImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.internal.message 19 | 20 | import love.forte.simbot.ability.DeleteOption 21 | import love.forte.simbot.ability.StandardDeleteOption 22 | import love.forte.simbot.common.id.ID 23 | import love.forte.simbot.component.onebot.v11.core.api.DeleteMsgApi 24 | import love.forte.simbot.component.onebot.v11.core.api.SendMsgResult 25 | import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl 26 | import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt 27 | 28 | 29 | /** 30 | * @author ForteScarlet 31 | */ 32 | internal class OneBotMessageReceiptImpl( 33 | override val messageId: ID, 34 | private val bot: OneBotBotImpl, 35 | ) : OneBotMessageReceipt { 36 | override suspend fun delete(vararg options: DeleteOption) { 37 | kotlin.runCatching { 38 | bot.executeData(DeleteMsgApi.create(messageId)) 39 | }.onFailure { ex -> 40 | if (StandardDeleteOption.IGNORE_ON_FAILURE !in options) { 41 | throw ex 42 | } 43 | } 44 | } 45 | } 46 | 47 | 48 | internal fun SendMsgResult.toReceipt(bot: OneBotBotImpl): OneBotMessageReceiptImpl = 49 | OneBotMessageReceiptImpl(messageId, bot) 50 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/utils/EventPushLogs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.utils 19 | 20 | import kotlinx.coroutines.flow.Flow 21 | import love.forte.simbot.event.EventResult 22 | import love.forte.simbot.event.onEachError 23 | import love.forte.simbot.logger.Logger 24 | 25 | internal fun Flow.onEachErrorLog( 26 | logger: Logger 27 | ): Flow = onEachError { err -> 28 | logger.error( 29 | "Event process with an error result: {}", 30 | err.content.message, 31 | err.content 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/utils/MessageResolvers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.utils 19 | 20 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot 21 | import love.forte.simbot.component.onebot.v11.message.resolveToOneBotSegmentList 22 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegment 23 | import love.forte.simbot.message.Message 24 | 25 | internal fun Message.resolveToOneBotSegmentList( 26 | bot: OneBotBot, 27 | ): List = resolveToOneBotSegmentList( 28 | defaultImageAdditionalParams = bot.configuration.defaultImageAdditionalParamsProvider 29 | ) 30 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/utils/TimestampUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.utils 19 | 20 | import love.forte.simbot.common.time.TimeUnit 21 | import love.forte.simbot.common.time.Timestamp 22 | import love.forte.simbot.component.onebot.v11.core.event.OBSourceEvent 23 | 24 | // 虽然是 Long 类型,但是似乎是10位秒值 25 | internal fun OBSourceEvent.timestamp(): Timestamp = 26 | Timestamp.ofMilliseconds(TimeUnit.SECONDS.toMillis(time)) 27 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroupDeleteTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.actor 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.engine.mock.* 5 | import io.ktor.utils.io.core.* 6 | import kotlinx.coroutines.test.runTest 7 | import kotlinx.serialization.json.Json 8 | import kotlinx.serialization.json.JsonObject 9 | import kotlinx.serialization.json.booleanOrNull 10 | import kotlinx.serialization.json.jsonPrimitive 11 | import love.forte.simbot.common.id.IntID.Companion.ID 12 | import love.forte.simbot.component.onebot.v11.core.actor.internal.OneBotGroupImpl 13 | import love.forte.simbot.component.onebot.v11.core.api.SetGroupLeaveApi 14 | import love.forte.simbot.component.onebot.v11.core.api.requestData 15 | import kotlin.test.Test 16 | import kotlin.test.assertFalse 17 | import kotlin.test.assertNotNull 18 | import kotlin.test.assertTrue 19 | 20 | 21 | /** 22 | * 23 | * @author ForteScarlet 24 | */ 25 | class OneBotGroupDeleteTests { 26 | 27 | @Test 28 | fun oneBotGroupDeleteMarkTest() { 29 | var mark = OneBotGroupImpl.DeleteMark() 30 | assertFalse(mark.isDismiss) 31 | assertFalse(mark.isIgnoreFailure) 32 | 33 | mark = mark.dismiss() 34 | assertTrue(mark.isDismiss) 35 | 36 | mark = mark.ignoreFailure() 37 | assertTrue(mark.isIgnoreFailure) 38 | } 39 | 40 | @Test 41 | fun oneBotGroupDeleteTest() = runTest { 42 | HttpClient( 43 | MockEngine { reqData -> 44 | val json = reqData.body.toByteArray().decodeToString() 45 | val obj = Json.decodeFromString(JsonObject.serializer(), json) 46 | val dismiss = obj["is_dismiss"]?.jsonPrimitive?.booleanOrNull 47 | assertNotNull(dismiss) 48 | assertTrue(dismiss) 49 | respondOk("""{"retcode":0,"status":null,"data":null}""") 50 | } 51 | ).use { client -> 52 | SetGroupLeaveApi.create(123.ID, isDismiss = true).requestData( 53 | client, 54 | "127.0.0.1" 55 | ) 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotMemberDeleteTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.actor 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.engine.mock.* 5 | import io.ktor.utils.io.core.* 6 | import kotlinx.coroutines.test.runTest 7 | import kotlinx.serialization.json.Json 8 | import kotlinx.serialization.json.JsonObject 9 | import kotlinx.serialization.json.booleanOrNull 10 | import kotlinx.serialization.json.jsonPrimitive 11 | import love.forte.simbot.common.id.UIntID.Companion.ID 12 | import love.forte.simbot.common.id.ULongID.Companion.ID 13 | import love.forte.simbot.component.onebot.v11.core.actor.internal.OneBotMemberImpl 14 | import love.forte.simbot.component.onebot.v11.core.api.SetGroupKickApi 15 | import love.forte.simbot.component.onebot.v11.core.api.requestData 16 | import kotlin.test.Test 17 | import kotlin.test.assertFalse 18 | import kotlin.test.assertNotNull 19 | import kotlin.test.assertTrue 20 | 21 | 22 | /** 23 | * 24 | * @author ForteScarlet 25 | */ 26 | class OneBotMemberDeleteTests { 27 | @Test 28 | fun oneBotMemberDeleteMarkTest() { 29 | var mark = OneBotMemberImpl.DeleteMark() 30 | assertFalse(mark.isRejectRequest) 31 | assertFalse(mark.isIgnoreFailure) 32 | 33 | mark = mark.rejectRequest() 34 | assertTrue(mark.isRejectRequest) 35 | 36 | mark = mark.ignoreFailure() 37 | assertTrue(mark.isIgnoreFailure) 38 | } 39 | 40 | @Test 41 | fun oneBotMemberDeleteTest() = runTest { 42 | HttpClient( 43 | MockEngine { reqData -> 44 | val json = reqData.body.toByteArray().decodeToString() 45 | val obj = Json.decodeFromString(JsonObject.serializer(), json) 46 | val rejectRequest = obj["reject_add_request"]?.jsonPrimitive?.booleanOrNull 47 | assertNotNull(rejectRequest) 48 | assertTrue(rejectRequest) 49 | respondOk("""{"retcode":0,"status":null,"data":null}""") 50 | } 51 | ).use { client -> 52 | SetGroupKickApi.create(ULong.MAX_VALUE.ID, UInt.MAX_VALUE.ID, rejectAddRequest = true).requestData( 53 | client, 54 | "127.0.0.1" 55 | ) 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotApiEmptySerializerTest.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.api 2 | 3 | import kotlinx.serialization.json.Json 4 | import kotlin.test.* 5 | 6 | 7 | /** 8 | * 9 | * @author ForteScarlet 10 | */ 11 | class OneBotApiEmptySerializerTest { 12 | val json = Json { 13 | isLenient = true 14 | ignoreUnknownKeys = true 15 | } 16 | 17 | @Test 18 | fun deserializeNullDataTest() { 19 | val jsonText = """ 20 | {"retcode":0,"status":"OK","data":null} 21 | """.trim() 22 | 23 | val data = json.decodeFromString( 24 | OneBotApiResult.emptySerializer(), 25 | jsonText 26 | ) 27 | 28 | assertTrue(data.isSuccess) 29 | assertEquals(Unit, data.data) 30 | } 31 | 32 | @Test 33 | fun deserializeNoFieldDataTest() { 34 | val jsonText = """ 35 | {"retcode":0,"status":"OK"} 36 | """.trim() 37 | 38 | val data = json.decodeFromString( 39 | OneBotApiResult.emptySerializer(), 40 | jsonText 41 | ) 42 | 43 | assertTrue(data.isSuccess) 44 | assertEquals(Unit, data.data) 45 | } 46 | 47 | @Test 48 | fun deserializeFailedDataTest() { 49 | val jsonText = """ 50 | {"retcode":100,"status":"failed"} 51 | """.trim() 52 | 53 | val data = json.decodeFromString( 54 | OneBotApiResult.emptySerializer(), 55 | jsonText 56 | ) 57 | 58 | assertFalse(data.isSuccess) 59 | assertNull(data.data) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotMessageElementTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.api 2 | 3 | import kotlinx.serialization.json.Json 4 | import kotlinx.serialization.modules.plus 5 | import love.forte.simbot.common.id.IntID.Companion.ID 6 | import love.forte.simbot.component.onebot.v11.core.OneBot11 7 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotAt 8 | import love.forte.simbot.component.onebot.v11.message.segment.add 9 | import love.forte.simbot.message.At 10 | import love.forte.simbot.message.Messages 11 | import love.forte.simbot.message.buildMessages 12 | import love.forte.simbot.message.encodeMessagesToString 13 | import kotlin.test.Test 14 | 15 | 16 | /** 17 | * 18 | * @author ForteScarlet 19 | */ 20 | class OneBotMessageElementTests { 21 | 22 | @Test 23 | fun elementSerializationTest() { 24 | val json = Json(OneBot11.DefaultJson) { 25 | serializersModule = Messages.standardSerializersModule + serializersModule 26 | } 27 | 28 | val msgList = buildMessages { 29 | add(At(123.ID)) 30 | add(OneBotAt.create(1.ID)) 31 | } 32 | 33 | println(json.encodeMessagesToString(msgList)) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoingTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.api 2 | 3 | import kotlinx.serialization.json.Json 4 | import love.forte.simbot.common.id.StringID.Companion.ID 5 | import love.forte.simbot.component.onebot.v11.core.OneBot11 6 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotAt 7 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotFace 8 | import kotlin.test.Test 9 | import kotlin.test.assertEquals 10 | 11 | 12 | /** 13 | * 14 | * @author ForteScarlet 15 | */ 16 | class OneBotMessageOutgoingTests { 17 | private val json: Json = OneBot11.DefaultJson 18 | 19 | @Test 20 | fun serializationTest() { 21 | with(OneBotMessageOutgoing.create("[CQ:at,code=123]")) { 22 | val jsonStr = json.encodeToString(OneBotMessageOutgoing.serializer(), this) 23 | assertEquals("\"[CQ:at,code=123]\"", jsonStr) 24 | } 25 | 26 | with( 27 | OneBotMessageOutgoing.create( 28 | listOf( 29 | OneBotAt.create("123"), 30 | OneBotFace.create("456".ID) 31 | ) 32 | ) 33 | ) { 34 | val jsonStr = json.encodeToString(OneBotMessageOutgoing.serializer(), this) 35 | assertEquals( 36 | """[{"type":"at","data":{"qq":"123"}},{"type":"face","data":{"id":"456"}}]""", 37 | jsonStr 38 | ) 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/event/ResolveRawEventToEventTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.event 2 | 3 | import kotlinx.serialization.KSerializer 4 | import love.forte.simbot.component.onebot.v11.core.OneBot11 5 | import love.forte.simbot.component.onebot.v11.event.RawEvent 6 | import love.forte.simbot.component.onebot.v11.event.message.RawGroupMessageEvent 7 | 8 | 9 | /** 10 | * 11 | * @author ForteScarlet 12 | */ 13 | class ResolveRawEventToEventTests { 14 | 15 | // @Test // TODO 16 | fun resolveGroupMessageEventTest() { 17 | val event = decodeEvent( 18 | RawGroupMessageEvent.serializer(), 19 | "" 20 | ) 21 | 22 | } 23 | } 24 | 25 | private fun decodeEvent( 26 | serializer: KSerializer, 27 | raw: String 28 | ): T { 29 | return OneBot11.DefaultJson.decodeFromString( 30 | serializer, 31 | raw 32 | ) 33 | } 34 | 35 | // GroupMessageEvent 36 | // PrivateMessageEvent 37 | // HeartbeatEvent 38 | // LifecycleEvent 39 | // FriendAddEvent 40 | // FriendRecallEvent 41 | // GroupAdminEvent 42 | // GroupBanEvent 43 | // GroupDecreaseEvent 44 | // GroupIncreaseEvent 45 | // GroupRecallEvent 46 | // GroupUploadEvent 47 | // NotifyEvent 48 | // FriendRequestEvent 49 | // GroupRequestEvent 50 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/utils/ReplyMessageSegmentListTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core.utils 2 | 3 | import love.forte.simbot.common.id.IntID.Companion.ID 4 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotAt 5 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotDice 6 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotReply 7 | import kotlin.test.Test 8 | import kotlin.test.assertContentEquals 9 | import kotlin.test.assertEquals 10 | import kotlin.test.assertIs 11 | 12 | 13 | /** 14 | * 15 | * @author ForteScarlet 16 | */ 17 | class ReplyMessageSegmentListTests { 18 | 19 | @Test 20 | fun resolveReplyMessageSegmentListWithoutReplyTest() { 21 | val list = listOf( 22 | OneBotAt.create("1"), 23 | OneBotAt.createAtAll(), 24 | OneBotDice, 25 | ) 26 | 27 | val newList = resolveReplyMessageSegmentList(list, 0.ID) 28 | 29 | assertEquals(4, newList.size) 30 | assertIs(newList.first()) 31 | assertContentEquals(list, newList.subList(1, newList.size)) 32 | } 33 | 34 | @Test 35 | fun resolveReplyMessageSegmentListWithReplyTest() { 36 | val list = listOf( 37 | OneBotAt.create("1"), 38 | OneBotReply.create(10.ID), 39 | OneBotDice, 40 | ) 41 | 42 | val newList = resolveReplyMessageSegmentList(list, 0.ID) 43 | 44 | println(newList) 45 | 46 | assertEquals(3, newList.size) 47 | assertContentEquals(list, newList) 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jsMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotApiRequests.js.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.api 19 | 20 | /** 21 | * 始终得到 `true`。 22 | */ 23 | @Suppress("TopLevelPropertyNaming") 24 | internal actual const val isContentNegotiationRuntimeAvailable: Boolean = true 25 | internal actual fun initConfig(key: String, default: String?): String? = default 26 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jsMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBotManager.js.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.bot 19 | 20 | import love.forte.simbot.common.services.Services 21 | 22 | internal actual fun loadOneBotBotManagerConfigures(): Sequence = 23 | Services.loadProviders().map { it() } 24 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jsMain/kotlin/love/forte/simbot/component/onebot/v11/core/component/OneBot11Component.js.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.component 19 | 20 | import love.forte.simbot.common.services.Services 21 | 22 | internal actual fun loadOneBot11ComponentConfigures(): Sequence = 23 | Services.loadProviders().map { it() } 24 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBotManager.jvm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.bot 19 | 20 | import love.forte.simbot.common.services.Services 21 | import java.util.ServiceLoader 22 | 23 | internal actual fun loadOneBotBotManagerConfigures(): Sequence = 24 | ServiceLoader 25 | .load(OneBotBotManagerFactoryConfigurerProvider::class.java) 26 | .asSequence() + 27 | Services.loadProviders().map { it() } 28 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/kotlin/love/forte/simbot/component/onebot/v11/core/component/OneBot11Component.jvm.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.component 19 | 20 | import love.forte.simbot.common.services.Services 21 | import java.util.* 22 | 23 | internal actual fun loadOneBot11ComponentConfigures(): Sequence { 24 | return ServiceLoader 25 | .load(OneBot11ComponentFactoryConfigurerProvider::class.java) 26 | .asSequence() + 27 | Services.loadProviders().map { it() } 28 | } 29 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/resources/META-INF/services/love.forte.simbot.component.ComponentFactoryProvider: -------------------------------------------------------------------------------- 1 | love.forte.simbot.component.onebot.v11.core.component.OneBot11ComponentFactoryProvider 2 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/resources/META-INF/services/love.forte.simbot.plugin.PluginFactoryProvider: -------------------------------------------------------------------------------- 1 | love.forte.simbot.component.onebot.v11.core.bot.OneBotBotManagerFactoryProvider 2 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/kotlin/GetFileApi.kt: -------------------------------------------------------------------------------- 1 | import kotlinx.serialization.DeserializationStrategy 2 | import kotlinx.serialization.SerialName 3 | import kotlinx.serialization.Serializable 4 | import love.forte.simbot.component.onebot.v11.core.api.OneBotApi 5 | import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult 6 | 7 | // LLOneBot GetFile API 8 | 9 | class GetFileApi private constructor( 10 | override val body: Any 11 | ) : OneBotApi { 12 | 13 | override val action: String 14 | get() = ACTION 15 | 16 | override val resultDeserializer: DeserializationStrategy 17 | get() = GetFileResult.serializer() 18 | 19 | override val apiResultDeserializer: DeserializationStrategy> 20 | get() = RESULT_RES 21 | 22 | companion object { 23 | private const val ACTION: String = "get_file" 24 | private val RESULT_RES = OneBotApiResult.serializer(GetFileResult.serializer()) 25 | 26 | @JvmStatic 27 | fun create(fileId: String): GetFileApi { 28 | return GetFileApi(Body(fileId)) 29 | } 30 | } 31 | 32 | @Serializable 33 | internal data class Body( 34 | @SerialName("file_id") 35 | internal val fileId: String, 36 | ) 37 | } 38 | 39 | @Serializable 40 | data class GetFileResult( 41 | /** 42 | * 文件的绝对路径 43 | */ 44 | val file: String, 45 | @SerialName("file_name") 46 | val fileName: String = "", 47 | @SerialName("file_size") 48 | val fileSize: Long = -1L, 49 | val base64: String = "", 50 | ) 51 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/kotlin/LLOBApiTest.kt: -------------------------------------------------------------------------------- 1 | import io.ktor.client.* 2 | import io.ktor.client.engine.java.* 3 | import io.ktor.http.* 4 | import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoApi 5 | import love.forte.simbot.component.onebot.v11.core.api.GetStatusApi 6 | import love.forte.simbot.component.onebot.v11.core.api.GetVersionInfoApi 7 | import love.forte.simbot.component.onebot.v11.core.api.requestData 8 | 9 | suspend fun main() { 10 | val host = Url("http://localhost:3000") 11 | val client = HttpClient(Java) 12 | 13 | println( 14 | GetLoginInfoApi 15 | .create() 16 | .requestData( 17 | client, 18 | host, 19 | ) 20 | ) 21 | 22 | println( 23 | GetStatusApi.create() 24 | .requestData( 25 | client, 26 | host, 27 | ) 28 | ) 29 | 30 | println( 31 | GetVersionInfoApi.create() 32 | .requestData( 33 | client, 34 | host 35 | ) 36 | ) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/kotlin/LLOBWsTest.kt: -------------------------------------------------------------------------------- 1 | import io.ktor.client.* 2 | import io.ktor.client.engine.java.* 3 | import io.ktor.client.plugins.websocket.* 4 | import io.ktor.http.* 5 | import io.ktor.websocket.* 6 | import kotlinx.coroutines.* 7 | import kotlinx.coroutines.flow.catch 8 | import kotlinx.coroutines.flow.receiveAsFlow 9 | import love.forte.simbot.annotations.FragileSimbotAPI 10 | import love.forte.simbot.component.onebot.v11.core.OneBot11 11 | import kotlin.coroutines.EmptyCoroutineContext 12 | import kotlin.time.Duration.Companion.seconds 13 | 14 | @OptIn(FragileSimbotAPI::class, ExperimentalStdlibApi::class) 15 | suspend fun main() { 16 | val host = Url("ws://localhost:3001") 17 | val client = HttpClient(Java) { 18 | WebSockets {} 19 | } 20 | 21 | val job = SupervisorJob() 22 | val json = OneBot11.DefaultJson 23 | 24 | val scope = CoroutineScope(EmptyCoroutineContext) 25 | 26 | val session = client.webSocketSession { 27 | url { takeFrom(host) } 28 | } 29 | 30 | scope.launch { 31 | delay(5.seconds) 32 | job.cancel() 33 | } 34 | 35 | println(session.coroutineContext[Job]) 36 | println(session.coroutineContext[CoroutineDispatcher]) 37 | 38 | job.invokeOnCompletion { 39 | session.cancel("Cancelled by job") 40 | } 41 | 42 | try { 43 | session.incoming.receiveAsFlow() 44 | .catch { e -> 45 | println("incoming Err: $e") 46 | e.printStackTrace() 47 | } 48 | .collect { 49 | println("Received $it") 50 | } 51 | } catch (e: Exception) { 52 | println("withContext Err: $e") 53 | e.printStackTrace() 54 | } 55 | 56 | println(session) 57 | println(session.isActive) 58 | 59 | session.close() 60 | 61 | println(session) 62 | println(session.isActive) 63 | 64 | } 65 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/kotlin/love/forte/simbot/component/onebot/v11/core/ApiExecutableTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core 2 | 3 | import io.mockk.coVerify 4 | import io.mockk.mockk 5 | import kotlinx.coroutines.test.runTest 6 | import love.forte.simbot.component.onebot.v11.core.api.OneBotApi 7 | import love.forte.simbot.component.onebot.v11.core.api.OneBotApiExecutable 8 | import love.forte.simbot.component.onebot.v11.core.api.inExecutableScope 9 | 10 | /** 11 | * 12 | * @author ForteScarlet 13 | */ 14 | class ApiExecutableTests { 15 | // see https://github.com/mockk/mockk/issues/1282 16 | 17 | // @Test 18 | fun executableScopeTest() = runTest { 19 | val executable = mockk(relaxed = true) 20 | val api = mockk>(relaxed = true) 21 | 22 | executable.inExecutableScope { 23 | api.execute() 24 | } 25 | 26 | coVerify { executable.execute(any()) } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/kotlin/love/forte/simbot/component/onebot/v11/core/AppTest.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.core 2 | 3 | import io.ktor.client.engine.java.Java 4 | import io.ktor.http.Url 5 | import love.forte.simbot.application.listeners 6 | import love.forte.simbot.bot.get 7 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBotConfiguration 8 | import love.forte.simbot.component.onebot.v11.core.bot.OneBotBotManager 9 | import love.forte.simbot.component.onebot.v11.core.component.OneBot11Component 10 | import love.forte.simbot.component.onebot.v11.core.event.message.OneBotPrivateMessageEvent 11 | import love.forte.simbot.core.application.launchSimpleApplication 12 | import love.forte.simbot.event.process 13 | 14 | suspend fun main() { 15 | val app = launchSimpleApplication { 16 | install(OneBot11Component) 17 | install(OneBotBotManager) 18 | } 19 | 20 | app.listeners { 21 | process { event -> 22 | println("Event: $event") 23 | println("Event.plainText: ${event.messageContent.plainText}") 24 | println("Event.messages: ${event.messageContent.messages}") 25 | 26 | event.reply("喵") 27 | } 28 | 29 | } 30 | 31 | app.botManagers.get().apply { 32 | val bot = register( 33 | OneBotBotConfiguration().apply { 34 | botUniqueId = "2240189254" 35 | apiServerHost = Url("http://localhost:3000") 36 | eventServerHost = Url("ws://localhost:3001") 37 | wsClientEngineFactory = Java 38 | apiClientEngineFactory = Java 39 | accessToken("test") 40 | } 41 | ) 42 | 43 | bot.start() 44 | } 45 | 46 | app.join() 47 | } 48 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmTest/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/nativeMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotApiRequests.native.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.api 19 | 20 | /** 21 | * 始终得到 `true`。 22 | */ 23 | @Suppress("TopLevelPropertyNaming") 24 | internal actual const val isContentNegotiationRuntimeAvailable: Boolean = true 25 | internal actual fun initConfig(key: String, default: String?): String? = default 26 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/nativeMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBotManager.native.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.bot 19 | 20 | import love.forte.simbot.common.services.Services 21 | 22 | internal actual fun loadOneBotBotManagerConfigures(): Sequence = 23 | Services.loadProviders().map { it() } 24 | 25 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/nativeMain/kotlin/love/forte/simbot/component/onebot/v11/core/component/OneBot11Component.native.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.core.component 19 | 20 | import love.forte.simbot.common.services.Services 21 | 22 | internal actual fun loadOneBot11ComponentConfigures(): Sequence = 23 | Services.loadProviders().map { it() } 24 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/RawEventDeserializationException.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.event 2 | 3 | /** 4 | * 5 | * [RawEvent] 的反序列化异常。 6 | * @since 1.8.0 7 | * @author ForteScarlet 8 | */ 9 | public open class RawEventDeserializationException : RuntimeException { 10 | public constructor() : super() 11 | public constructor(cause: Throwable?) : super(cause) 12 | public constructor(message: String?) : super(message) 13 | public constructor(message: String?, cause: Throwable?) : super(message, cause) 14 | } 15 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/meta/RawHeartbeatEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.meta 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.LongID 23 | import love.forte.simbot.component.onebot.v11.common.api.StatusResult 24 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 25 | 26 | 27 | /** 28 | * [心跳](https://github.com/botuniverse/onebot-11/blob/master/event/meta.md#心跳) 29 | * 30 | * > 其中 `status` 字段的内容和 `get_status` 接口的快速操作相同。 31 | * 32 | * @property status 状态信息 33 | * @property interval 到下次心跳的间隔,单位毫秒 34 | * 35 | * @author ForteScarlet 36 | */ 37 | @Serializable 38 | @ExpectEventType(postType = RawMetaEvent.POST_TYPE, subType = "heartbeat") 39 | public data class RawHeartbeatEvent( 40 | override val time: Long, 41 | @SerialName("meta_event_type") 42 | override val metaEventType: String, 43 | @SerialName("self_id") 44 | override val selfId: LongID, 45 | @SerialName("post_type") 46 | override val postType: String, 47 | public val status: StatusResult, 48 | public val interval: Long = -1L, 49 | ) : RawMetaEvent 50 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/meta/RawLifecycleEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.meta 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.LongID 23 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 24 | 25 | /** 26 | * [生命周期](https://github.com/botuniverse/onebot-11/blob/master/event/meta.md#生命周期) 27 | * 28 | * 29 | * @property subType 事件子类型,分别表示 OneBot 启用、停用、WebSocket 连接成功. 30 | * 可能的值: `enable`、`disable`、`connect`. 31 | * 注意,目前生命周期元事件中,只有 HTTP POST 的情况下可以收到 `enable` 和 `disable`, 32 | * 只有正向 WebSocket 和反向 WebSocket 可以收到 `connect`。 33 | */ 34 | @Serializable 35 | @ExpectEventType(postType = RawMetaEvent.POST_TYPE, subType = "lifecycle") 36 | public data class RawLifecycleEvent( 37 | override val time: Long, 38 | @SerialName("self_id") 39 | override val selfId: LongID, 40 | @SerialName("post_type") 41 | override val postType: String, 42 | @SerialName("meta_event_type") 43 | override val metaEventType: String, 44 | @SerialName("sub_type") 45 | public val subType: String, 46 | ) : RawMetaEvent 47 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/meta/RawMetaEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.meta 19 | 20 | import love.forte.simbot.component.onebot.v11.event.RawEvent 21 | import love.forte.simbot.component.onebot.v11.event.ExpectEventSubTypeProperty 22 | 23 | 24 | /** 25 | * 26 | * [元事件](https://github.com/botuniverse/onebot-11/blob/master/event/meta.md) 27 | * 28 | * > 消息、通知、请求三大类事件是与聊天软件直接相关的、机器人真实接收到的事件, 29 | * 除了这些,OneBot 自己还会产生一类事件,这里称之为「元事件」, 30 | * 例如生命周期事件、心跳事件等,这类事件与 OneBot 本身的运行状态有关, 31 | * 而与聊天软件无关。元事件的上报方式和普通事件完全一样。 32 | * 33 | * @author ForteScarlet 34 | */ 35 | @ExpectEventSubTypeProperty(value = "metaEventType", postType = RawMetaEvent.POST_TYPE, name = "meta_event_type") 36 | public interface RawMetaEvent : RawEvent { 37 | /** 38 | * 元事件类型 39 | */ 40 | public val metaEventType: String 41 | 42 | public companion object { 43 | public const val POST_TYPE: String = "meta_event" 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/notice/RawFriendAddEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.notice 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.LongID 23 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 24 | 25 | /** 26 | * [好友添加](https://github.com/botuniverse/onebot-11/blob/master/event/notice.md#好友添加) 27 | * 28 | * @property userId 新添加好友 QQ 号。 29 | */ 30 | @ExpectEventType( 31 | postType = RawNoticeEvent.POST_TYPE, 32 | subType = "friend_add", 33 | ) 34 | @Serializable 35 | public data class RawFriendAddEvent( 36 | override val time: Long, 37 | @SerialName("self_id") 38 | override val selfId: LongID, 39 | @SerialName("post_type") 40 | override val postType: String, 41 | @SerialName("notice_type") 42 | override val noticeType: String, 43 | @SerialName("user_id") 44 | public val userId: LongID, 45 | ) : RawNoticeEvent 46 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/notice/RawFriendRecallEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.notice 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.LongID 23 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 24 | 25 | /** 26 | * [好友消息撤回](https://github.com/botuniverse/onebot-11/blob/master/event/notice.md#好友消息撤回) 27 | * 28 | * @property userId 好友 QQ 号。 29 | * @property messageId 被撤回的消息 ID。 30 | */ 31 | @ExpectEventType( 32 | postType = RawNoticeEvent.POST_TYPE, 33 | subType = "friend_recall", 34 | ) 35 | @Serializable 36 | public data class RawFriendRecallEvent( 37 | override val time: Long, 38 | @SerialName("self_id") 39 | override val selfId: LongID, 40 | @SerialName("post_type") 41 | override val postType: String, 42 | @SerialName("notice_type") 43 | override val noticeType: String, 44 | @SerialName("user_id") 45 | public val userId: LongID, 46 | @SerialName("message_id") 47 | public val messageId: LongID, 48 | ) : RawNoticeEvent 49 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/notice/RawGroupIncreaseEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.notice 19 | 20 | import kotlin.Long 21 | import kotlin.String 22 | import kotlinx.serialization.SerialName 23 | import kotlinx.serialization.Serializable 24 | import love.forte.simbot.common.id.LongID 25 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 26 | 27 | /** 28 | * [群成员增加](https://github.com/botuniverse/onebot-11/blob/master/event/notice.md#群成员增加) 29 | * 30 | * @property subType 事件子类型,分别表示管理员已同意入群、管理员邀请入群。 31 | * 可能的值: `approve`、`invite` 32 | * @property groupId 群号。 33 | * @property operatorId 操作者 QQ 号。 34 | * @property userId 加入者 QQ 号。 35 | */ 36 | @ExpectEventType( 37 | postType = RawNoticeEvent.POST_TYPE, 38 | subType = "group_increase", 39 | ) 40 | @Serializable 41 | public data class RawGroupIncreaseEvent( 42 | override val time: Long, 43 | @SerialName("self_id") 44 | override val selfId: LongID, 45 | @SerialName("post_type") 46 | override val postType: String, 47 | @SerialName("notice_type") 48 | override val noticeType: String, 49 | @SerialName("sub_type") 50 | public val subType: String, 51 | @SerialName("group_id") 52 | public val groupId: LongID, 53 | @SerialName("operator_id") 54 | public val operatorId: LongID? = null, 55 | @SerialName("user_id") 56 | public val userId: LongID, 57 | ) : RawNoticeEvent 58 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/notice/RawGroupRecallEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.notice 19 | 20 | import kotlin.Long 21 | import kotlin.String 22 | import kotlinx.serialization.SerialName 23 | import kotlinx.serialization.Serializable 24 | import love.forte.simbot.common.id.LongID 25 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 26 | 27 | /** 28 | * [群消息撤回](https://github.com/botuniverse/onebot-11/blob/master/event/notice.md#群消息撤回) 29 | * 30 | * @property groupId 群号。 31 | * @property userId 消息发送者 QQ 号。 32 | * @property operatorId 操作者 QQ 号。 33 | * @property messageId 被撤回的消息 ID。 34 | */ 35 | @ExpectEventType( 36 | postType = RawNoticeEvent.POST_TYPE, 37 | subType = "group_recall", 38 | ) 39 | @Serializable 40 | public data class RawGroupRecallEvent( 41 | override val time: Long, 42 | @SerialName("self_id") 43 | override val selfId: LongID, 44 | @SerialName("post_type") 45 | override val postType: String, 46 | @SerialName("notice_type") 47 | override val noticeType: String, 48 | @SerialName("group_id") 49 | public val groupId: LongID, 50 | @SerialName("user_id") 51 | public val userId: LongID, 52 | @SerialName("operator_id") 53 | public val operatorId: LongID?, 54 | @SerialName("message_id") 55 | public val messageId: LongID, 56 | ) : RawNoticeEvent 57 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/notice/RawNoticeEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.notice 19 | 20 | import love.forte.simbot.component.onebot.v11.event.RawEvent 21 | import love.forte.simbot.component.onebot.v11.event.ExpectEventSubTypeProperty 22 | 23 | 24 | /** 25 | * [通知事件](https://github.com/botuniverse/onebot-11/blob/master/event/notice.md) 26 | * 27 | * @author ForteScarlet 28 | */ 29 | @ExpectEventSubTypeProperty(value = "noticeType", postType = RawNoticeEvent.POST_TYPE, name = "notice_type") 30 | public interface RawNoticeEvent : RawEvent { 31 | /** 32 | * 通知类型 33 | */ 34 | public val noticeType: String 35 | 36 | public companion object { 37 | public const val POST_TYPE: String = "notice" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/request/RawFriendRequestEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.request 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.LongID 23 | import love.forte.simbot.component.onebot.v11.event.ExpectEventType 24 | 25 | 26 | /** 27 | * [加好友请求](https://github.com/botuniverse/onebot-11/blob/master/event/request.md#加好友请求) 28 | * 29 | * @property userId 发送请求的 QQ 号 30 | * @property comment 验证信息 31 | * @property flag 请求 flag,在调用处理请求的 API 时需要传入 32 | * 33 | * @author ForteScarlet 34 | */ 35 | @Serializable 36 | @ExpectEventType(postType = RawRequestEvent.POST_TYPE, subType = "friend") 37 | public data class RawFriendRequestEvent( 38 | override val time: Long, 39 | @SerialName("request_type") 40 | override val requestType: String, 41 | @SerialName("self_id") 42 | override val selfId: LongID, 43 | @SerialName("post_type") 44 | override val postType: String, 45 | @SerialName("user_id") 46 | public val userId: LongID, 47 | public val comment: String = "", 48 | public val flag: String, 49 | ) : RawRequestEvent 50 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/event/request/RawRequestEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.event.request 19 | 20 | import love.forte.simbot.component.onebot.v11.event.RawEvent 21 | import love.forte.simbot.component.onebot.v11.event.ExpectEventSubTypeProperty 22 | 23 | 24 | /** 25 | * [请求事件](https://github.com/botuniverse/onebot-11/blob/master/event/request.md) 26 | * 27 | * @author ForteScarlet 28 | */ 29 | @ExpectEventSubTypeProperty(value = "requestType", postType = RawRequestEvent.POST_TYPE, name = "request_type") 30 | public interface RawRequestEvent : RawEvent { 31 | /** 32 | * 请求类型 33 | */ 34 | public val requestType: String 35 | 36 | public companion object { 37 | public const val POST_TYPE: String = "request" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-event/src/jvmMain/java/module-info.java: -------------------------------------------------------------------------------- 1 | module simbot.component.onebot11v.event { 2 | requires kotlin.stdlib; 3 | requires simbot.api; 4 | requires simbot.component.onebot.common; 5 | requires static simbot.common.annotations; 6 | requires transitive simbot.component.onebot11v.common; 7 | requires transitive simbot.component.onebot11v.message; 8 | requires transitive kotlinx.coroutines.core; 9 | 10 | exports love.forte.simbot.component.onebot.v11.event; 11 | exports love.forte.simbot.component.onebot.v11.event.request; 12 | exports love.forte.simbot.component.onebot.v11.event.notice; 13 | exports love.forte.simbot.component.onebot.v11.event.meta; 14 | exports love.forte.simbot.component.onebot.v11.event.message; 15 | } 16 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageElement.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message 19 | 20 | import kotlinx.serialization.KSerializer 21 | import kotlinx.serialization.PolymorphicSerializer 22 | import kotlinx.serialization.builtins.ListSerializer 23 | import love.forte.simbot.message.Message 24 | 25 | 26 | /** 27 | * OneBot组件中的 [Message.Element] 统一类型。 28 | * 29 | * [OneBotMessageElement] 接口本身由内部实现,不可用于第三方自定义实现。 30 | * 31 | * @author ForteScarlet 32 | */ 33 | public interface OneBotMessageElement : Message.Element 34 | 35 | /** 36 | * 可用于便捷地直接对一个 37 | * [OneBotMessageElement] 列表进行序列化地序列化器。 38 | * 39 | * 注意:序列化/反序列化时需要确保模型内添加了 `OneBot11Component.SerializersModule`, 40 | * 因为这本质上是一个列表中的**多态**序列化器。 41 | */ 42 | public object OneBotMessageElementSerializer : KSerializer> by 43 | ListSerializer(PolymorphicSerializer(OneBotMessageElement::class)) 44 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageReceipt.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message 19 | 20 | import love.forte.simbot.ability.DeleteOption 21 | import love.forte.simbot.ability.StandardDeleteOption 22 | import love.forte.simbot.common.id.ID 23 | import love.forte.simbot.message.MessageReceipt 24 | 25 | 26 | /** 27 | * OneBot组件中,消息发送成功后得到的回执。 28 | * 29 | * @author ForteScarlet 30 | */ 31 | public interface OneBotMessageReceipt : MessageReceipt { 32 | /** 33 | * 消息发送后的结果id。 34 | */ 35 | public val messageId: ID 36 | 37 | /** 38 | * 删除此消息。 39 | * 40 | * 支持的操作: 41 | * - [StandardDeleteOption.IGNORE_ON_FAILURE] 忽略请求API所产生的异常 42 | * 43 | * @throws Exception 任何请求API过程中可能会产生的异常, 44 | * 例如因权限不足或消息不存在得到的请求错误 45 | */ 46 | override suspend fun delete(vararg options: DeleteOption) 47 | } 48 | 49 | // 实现在core模块:因为要使用到API 50 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/OneBotDice.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | 23 | /** 24 | * [掷骰子魔法表情](https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E6%8E%B7%E9%AA%B0%E5%AD%90%E9%AD%94%E6%B3%95%E8%A1%A8%E6%83%85) 25 | * 26 | */ 27 | @Serializable 28 | @SerialName(OneBotDice.TYPE) 29 | public object OneBotDice : 30 | OneBotMessageSegment, 31 | OneBotMessageSegmentElementResolver { 32 | public const val TYPE: String = "dice" 33 | 34 | override val data: Unit 35 | get() = Unit 36 | 37 | override fun toElement(): OneBotMessageSegmentElement = Element 38 | 39 | @Serializable 40 | @SerialName("ob11.segment.dice") 41 | public data object Element : OneBotMessageSegmentElement() { 42 | override val segment: OneBotDice 43 | get() = OneBotDice 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/OneBotReply.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import love.forte.simbot.common.id.ID 23 | import love.forte.simbot.message.MessageReference 24 | import kotlin.jvm.JvmStatic 25 | 26 | 27 | /** 28 | * [回复](https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E5%9B%9E%E5%A4%8D) 29 | * 30 | * @author ForteScarlet 31 | */ 32 | @Serializable 33 | @SerialName(OneBotReply.TYPE) 34 | public class OneBotReply private constructor( 35 | override val data: Data 36 | ) : OneBotMessageSegment, MessageReference { 37 | 38 | /** 39 | * The [Data.id]. 40 | * 41 | * @see Data.id 42 | */ 43 | override val id: ID 44 | get() = data.id 45 | 46 | public companion object Factory { 47 | public const val TYPE: String = "reply" 48 | 49 | /** 50 | * Create [OneBotReply]. 51 | * @param id 回复时引用的消息 ID 52 | */ 53 | @JvmStatic 54 | public fun create(id: ID): OneBotReply = 55 | OneBotReply(Data(id)) 56 | } 57 | 58 | /** 59 | * The Data of [OneBotReply]. 60 | * 61 | * @property id 回复时引用的消息 ID 62 | */ 63 | @Serializable 64 | public data class Data(val id: ID) 65 | } 66 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/OneBotRps.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | 23 | /** 24 | * [猜拳魔法表情](https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E7%8C%9C%E6%8B%B3%E9%AD%94%E6%B3%95%E8%A1%A8%E6%83%85) 25 | * 26 | */ 27 | @Serializable 28 | @SerialName(OneBotRps.TYPE) 29 | public object OneBotRps : OneBotMessageSegment { 30 | public const val TYPE: String = "rps" 31 | 32 | override val data: Unit 33 | get() = Unit 34 | } 35 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/OneBotShake.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | 23 | /** 24 | * [窗口抖动(戳一戳)](https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E7%AA%97%E5%8F%A3%E6%8A%96%E5%8A%A8%E6%88%B3%E4%B8%80%E6%88%B3-) 25 | * 26 | */ 27 | @Serializable 28 | @SerialName(OneBotShake.TYPE) 29 | public object OneBotShake : OneBotMessageSegment { 30 | public const val TYPE: String = "shake" 31 | 32 | override val data: Unit 33 | get() = Unit 34 | } 35 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/message/ListElementSerializationTests.kt: -------------------------------------------------------------------------------- 1 | package love.forte.simbot.component.onebot.v11.message 2 | 3 | import kotlinx.serialization.json.Json 4 | import kotlinx.serialization.modules.SerializersModule 5 | import kotlinx.serialization.modules.polymorphic 6 | import love.forte.simbot.common.id.IntID.Companion.ID 7 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotFace 8 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegment 9 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegmentSerializer 10 | import love.forte.simbot.component.onebot.v11.message.segment.OneBotText 11 | import love.forte.simbot.message.messageElementPolymorphic 12 | import kotlin.test.Test 13 | import kotlin.test.assertEquals 14 | 15 | 16 | /** 17 | * 18 | * @author ForteScarlet 19 | */ 20 | class ListElementSerializationTests { 21 | @Suppress("VariableNaming") 22 | private val defaultJson = Json { 23 | isLenient = true 24 | isLenient = true 25 | ignoreUnknownKeys = true 26 | allowSpecialFloatingPointValues = true 27 | prettyPrint = false 28 | serializersModule = SerializersModule { 29 | messageElementPolymorphic { 30 | includeAllComponentMessageElementImpls() 31 | } 32 | polymorphic(OneBotMessageElement::class) { 33 | includeAllComponentMessageElementImpls() 34 | } 35 | polymorphic(OneBotMessageSegment::class) { 36 | includeAllOneBotSegmentImpls() 37 | } 38 | } 39 | } 40 | 41 | @Test 42 | fun listSegmentTest() { 43 | val elementList: List = listOf( 44 | OneBotText.create("Text"), 45 | OneBotFace.create(123.ID), 46 | ) 47 | 48 | val jsonString = defaultJson.encodeToString(OneBotMessageSegmentSerializer, elementList) 49 | assertEquals( 50 | """[{"type":"text","data":{"text":"Text"}},{"type":"face","data":{"id":"123"}}]""", 51 | jsonString 52 | ) 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/jsMain/kotlin/love/forte/simbot/component/onebot/v11/message/MessageElementResolvers.js.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message 19 | 20 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/jsMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/StandardOneBotMessageSegments.js.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import love.forte.simbot.component.onebot.v11.message.Base64Encoder 21 | import love.forte.simbot.resource.Resource 22 | 23 | internal actual fun resolveResourceToFileValuePlatform( 24 | resource: Resource, 25 | localFileToBase64: Boolean, 26 | encoder: Base64Encoder 27 | ): String? = null 28 | 29 | internal actual fun uriResource(uri: String): Resource { 30 | throw UnsupportedOperationException("URI resource is not supported in JS platform") 31 | } 32 | 33 | internal actual fun pathResource(path: String): Resource { 34 | throw UnsupportedOperationException("Path resource is not supported in JS platform") 35 | } 36 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/jvmMain/java/module-info.java: -------------------------------------------------------------------------------- 1 | module simbot.component.onebot11v.message { 2 | requires kotlin.stdlib; 3 | requires simbot.api; 4 | requires simbot.component.onebot.common; 5 | requires static simbot.common.annotations; 6 | requires transitive kotlinx.serialization.core; 7 | requires simbot.common.suspendrunner; 8 | requires kotlinx.coroutines.core; 9 | 10 | exports love.forte.simbot.component.onebot.v11.message; 11 | exports love.forte.simbot.component.onebot.v11.message.segment; 12 | } 13 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/nativeMain/kotlin/love/forte/simbot/component/onebot/v11/message/MessageElementResolvers.native.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message 19 | -------------------------------------------------------------------------------- /simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/nativeMain/kotlin/love/forte/simbot/component/onebot/v11/message/segment/StandardOneBotMessageSegments.native.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-2025. ForteScarlet. 3 | * 4 | * This file is part of simbot-component-onebot. 5 | * 6 | * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms 7 | * of the GNU Lesser General Public License as published by the Free Software Foundation, 8 | * either version 3 of the License, or (at your option) any later version. 9 | * 10 | * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | * See the GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. 15 | * If not, see . 16 | */ 17 | 18 | package love.forte.simbot.component.onebot.v11.message.segment 19 | 20 | import love.forte.simbot.component.onebot.v11.message.Base64Encoder 21 | import love.forte.simbot.resource.Resource 22 | 23 | internal actual fun resolveResourceToFileValuePlatform( 24 | resource: Resource, 25 | localFileToBase64: Boolean, 26 | encoder: Base64Encoder 27 | ): String? = null 28 | 29 | internal actual fun uriResource(uri: String): Resource { 30 | throw UnsupportedOperationException("URI resource is not supported in native platform") 31 | } 32 | 33 | 34 | internal actual fun pathResource(path: String): Resource { 35 | throw UnsupportedOperationException("Path resource is not supported in native platform") 36 | } 37 | --------------------------------------------------------------------------------