Skip to content

Commit

Permalink
Merge pull request #168 from simple-robot/dev/main
Browse files Browse the repository at this point in the history
Rrelease: v4.0.0
  • Loading branch information
ForteScarlet authored Aug 17, 2024
2 parents a52a73a + 0ad2cec commit 21d29fc
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 63 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# v4.0.0

> Release & Pull Notes: [v4.0.0](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0)
- feat(core): KookBot 支持根据引用查询消息内容的相关API ([`98a7fc1..500491e`](https://github.com/simple-robot/simpler-robot/compare/98a7fc1..8e460f6))

<details><summary><code>98a7fc1..500491e</code></summary>

- [`98a7fc1`](https://github.com/simple-robot/simpler-robot/commit/98a7fc1)
- [`500491e`](https://github.com/simple-robot/simpler-robot/commit/500491e)

</details>

- feat(core): KookMessageContent 支持根据引用查询消息内容的相关API ([`8e460f6`](https://github.com/simple-robot/simpler-robot/commit/8e460f6))
- build(deps): Update Kotlin to 2.0.10, simbot to 4.6.0 ([`f81d7e7`](https://github.com/simple-robot/simpler-robot/commit/f81d7e7))
- build(deps): bump ksp from 2.0.0-1.0.24 to 2.0.10-1.0.24 ([`11bfb0c`](https://github.com/simple-robot/simpler-robot/commit/11bfb0c))

# v4.0.0-beta6

> Release & Pull Notes: [v4.0.0-beta6](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0-beta6)
Expand Down
21 changes: 2 additions & 19 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@
import love.forte.gradle.common.core.project.ProjectDetail
import love.forte.gradle.common.core.property.systemProp

/*
* Copyright (c) 2022-2022 ForteScarlet <ForteScarlet@163.com>
*
* 本文件是 simbot-component-kook 的一部分。
*
* simbot-component-kook 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。
*
* 发布 simbot-component-kook 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。
*
* 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看:
* https://www.gnu.org/licenses
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
*
*
*/


object P : ProjectDetail() {
const val GROUP = "love.forte.simbot.component"
Expand All @@ -49,8 +32,8 @@ object P : ProjectDetail() {
override val homepage: String
get() = HOMEPAGE

const val VERSION = "4.0.0-beta6"
const val NEXT_VERSION = "4.0.0-beta7"
const val VERSION = "4.0.0"
const val NEXT_VERSION = "4.0.1"

override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
override val version = if (isSnapshot()) snapshotVersion else VERSION
Expand Down
5 changes: 1 addition & 4 deletions buildSrc/src/main/kotlin/changelog/GenerateChangelog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ fun Project.generateChangelog(tag: String) {

file.writeText(
"""
> [!note]
> 对应核心版本: [**v$coreVersion**](https://github.com/simple-robot/simpler-robot/releases/tag/v$coreVersion)
> [!warning]
> 目前版本尚处于 **`beta`** 阶段,代表仍然可能存在部分已知问题或未知问题,
> 以及尚未完善的内容和落后于官方更新的内容。
我们欢迎并期望着您的 [反馈](https://github.com/simple-robot/simbot-component-kook/issues) 或 [协助](https://github.com/simple-robot/simbot-component-kook/pulls),感谢您的贡献与支持!
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,6 @@ tasks.create("createChangelog") {
group = "documentation"
doFirst {
generateChangelog("v${P.version}")
// println("Generate change log for $version ...")
// // configurations.runtimeClasspath
// val changelogDir = rootProject.file(".changelog").also {
// it.mkdirs()
// }
// val file = File(changelogDir, "$version.md")
// if (!file.exists()) {
// file.createNewFile()
// val coreVersion = simbotVersion.toString()
// val autoGenerateText = """
//
// **部分依赖库版本参考**
//
// | **库** | **版本** |
// |---------|--------|
// | 核心库 | [**v$coreVersion**](https://github.com/ForteScarlet/simpler-robot/releases/tag/v$coreVersion) |
//
// > **Warning**
// 当前版本处于 **`ALPHA`**阶段,仍旧有很多[**已知问题**](https://github.com/simple-robot/simbot-component-kook/issues/)和可能存在的**潜在问题**,
// 如有发现问题请积极[反馈](https://github.com/simple-robot/simbot-component-kook/issues/)或 [协助我们解决](https://github.com/simple-robot/simbot-component-kook/pulls),非常感谢!
//
//
// """.trimIndent()
//
//
// file.writeText(autoGenerateText)
// }
}
}

6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[versions]
kotlin = "2.0.0"
kotlin = "2.0.10"
kotlinx-coroutines = "1.8.1"
kotlinx-serialization = "1.7.1"
dokka = "1.9.20"
openjdk-jmh = "1.37"
ktor = "2.3.12"
log4j = "2.23.0"
# simbot
simbot = "4.5.0"
simbot = "4.6.0"
suspendTransform = "0.9.0"
gradleCommon = "0.6.0"
# ksp
ksp = "2.0.0-1.0.24"
ksp = "2.0.10-1.0.24"
# https://square.github.io/kotlinpoet/
kotlinPoet = "1.18.1"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/*
* Copyright (c) 2023. ForteScarlet.
* Copyright (c) 2023-2024. ForteScarlet.
*
* This file is part of simbot-component-kook.
* This file is part of simbot-component-kook.
*
* simbot-component-kook 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-kook 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-kook 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.
* simbot-component-kook 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-kook,
* If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Lesser General Public License
* along with simbot-component-kook,
* If not, see <https://www.gnu.org/licenses/>.
*/

package love.forte.simbot.component.kook.bot
Expand All @@ -25,20 +28,25 @@ import love.forte.simbot.bot.GuildRelation
import love.forte.simbot.common.collectable.Collectable
import love.forte.simbot.common.id.ID
import love.forte.simbot.common.id.StringID.Companion.ID
import love.forte.simbot.common.id.literal
import love.forte.simbot.component.kook.KookComponent
import love.forte.simbot.component.kook.KookGuild
import love.forte.simbot.component.kook.KookUserChat
import love.forte.simbot.component.kook.message.KookAsset
import love.forte.simbot.component.kook.message.KookAssetImage
import love.forte.simbot.component.kook.message.KookChannelMessageDetailsContent.Companion.toContent
import love.forte.simbot.component.kook.message.KookMessageContent
import love.forte.simbot.component.kook.util.requestDataBy
import love.forte.simbot.kook.api.ApiResponseException
import love.forte.simbot.kook.api.ApiResultException
import love.forte.simbot.kook.api.asset.Asset
import love.forte.simbot.kook.api.asset.CreateAssetApi
import love.forte.simbot.kook.api.message.GetChannelMessageViewApi
import love.forte.simbot.kook.api.userchat.GetUserChatListApi
import love.forte.simbot.kook.messages.MessageType
import love.forte.simbot.kook.stdlib.Ticket
import love.forte.simbot.logger.Logger
import love.forte.simbot.message.MessageReference
import love.forte.simbot.suspendrunner.ST
import love.forte.simbot.suspendrunner.STP
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -162,6 +170,23 @@ public interface KookBot : Bot, CoroutineScope {
@Deprecated("Unsupported in KOOK", ReplaceWith("null"))
override val groupRelation: GroupRelation?
get() = null

/**
* 根据引用ID查询对应的 **频道消息** 的 [KookMessageContent]。
*/
@ST
override suspend fun messageFromId(id: ID): KookMessageContent {
val view = GetChannelMessageViewApi.create(id.literal).requestDataBy(this)
return view.toContent(this)
}

/**
* 根据引用查询对应的 **频道消息** 的 [KookMessageContent]。
*/
@ST
override suspend fun messageFromReference(reference: MessageReference): KookMessageContent {
return messageFromId(reference.id)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public data class KookChannelMessageDetailsContent internal constructor(
return details.quote?.asMessage()
}

override suspend fun referenceMessage(): KookMessageContent? {
val quote = details.quote ?: return null
val view = GetChannelMessageViewApi.create(quote.id).requestDataBy(bot)
return view.toContent(bot)
}

/**
* 删除当前的频道消息。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import love.forte.simbot.common.id.IntID.Companion.ID
import love.forte.simbot.common.id.StringID.Companion.ID
import love.forte.simbot.component.kook.bot.KookBot
import love.forte.simbot.component.kook.message.KookAttachmentMessage.Companion.asMessage
import love.forte.simbot.component.kook.message.KookChannelMessageDetailsContent.Companion.toContent
import love.forte.simbot.component.kook.message.KookMessages.AT_TYPE_ROLE
import love.forte.simbot.component.kook.message.KookMessages.AT_TYPE_USER
import love.forte.simbot.component.kook.message.KookQuote.Companion.asMessage
Expand All @@ -46,6 +47,8 @@ import love.forte.simbot.kook.api.message.GetChannelMessageViewApi
import love.forte.simbot.kook.api.message.GetDirectMessageViewApi
import love.forte.simbot.kook.api.userchat.CreateUserChatApi
import love.forte.simbot.kook.event.*
import love.forte.simbot.kook.messages.ChannelMessageDetails
import love.forte.simbot.kook.messages.DirectMessageDetails
import love.forte.simbot.kook.objects.card.CardMessage
import love.forte.simbot.logger.Logger
import love.forte.simbot.logger.LoggerFactory
Expand Down Expand Up @@ -159,6 +162,12 @@ public interface KookMessageContent : MessageContent, DeleteSupport {
@STP
override suspend fun reference(): KookQuote?

/**
* 根据 [消息引用][reference] 查询其对应的消息原内容。
*/
@STP
override suspend fun referenceMessage(): KookMessageContent?

/**
* 尝试根据当前消息ID删除目标。
*
Expand Down Expand Up @@ -192,6 +201,20 @@ private suspend fun referenceFromDirectWithChatCode(bot: KookBot, msgId: String,
return details.quote?.asMessage()
}

private suspend fun detailsFromChannel(bot: KookBot, msgId: String): ChannelMessageDetails {
val api = GetChannelMessageViewApi.create(msgId)
return bot.requestData(api)
}

private suspend fun detailsFromDirect(bot: KookBot, msgId: String, authorId: String): DirectMessageDetails {
val chat = CreateUserChatApi.create(authorId).requestDataBy(bot)
return detailsFromDirectWithChatCode(bot, msgId, chat.code)
}

private suspend fun detailsFromDirectWithChatCode(bot: KookBot, msgId: String, chatCode: String): DirectMessageDetails {
return GetDirectMessageViewApi.create(chatCode, msgId).requestDataBy(bot)
}

/**
* KOOK 消息事件所收到的消息正文类型。
*
Expand Down Expand Up @@ -239,6 +262,26 @@ public class KookReceiveMessageContent internal constructor(
}
}

override suspend fun referenceMessage(): KookMessageContent {
return if (isDirect) {
val details = detailsFromDirect(bot, source.msgId, source.authorId)
KookUpdatedMessageContent(
bot = bot,
isDirect = false,
chatCode = null,
rawContent = details.content,
msgId = details.id,
mention = emptyList(),
mentionRoles = emptyList(),
isMentionAll = false,
isMentionHere = false
)
} else {
val details = detailsFromChannel(bot, source.msgId)
details.toContent(bot)
}
}

@JvmSynthetic
override suspend fun delete(vararg options: DeleteOption) {
// TODO options
Expand Down Expand Up @@ -300,6 +343,27 @@ public class KookUpdatedMessageContent internal constructor(
}
}

@JvmSynthetic
override suspend fun referenceMessage(): KookMessageContent {
return if (isDirect) {
val details = detailsFromDirectWithChatCode(bot, msgId, chatCode!!)
KookUpdatedMessageContent(
bot = bot,
isDirect = false,
chatCode = null,
rawContent = details.content,
msgId = details.id,
mention = emptyList(),
mentionRoles = emptyList(),
isMentionAll = false,
isMentionHere = false
)
} else {
val details = detailsFromChannel(bot, msgId)
details.toContent(bot)
}
}

@JvmSynthetic
override suspend fun delete(vararg options: DeleteOption) {
// TODO options
Expand Down

0 comments on commit 21d29fc

Please sign in to comment.