From a58d3403e7613d56aa24f1c7838ae53f318c1f42 Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Mon, 5 Apr 2021 14:34:19 +0200 Subject: [PATCH] Remove webhookId from behavior --- core/src/main/kotlin/behavior/MessageBehavior.kt | 13 +++---------- core/src/main/kotlin/entity/Message.kt | 2 +- .../main/kotlin/entity/channel/MessageChannel.kt | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/main/kotlin/behavior/MessageBehavior.kt b/core/src/main/kotlin/behavior/MessageBehavior.kt index ddf284c3f0c..4d9a4cf05d2 100644 --- a/core/src/main/kotlin/behavior/MessageBehavior.kt +++ b/core/src/main/kotlin/behavior/MessageBehavior.kt @@ -40,8 +40,6 @@ interface MessageBehavior : KordEntity, Strategizable { */ val channel get() = MessageChannelBehavior(channelId, kord) - val webhookId: Snowflake? - /** * Requests to get the channel this message was send in. */ @@ -200,7 +198,7 @@ interface MessageBehavior : KordEntity, Strategizable { */ override fun withStrategy( strategy: EntitySupplyStrategy<*>, - ): MessageBehavior = MessageBehavior(channelId, id, kord, webhookId, strategy) + ): MessageBehavior = MessageBehavior(channelId, id, kord) } @@ -208,13 +206,11 @@ fun MessageBehavior( channelId: Snowflake, messageId: Snowflake, kord: Kord, - webhookId: Snowflake? = null, strategy: EntitySupplyStrategy<*> = kord.resources.defaultStrategy, ) = object : MessageBehavior { override val channelId: Snowflake = channelId override val id: Snowflake = messageId override val kord: Kord = kord - override val webhookId: Snowflake? = webhookId override val supplier: EntitySupplier = strategy.supply(kord) override fun hashCode(): Int = Objects.hash(id) @@ -244,8 +240,6 @@ suspend inline fun MessageBehavior.edit(builder: MessageModifyBuilder.() -> Unit callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } - require(webhookId == null) { "Cannot perform edits on webhook messages use editWebhook() instead" } - val response = kord.rest.channel.editMessage(channelId = channelId, messageId = id, builder = builder) val data = MessageData.from(response) @@ -264,6 +258,7 @@ suspend inline fun MessageBehavior.edit(builder: MessageModifyBuilder.() -> Unit */ @OptIn(ExperimentalContracts::class) suspend inline fun MessageBehavior.editWebhookMessage( + webhookId: Snowflake, token: String, builder: EditWebhookMessageBuilder.() -> Unit ): Message { @@ -271,11 +266,9 @@ suspend inline fun MessageBehavior.editWebhookMessage( callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } - require(webhookId != null) { "Cannot perform edits on non webhook messages use edit() instead" } - val response = kord.rest.webhook.editWebhookMessage( - webhookId = webhookId!!, + webhookId = webhookId, messageId = id, token = token, builder = builder diff --git a/core/src/main/kotlin/entity/Message.kt b/core/src/main/kotlin/entity/Message.kt index 7c1eb9613f9..81010baad0e 100644 --- a/core/src/main/kotlin/entity/Message.kt +++ b/core/src/main/kotlin/entity/Message.kt @@ -219,7 +219,7 @@ class Message( * * Returns null if this message was not send using a webhook. */ - override val webhookId: Snowflake? get() = data.webhookId.value + val webhookId: Snowflake? get() = data.webhookId.value /** * Returns itself. diff --git a/core/src/main/kotlin/entity/channel/MessageChannel.kt b/core/src/main/kotlin/entity/channel/MessageChannel.kt index d59f24c7eff..4e69db7179b 100644 --- a/core/src/main/kotlin/entity/channel/MessageChannel.kt +++ b/core/src/main/kotlin/entity/channel/MessageChannel.kt @@ -8,7 +8,6 @@ import dev.kord.core.behavior.channel.MessageChannelBehavior import dev.kord.core.entity.Message import dev.kord.core.supplier.EntitySupplyStrategy import dev.kord.core.toInstant -import dev.kord.core.toSnowflakeOrNull import java.time.Instant /**