From 4f404ad6d73c68489a21cbff9162a757abdeda52 Mon Sep 17 00:00:00 2001 From: lukellmann Date: Mon, 18 Sep 2023 12:24:25 +0200 Subject: [PATCH] Add ReactionAddEvent.messageAuthorId See https://github.com/discord/discord-api-docs/pull/6102 and https://github.com/discord/discord-api-docs/pull/6296 --- common/api/common.api | 12 +++--- .../kotlin/entity/DiscordMessage.kt | 2 + core/api/core.api | 9 ++++- .../kotlin/event/message/ReactionAddEvent.kt | 38 +++++++++++++++---- .../gateway/handler/MessageEventHandler.kt | 1 + 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/common/api/common.api b/common/api/common.api index 6d0264acd0d5..ac73fecb4713 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -7598,22 +7598,24 @@ public final class dev/kord/common/entity/MessageFlags$Companion { public final class dev/kord/common/entity/MessageReactionAddData { public static final field Companion Ldev/kord/common/entity/MessageReactionAddData$Companion; - public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;)V - public synthetic fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Ldev/kord/common/entity/optional/OptionalSnowflake;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Ldev/kord/common/entity/optional/OptionalSnowflake;)V + public synthetic fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Ldev/kord/common/entity/optional/OptionalSnowflake;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/Snowflake; public final fun component2 ()Ldev/kord/common/entity/Snowflake; public final fun component3 ()Ldev/kord/common/entity/Snowflake; public final fun component4 ()Ldev/kord/common/entity/optional/OptionalSnowflake; public final fun component5 ()Ldev/kord/common/entity/optional/Optional; public final fun component6 ()Ldev/kord/common/entity/DiscordPartialEmoji; - public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;)Ldev/kord/common/entity/MessageReactionAddData; - public static synthetic fun copy$default (Ldev/kord/common/entity/MessageReactionAddData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;ILjava/lang/Object;)Ldev/kord/common/entity/MessageReactionAddData; + public final fun component7 ()Ldev/kord/common/entity/optional/OptionalSnowflake; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Ldev/kord/common/entity/optional/OptionalSnowflake;)Ldev/kord/common/entity/MessageReactionAddData; + public static synthetic fun copy$default (Ldev/kord/common/entity/MessageReactionAddData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/DiscordPartialEmoji;Ldev/kord/common/entity/optional/OptionalSnowflake;ILjava/lang/Object;)Ldev/kord/common/entity/MessageReactionAddData; public fun equals (Ljava/lang/Object;)Z public final fun getChannelId ()Ldev/kord/common/entity/Snowflake; public final fun getEmoji ()Ldev/kord/common/entity/DiscordPartialEmoji; public final fun getGuildId ()Ldev/kord/common/entity/optional/OptionalSnowflake; public final fun getMember ()Ldev/kord/common/entity/optional/Optional; + public final fun getMessageAuthorId ()Ldev/kord/common/entity/optional/OptionalSnowflake; public final fun getMessageId ()Ldev/kord/common/entity/Snowflake; public final fun getUserId ()Ldev/kord/common/entity/Snowflake; public fun hashCode ()I diff --git a/common/src/commonMain/kotlin/entity/DiscordMessage.kt b/common/src/commonMain/kotlin/entity/DiscordMessage.kt index 68c4bb916cdc..79a9df2a9494 100644 --- a/common/src/commonMain/kotlin/entity/DiscordMessage.kt +++ b/common/src/commonMain/kotlin/entity/DiscordMessage.kt @@ -671,6 +671,8 @@ public data class MessageReactionAddData( val guildId: OptionalSnowflake = OptionalSnowflake.Missing, val member: Optional = Optional.Missing(), val emoji: DiscordPartialEmoji, + @SerialName("message_author_id") + val messageAuthorId: OptionalSnowflake = OptionalSnowflake.Missing, ) @Serializable diff --git a/core/api/core.api b/core/api/core.api index bd33428b637f..060c4c669f19 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -12994,8 +12994,8 @@ public final class dev/kord/core/event/message/MessageUpdateEvent : dev/kord/cor } public final class dev/kord/core/event/message/ReactionAddEvent : dev/kord/core/entity/Strategizable, dev/kord/core/event/Event { - public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/entity/ReactionEmoji;Ldev/kord/core/Kord;ILjava/lang/Object;Ldev/kord/core/supplier/EntitySupplier;)V - public synthetic fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/entity/ReactionEmoji;Ldev/kord/core/Kord;ILjava/lang/Object;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/entity/ReactionEmoji;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;ILjava/lang/Object;Ldev/kord/core/supplier/EntitySupplier;)V + public synthetic fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/entity/ReactionEmoji;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;ILjava/lang/Object;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getChannel ()Ldev/kord/core/behavior/channel/MessageChannelBehavior; public final fun getChannel (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getChannelId ()Ldev/kord/common/entity/Snowflake; @@ -13009,6 +13009,11 @@ public final class dev/kord/core/event/message/ReactionAddEvent : dev/kord/core/ public fun getKord ()Ldev/kord/core/Kord; public final fun getMessage ()Ldev/kord/core/behavior/MessageBehavior; public final fun getMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getMessageAuthor ()Ldev/kord/core/behavior/UserBehavior; + public final fun getMessageAuthorAsMember ()Ldev/kord/core/behavior/MemberBehavior; + public final fun getMessageAuthorAsMemberOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getMessageAuthorId ()Ldev/kord/common/entity/Snowflake; + public final fun getMessageAuthorOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getMessageId ()Ldev/kord/common/entity/Snowflake; public final fun getMessageOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getShard ()I diff --git a/core/src/commonMain/kotlin/event/message/ReactionAddEvent.kt b/core/src/commonMain/kotlin/event/message/ReactionAddEvent.kt index 4413ff0f64c7..69dc6f2fc9ab 100644 --- a/core/src/commonMain/kotlin/event/message/ReactionAddEvent.kt +++ b/core/src/commonMain/kotlin/event/message/ReactionAddEvent.kt @@ -21,6 +21,7 @@ public class ReactionAddEvent( public val messageId: Snowflake, public val guildId: Snowflake?, public val emoji: ReactionEmoji, + public val messageAuthorId: Snowflake?, override val kord: Kord, override val shard: Int, override val customContext: Any?, @@ -34,9 +35,16 @@ public class ReactionAddEvent( public val message: MessageBehavior get() = MessageBehavior(channelId, messageId, kord) public val user: UserBehavior get() = UserBehavior(userId, kord) - public val userAsMember: MemberBehavior? get() = guildId?.let { MemberBehavior(it, userId, kord) } + public val messageAuthor: UserBehavior? get() = messageAuthorId?.let { UserBehavior(it, kord) } + public val messageAuthorAsMember: MemberBehavior? + get() = guildId?.let { guildId -> + messageAuthorId?.let { messageAuthorId -> + MemberBehavior(guildId, messageAuthorId, kord) + } + } + public suspend fun getChannel(): MessageChannel = supplier.getChannelOf(channelId) public suspend fun getChannelOrNull(): MessageChannel? = supplier.getChannelOfOrNull(channelId) @@ -48,13 +56,29 @@ public class ReactionAddEvent( public suspend fun getUser(): User = supplier.getUser(userId) public suspend fun getUserOrNull(): User? = supplier.getUserOrNull(userId) - public suspend fun getUserAsMember(): Member? = guildId?.let { supplier.getMemberOrNull(it, userId) } - override fun withStrategy(strategy: EntitySupplyStrategy<*>): ReactionAddEvent = - ReactionAddEvent(userId, channelId, messageId, guildId, emoji, kord, shard, customContext, strategy.supply(kord)) - - override fun toString(): String { - return "ReactionAddEvent(userId=$userId, channelId=$channelId, messageId=$messageId, guildId=$guildId, emoji=$emoji, kord=$kord, shard=$shard, supplier=$supplier)" + public suspend fun getMessageAuthorOrNull(): User? = messageAuthorId?.let { supplier.getUserOrNull(it) } + public suspend fun getMessageAuthorAsMemberOrNull(): Member? = guildId?.let { guildId -> + messageAuthorId?.let { messageAuthorId -> + supplier.getMemberOrNull(guildId, messageAuthorId) + } } + + override fun withStrategy(strategy: EntitySupplyStrategy<*>): ReactionAddEvent = ReactionAddEvent( + userId, + channelId, + messageId, + guildId, + emoji, + messageAuthorId, + kord, + shard, + customContext, + strategy.supply(kord) + ) + + override fun toString(): String = "ReactionAddEvent(userId=$userId, channelId=$channelId, messageId=$messageId, " + + "guildId=$guildId, emoji=$emoji, messageAuthorId=$messageAuthorId, kord=$kord, shard=$shard, " + + "customContext=$customContext, supplier=$supplier)" } diff --git a/core/src/commonMain/kotlin/gateway/handler/MessageEventHandler.kt b/core/src/commonMain/kotlin/gateway/handler/MessageEventHandler.kt index c714a4f92553..dc4f333a4baf 100644 --- a/core/src/commonMain/kotlin/gateway/handler/MessageEventHandler.kt +++ b/core/src/commonMain/kotlin/gateway/handler/MessageEventHandler.kt @@ -195,6 +195,7 @@ internal class MessageEventHandler : BaseGatewayEventHandler() { messageId, guildId.value, reaction, + messageAuthorId.value, kord, shard, context?.get(),