Skip to content

Commit

Permalink
Remove webhookId from behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Apr 5, 2021
1 parent 5942a23 commit a58d340
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
13 changes: 3 additions & 10 deletions core/src/main/kotlin/behavior/MessageBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -200,21 +198,19 @@ interface MessageBehavior : KordEntity, Strategizable {
*/
override fun withStrategy(
strategy: EntitySupplyStrategy<*>,
): MessageBehavior = MessageBehavior(channelId, id, kord, webhookId, strategy)
): MessageBehavior = MessageBehavior(channelId, id, kord)

}

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)
Expand Down Expand Up @@ -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)
Expand All @@ -264,18 +258,17 @@ suspend inline fun MessageBehavior.edit(builder: MessageModifyBuilder.() -> Unit
*/
@OptIn(ExperimentalContracts::class)
suspend inline fun MessageBehavior.editWebhookMessage(
webhookId: Snowflake,
token: String,
builder: EditWebhookMessageBuilder.() -> Unit
): Message {
contract {
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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/entity/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion core/src/main/kotlin/entity/channel/MessageChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit a58d340

Please sign in to comment.