Skip to content

Commit

Permalink
Merge pull request #23 from simple-robot/dev/query-api-for-group-when…
Browse files Browse the repository at this point in the history
…-get-content-in-event

部分群消息事件实现中,获取 content 将直接查询API
  • Loading branch information
ForteScarlet authored Jun 12, 2024
2 parents be93060 + 4f4c64b commit 75e6755
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import love.forte.simbot.component.onebot.v11.core.bot.requestResultBy
import love.forte.simbot.component.onebot.v11.core.internal.message.toReceipt
import love.forte.simbot.component.onebot.v11.core.utils.sendGroupMsgApi
import love.forte.simbot.component.onebot.v11.core.utils.sendGroupTextMsgApi
import love.forte.simbot.component.onebot.v11.event.message.GroupMessageEvent
import love.forte.simbot.component.onebot.v11.message.OneBotMessageContent
import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt
import love.forte.simbot.component.onebot.v11.message.resolveToOneBotSegmentList
Expand Down Expand Up @@ -147,40 +146,6 @@ internal abstract class OneBotGroupImpl : OneBotGroup {
override fun toString(): String = "OneBotGroup(id=$id, bot=${bot.id})"
}

internal class OneBotGroupEventImpl(
private val source: GroupMessageEvent,
override val bot: OneBotBotImpl,

/**
* 群名称
*/
override val name: String,

/**
* 群主ID
*/
override val ownerId: ID?
) : OneBotGroupImpl() {
override val coroutineContext: CoroutineContext = bot.subContext

override val id: ID
get() = source.groupId
}

// TODO 群名称, 可能需要使用缓存或API初始化,
// 事件中似乎取不到
internal fun GroupMessageEvent.toGroup(
bot: OneBotBotImpl,
name: String = "",
ownerId: ID? = null
): OneBotGroupEventImpl =
OneBotGroupEventImpl(
source = this,
bot = bot,
name = name,
ownerId = ownerId,
)

/**
* 通过API查询得到的群信息。
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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.toGroup
import love.forte.simbot.component.onebot.v11.core.actor.internal.toMember
import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl
import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy
Expand Down Expand Up @@ -59,7 +58,8 @@ internal abstract class OneBotGroupMessageEventImpl(
)

override suspend fun content(): OneBotGroup {
return sourceEvent.toGroup(bot)
return bot.groupRelation.group(sourceEvent.groupId)
?: error("Group with id $groupId is not found")
}

override suspend fun reply(text: String): OneBotMessageReceipt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal class OneBotGroupPrivateMessageEventImpl(

override suspend fun source(): OneBotGroup {
// TODO 额,怎么知道群号?
throw UnsupportedOperationException("The way to get the group number from PrivateMessageEvent is unknown.")
throw UnsupportedOperationException("The way to get the group id from PrivateMessageEvent is unknown yet.")
}

override fun toString(): String =
Expand Down

0 comments on commit 75e6755

Please sign in to comment.