Skip to content

Commit

Permalink
Merge pull request #8 from simple-robot/dev/support-notice-events
Browse files Browse the repository at this point in the history
支持Notice相关事件的组件事件类型实现,且组件事件中支持区分荣誉事件、红包人气王事件和戳一戳事件
  • Loading branch information
ForteScarlet authored Jun 8, 2024
2 parents b43ba29 + 80bb524 commit 7469750
Show file tree
Hide file tree
Showing 49 changed files with 2,746 additions and 214 deletions.
1,235 changes: 1,235 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ apiValidation {
// 实验性和内部API可能无法保证二进制兼容
nonPublicMarkers.addAll(
listOf(
"love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI",
"love.forte.simbot.component.onebot.common.annotations.ExperimentalOneBotAPI",

"love.forte.simbot.annotations.ExperimentalSimbotAPI",
"love.forte.simbot.annotations.InternalSimbotAPI",
"love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ import com.google.devtools.ksp.processing.SymbolProcessorProvider
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.WildcardTypeName
import com.squareup.kotlinpoet.asTypeName
import com.squareup.kotlinpoet.buildCodeBlock
import com.squareup.kotlinpoet.jvm.jvmMultifileClass
import com.squareup.kotlinpoet.jvm.jvmName
import com.squareup.kotlinpoet.ksp.toClassName
Expand Down Expand Up @@ -80,7 +88,10 @@ private const val FUNCTION_RESOLVER_SUB_TYPE_NAME = "resolveEventSubTypeFieldNam
private const val FILE_NAME = "EventResolver.generated"
private const val FILE_JVM_NAME = "EventResolvers"

private val InternalSimbotAPIClassName = ClassName("love.forte.simbot.annotations", "InternalSimbotAPI")
private val InternalAPIClassName = ClassName(
"love.forte.simbot.component.onebot.common.annotations",
"InternalOneBotAPI"
)

private class EventTypeResolverProcessor(val environment: SymbolProcessorEnvironment) : SymbolProcessor {
private val generated = AtomicBoolean(false)
Expand Down Expand Up @@ -201,7 +212,7 @@ private class EventTypeResolverProcessor(val environment: SymbolProcessorEnviron
rootSubEventTypes: List<KSClassDeclaration>
): FunSpec {
return FunSpec.builder(FUNCTION_RESOLVER_SERIALIZER_NAME).apply {
addAnnotation(InternalSimbotAPIClassName)
addAnnotation(InternalAPIClassName)
addParameter(FUNCTION_EVENT_PARAM_NAME, EventClassName)
returns(
KSerializerClassName.parameterizedBy(
Expand Down Expand Up @@ -365,7 +376,7 @@ private class EventTypeResolverProcessor(val environment: SymbolProcessorEnviron
values: Map<String, Map<String, KSClassDeclaration>>
): FunSpec {
return FunSpec.builder(FUNCTION_RESOLVER_SERIALIZER_NAME).apply {
addAnnotation(InternalSimbotAPIClassName)
addAnnotation(InternalAPIClassName)
addParameter(FUNCTION_POST_TYPE_PARAM_NAME, STRING)
addParameter(FUNCTION_SUB_TYPE_PARAM_NAME, STRING)
returns(
Expand Down Expand Up @@ -399,7 +410,7 @@ private class EventTypeResolverProcessor(val environment: SymbolProcessorEnviron
values: Map<String, Map<String, KSClassDeclaration>>
): FunSpec {
return FunSpec.builder(FUNCTION_RESOLVER_TYPE_NAME).apply {
addAnnotation(InternalSimbotAPIClassName)
addAnnotation(InternalAPIClassName)
addParameter(FUNCTION_POST_TYPE_PARAM_NAME, STRING)
addParameter(FUNCTION_SUB_TYPE_PARAM_NAME, STRING)
returns(
Expand Down Expand Up @@ -434,7 +445,7 @@ private class EventTypeResolverProcessor(val environment: SymbolProcessorEnviron
rootSubEventTypes: List<KSClassDeclaration>
): FunSpec {
return FunSpec.builder(FUNCTION_RESOLVER_SUB_TYPE_NAME).apply {
addAnnotation(InternalSimbotAPIClassName)
addAnnotation(InternalAPIClassName)
addParameter(FUNCTION_POST_TYPE_PARAM_NAME, STRING)

returns(STRING.copy(nullable = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ private const val SEGMENT_FUNCTION_NAME = "includeAllOneBotSegmentImpls"

private const val FILE_NAME = "OneBotMessageElements.generated"

private val InternalSimbotAPIClassName = ClassName("love.forte.simbot.annotations", "InternalSimbotAPI")
private val InternalAPIClassName = ClassName(
"love.forte.simbot.component.onebot.common.annotations",
"InternalOneBotAPI"
)

private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEnvironment) : SymbolProcessor {
private val generated = AtomicBoolean(false)
Expand Down Expand Up @@ -183,7 +186,7 @@ private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEn

return FunSpec.builder(functionName).apply {
addModifiers(KModifier.PUBLIC)
addAnnotation(InternalSimbotAPIClassName)
addAnnotation(InternalAPIClassName)
receiver(PolymorphicModuleBuilderClassName.parameterizedBy(baseType))
for (impl in impls) {
addCode("%M(%T.serializer())\n", memberName, impl.toClassName())
Expand Down
3 changes: 2 additions & 1 deletion simbot-component-onebot-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
optIn.addAll(
"love.forte.simbot.annotations.InternalSimbotAPI"
"love.forte.simbot.annotations.InternalSimbotAPI",
"love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package love.forte.simbot.component.onebot.common

import love.forte.simbot.annotations.InternalSimbotAPI
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI

/**
* An OneBot object.
*/
@InternalSimbotAPI
@InternalOneBotAPI
public object OneBot

// TODO 一些Opt注解放在这个模块?
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024. ForteScarlet.
*
* This file is part of simbot-component-onebot.
*
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
* If not, see <https://www.gnu.org/licenses/>.
*/

package love.forte.simbot.component.onebot.common.annotations

/**
* 标记为仅用于OneBot组件内部使用的API,可能会随时变更、删除
*/
@Retention(AnnotationRetention.BINARY)
@RequiresOptIn(
message = "仅用于OneBot组件内部使用的API,可能会随时变更、删除",
level = RequiresOptIn.Level.ERROR
)
@MustBeDocumented
public annotation class InternalOneBotAPI

/**
* 标记为OneBot组件中仍处于实验阶段的API,可能会随时变更、删除
*/
@Retention(AnnotationRetention.BINARY)
@RequiresOptIn(
message = "OneBot组件中仍处于实验阶段的API,可能会随时变更、删除",
level = RequiresOptIn.Level.ERROR
)
@MustBeDocumented
public annotation class ExperimentalOneBotAPI
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package love.forte.simbot.component.onebot.v11.common.utils

import love.forte.simbot.annotations.InternalSimbotAPI
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI
import kotlin.jvm.JvmName

/**
* 得到 `s=640` 的QQ头像。
*
* @param id QQ号
*/
@InternalSimbotAPI
@InternalOneBotAPI
public fun qqAvatar640(id: String): String =
"https://q1.qlogo.cn/g?b=qq&nk=$id&s=640"

Expand All @@ -36,6 +36,6 @@ public fun qqAvatar640(id: String): String =
*
* @param id QQ号
*/
@InternalSimbotAPI
@InternalOneBotAPI
public fun qqAvatar100(id: String): String =
"https://q1.qlogo.cn/g?b=qq&nk=$id&s=100"
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
optIn.addAll(
"love.forte.simbot.annotations.InternalSimbotAPI"
"love.forte.simbot.annotations.InternalSimbotAPI",
"love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.utils.io.charsets.*
import love.forte.simbot.annotations.InternalSimbotAPI
import love.forte.simbot.common.serialization.guessSerializer
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI
import love.forte.simbot.component.onebot.v11.core.OneBot11
import love.forte.simbot.logger.Logger
import love.forte.simbot.logger.LoggerFactory
Expand All @@ -41,7 +41,7 @@ import kotlin.jvm.JvmSynthetic
/**
* 用于在对 [OneBotApi] 发起请求时或得到想用后输出相关日志日志收集器。
*/
@InternalSimbotAPI
@InternalOneBotAPI
public val ApiLogger: Logger = LoggerFactory.getLogger("love.forte.simbot.component.onebot.v11.core.api.API")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import love.forte.simbot.bot.GroupRelation
import love.forte.simbot.bot.GuildRelation
import love.forte.simbot.common.collectable.Collectable
import love.forte.simbot.common.id.ID
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI
import love.forte.simbot.component.onebot.v11.core.actor.OneBotFriend
import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup
import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoApi
Expand Down Expand Up @@ -58,6 +59,13 @@ public interface OneBotBot : Bot {
*/
public val configuration: OneBotBotConfiguration

/**
* 由 [OneBotBot] 衍生出的 actor 使用的 [CoroutineContext]。
* 源自 [coroutineContext], 但是不包含 [Job][kotlinx.coroutines.Job]。
*/
@InternalOneBotAPI
public val subContext: CoroutineContext

/**
* [OneBotBot] 用于请求API的 [HttpClient]。
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package love.forte.simbot.component.onebot.v11.core.bot

import io.ktor.http.Url
import io.ktor.http.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import love.forte.simbot.annotations.InternalSimbotAPI
import love.forte.simbot.bot.SerializableBotConfiguration
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI
import love.forte.simbot.component.onebot.v11.core.component.OneBot11Component


Expand All @@ -33,7 +33,7 @@ import love.forte.simbot.component.onebot.v11.core.component.OneBot11Component
*
* @author ForteScarlet
*/
@InternalSimbotAPI
@InternalOneBotAPI
@Serializable
@SerialName(OneBot11Component.ID_VALUE)
public data class OneBotBotSerializableConfiguration(
Expand Down
Loading

0 comments on commit 7469750

Please sign in to comment.