Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: essence message setting #2314

Merged
merged 19 commits into from
Mar 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions mirai-core/src/commonMain/kotlin/contact/essence/EssencesImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package net.mamoe.mirai.internal.contact.essence

import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand All @@ -22,6 +23,7 @@ import net.mamoe.mirai.contact.checkBotPermission
import net.mamoe.mirai.contact.essence.EssenceMessageRecord
import net.mamoe.mirai.contact.essence.Essences
import net.mamoe.mirai.internal.contact.GroupImpl
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopEssenceMsgManager
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
Expand Down Expand Up @@ -129,11 +131,23 @@ internal class EssencesImpl(

override suspend fun remove(source: MessageSource) {
group.checkBotPermission(MemberPermission.ADMINISTRATOR)
group.bot.cancelDigest(
groupCode = group.id,
msgSeq = source.ids.first(),
msgRandom = source.internalIds.first()
)
try {
val result = group.bot.network.sendAndExpect(
TroopEssenceMsgManager.RemoveEssence(
group.bot.client,
group.uin,
source.internalIds.first(),
source.ids.first()
), 5000, 2
)
check(result.success) { result.msg ?: "移除精华消息失败" }
} catch (_: CancellationException) {
group.bot.cancelDigest(
groupCode = group.id,
msgSeq = source.ids.first(),
msgRandom = source.internalIds.first()
)
}
}

override fun asFlow(): Flow<EssenceMessageRecord> {
Expand Down