diff --git a/simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/OneBot.kt b/simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/OneBot.kt index fac2f7c..45988ff 100644 --- a/simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/OneBot.kt +++ b/simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/OneBot.kt @@ -24,5 +24,3 @@ import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI */ @InternalOneBotAPI public object OneBot - -// TODO 一些Opt注解放在这个模块? diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt index 6393aa1..beeca5f 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt @@ -17,8 +17,8 @@ package love.forte.simbot.component.onebot.v11.core.bot -import io.ktor.client.HttpClient -import io.ktor.http.Url +import io.ktor.client.* +import io.ktor.http.* import kotlinx.coroutines.flow.count import kotlinx.coroutines.flow.firstOrNull import love.forte.simbot.bot.Bot @@ -30,6 +30,7 @@ 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.actor.OneBotMember import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoApi import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoResult import love.forte.simbot.suspendrunner.ST @@ -227,4 +228,16 @@ public interface OneBotBotGroupRelation : GroupRelation { @JvmSynthetic override suspend fun groupCount(): Int = groups.asFlow().count() + + /** + * 根据ID查询某个群中的某个成员。 + */ + @ST( + blockingBaseName = "getMember", + blockingSuffix = "", + asyncBaseName = "getMember", + reserveBaseName = "getMember" + ) + public suspend fun member(groupId: ID, memberId: ID): OneBotMember? + } diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/OneBotBotImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/OneBotBotImpl.kt index e2568b1..f8016b1 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/OneBotBotImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/OneBotBotImpl.kt @@ -61,13 +61,11 @@ import love.forte.simbot.common.id.StringID.Companion.ID import love.forte.simbot.component.onebot.v11.core.OneBot11 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.actor.OneBotMember import love.forte.simbot.component.onebot.v11.core.actor.internal.toFriend import love.forte.simbot.component.onebot.v11.core.actor.internal.toGroup -import love.forte.simbot.component.onebot.v11.core.api.GetFriendListApi -import love.forte.simbot.component.onebot.v11.core.api.GetGroupInfoApi -import love.forte.simbot.component.onebot.v11.core.api.GetGroupListApi -import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoApi -import love.forte.simbot.component.onebot.v11.core.api.GetLoginInfoResult +import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember +import love.forte.simbot.component.onebot.v11.core.api.* import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot import love.forte.simbot.component.onebot.v11.core.bot.OneBotBotConfiguration import love.forte.simbot.component.onebot.v11.core.bot.OneBotBotFriendRelation @@ -576,6 +574,12 @@ internal class OneBotBotImpl( // TODO owner? ) } + + override suspend fun member(groupId: ID, memberId: ID): OneBotMember { + // TODO 如何检测不存在? + return GetGroupMemberInfoApi.create(groupId, userId) + .requestDataBy(this@OneBotBotImpl).toMember(this@OneBotBotImpl) + } } override fun toString(): String = diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/message/OneBotPrivateMessageEventImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/message/OneBotPrivateMessageEventImpl.kt index 8f45441..9c1e9e6 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/message/OneBotPrivateMessageEventImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/message/OneBotPrivateMessageEventImpl.kt @@ -113,7 +113,7 @@ internal class OneBotGroupPrivateMessageEventImpl( override suspend fun source(): OneBotGroup { // TODO 额,怎么知道群号? // 无法得知群号 - throw UnsupportedOperationException("Don't know how to get the group number from PrivateMessageEvent") + throw UnsupportedOperationException("The way to get the group number from PrivateMessageEvent is unknown.") } override fun toString(): String = diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupAdminEventImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupAdminEventImpl.kt index 0a4a889..6846538 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupAdminEventImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupAdminEventImpl.kt @@ -21,10 +21,7 @@ import love.forte.simbot.common.id.ID import love.forte.simbot.common.id.StringID.Companion.ID import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember -import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember -import love.forte.simbot.component.onebot.v11.core.api.GetGroupMemberInfoApi -import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl -import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy +import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupAdminEvent import love.forte.simbot.component.onebot.v11.event.notice.GroupAdminEvent @@ -32,7 +29,7 @@ import love.forte.simbot.component.onebot.v11.event.notice.GroupAdminEvent internal class OneBotGroupAdminEventImpl( override val sourceEventRaw: String?, override val sourceEvent: GroupAdminEvent, - override val bot: OneBotBotImpl + override val bot: OneBotBot ) : OneBotGroupAdminEvent { override val id: ID get() = with(sourceEvent) { @@ -40,16 +37,18 @@ internal class OneBotGroupAdminEventImpl( }.ID override suspend fun content(): OneBotMember { - // TODO 换成 groupRelation - return GetGroupMemberInfoApi.create( + return bot.groupRelation.member( groupId = sourceEvent.groupId, - userId = sourceEvent.userId - ).requestDataBy(bot).toMember(bot) + memberId = sourceEvent.userId + ) ?: error( + "Member with id ${sourceEvent.userId} " + + "in Group ${sourceEvent.groupId} is not found" + ) } override suspend fun source(): OneBotGroup { return bot.groupRelation.group(sourceEvent.groupId) - ?: error("Group with id ${sourceEvent.groupId} not found") + ?: error("Group with id ${sourceEvent.groupId} is not found") } override fun toString(): String = diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupBanEventImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupBanEventImpl.kt index cd2ec5e..5f34368 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupBanEventImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupBanEventImpl.kt @@ -21,10 +21,7 @@ import love.forte.simbot.common.id.ID import love.forte.simbot.common.id.StringID.Companion.ID import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember -import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember -import love.forte.simbot.component.onebot.v11.core.api.GetGroupMemberInfoApi -import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl -import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy +import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupBanEvent import love.forte.simbot.component.onebot.v11.event.notice.GroupBanEvent @@ -37,7 +34,7 @@ import love.forte.simbot.component.onebot.v11.event.notice.GroupBanEvent internal class OneBotGroupBanEventImpl( override val sourceEventRaw: String?, override val sourceEvent: GroupBanEvent, - override val bot: OneBotBotImpl + override val bot: OneBotBot ) : OneBotGroupBanEvent { override val id: ID get() = with(sourceEvent) { @@ -45,16 +42,18 @@ internal class OneBotGroupBanEventImpl( }.ID override suspend fun content(): OneBotMember { - // TODO 换成 groupRelation - return GetGroupMemberInfoApi.create( + return bot.groupRelation.member( groupId = sourceEvent.groupId, - userId = sourceEvent.userId - ).requestDataBy(bot).toMember(bot) + memberId = sourceEvent.userId + ) ?: error( + "Member with id ${sourceEvent.userId} " + + "in Group ${sourceEvent.groupId} is not found" + ) } override suspend fun source(): OneBotGroup { return bot.groupRelation.group(sourceEvent.groupId) - ?: error("Group with id ${sourceEvent.groupId} not found") + ?: error("Group with id ${sourceEvent.groupId} is not found") } override fun toString(): String = diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupChangeEventImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupChangeEventImpl.kt index 88d7ebd..0168377 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupChangeEventImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotGroupChangeEventImpl.kt @@ -21,10 +21,8 @@ import love.forte.simbot.common.id.ID import love.forte.simbot.common.id.StringID.Companion.ID import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember -import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember -import love.forte.simbot.component.onebot.v11.core.api.GetGroupMemberInfoApi +import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl -import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupChangeEvent import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotGroupMemberDecreaseEvent @@ -45,26 +43,29 @@ internal abstract class OneBotGroupChangeEventImpl : OneBotGroupChangeEvent { override suspend fun content(): OneBotGroup { return bot.groupRelation.group(groupId) - ?: error("Group with id $groupId not found") + ?: error("Group with id $groupId is not found") } } internal class OneBotGroupMemberIncreaseEventImpl( override val sourceEventRaw: String?, override val sourceEvent: GroupIncreaseEvent, - override val bot: OneBotBotImpl + override val bot: OneBotBot ) : OneBotGroupChangeEventImpl(), OneBotGroupMemberIncreaseEvent { override suspend fun member(): OneBotMember { - // TODO 换成 groupRelation - return GetGroupMemberInfoApi.create( + return bot.groupRelation.member( groupId = sourceEvent.groupId, - userId = sourceEvent.userId - ).requestDataBy(bot).toMember(bot) + memberId = sourceEvent.userId + ) ?: error( + "Member with id ${sourceEvent.userId} " + + "in Group ${sourceEvent.groupId} is not found" + ) } override fun toString(): String = eventToString("OneBotGroupMemberIncreaseEvent") } + internal class OneBotGroupMemberDecreaseEventImpl( override val sourceEventRaw: String?, override val sourceEvent: GroupDecreaseEvent, diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotNotifyEventImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotNotifyEventImpl.kt index 34581d2..c612968 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotNotifyEventImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/internal/notice/OneBotNotifyEventImpl.kt @@ -21,16 +21,9 @@ import love.forte.simbot.common.id.ID import love.forte.simbot.common.id.StringID.Companion.ID import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember -import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember -import love.forte.simbot.component.onebot.v11.core.api.GetGroupMemberInfoApi import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl -import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy import love.forte.simbot.component.onebot.v11.core.event.internal.eventToString -import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotBotSelfPokeEvent -import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotHonorEvent -import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotLuckyKingEvent -import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotMemberPokeEvent -import love.forte.simbot.component.onebot.v11.core.event.notice.OneBotNotifyEvent +import love.forte.simbot.component.onebot.v11.core.event.notice.* import love.forte.simbot.component.onebot.v11.event.notice.NotifyEvent @@ -50,15 +43,17 @@ internal abstract class OneBotNotifyEventImpl( override suspend fun source(): OneBotGroup { return bot.groupRelation.group(groupId) - ?: error("Group with id $groupId not found") + ?: error("Group with id $groupId is not found") } override suspend fun content(): OneBotMember { - // TODO 换成 groupRelation - return GetGroupMemberInfoApi.create( + return bot.groupRelation.member( groupId = sourceEvent.groupId, - userId = sourceEvent.userId - ).requestDataBy(bot).toMember(bot) + memberId = sourceEvent.userId + ) ?: error( + "Member with id ${sourceEvent.userId} " + + "in Group ${sourceEvent.groupId} is not found" + ) } } diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/java/module-info.java b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/java/module-info.java index e79d1fa..b30846b 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/java/module-info.java +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/jvmMain/java/module-info.java @@ -37,6 +37,7 @@ exports love.forte.simbot.component.onebot.v11.core.event.meta; exports love.forte.simbot.component.onebot.v11.core.event.notice; exports love.forte.simbot.component.onebot.v11.core.event.request; + exports love.forte.simbot.component.onebot.v11.core.event.stage; exports love.forte.simbot.component.onebot.v11.core.utils; provides ComponentFactoryProvider with OneBot11ComponentFactoryProvider;