Skip to content

Commit

Permalink
Add ReactionAddEvent.messageAuthorId (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann authored Sep 18, 2023
1 parent 939d03d commit 122349f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
12 changes: 7 additions & 5 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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 <init> (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 <init> (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 <init> (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 <init> (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 <init> (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
Expand Down
2 changes: 2 additions & 0 deletions common/src/commonMain/kotlin/entity/DiscordMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ public data class MessageReactionAddData(
val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
val member: Optional<DiscordGuildMember> = Optional.Missing(),
val emoji: DiscordPartialEmoji,
@SerialName("message_author_id")
val messageAuthorId: OptionalSnowflake = OptionalSnowflake.Missing,
)

@Serializable
Expand Down
9 changes: 7 additions & 2 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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 <init> (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 <init> (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 <init> (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;
Expand All @@ -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
Expand Down
38 changes: 31 additions & 7 deletions core/src/commonMain/kotlin/event/message/ReactionAddEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -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)
Expand All @@ -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)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ internal class MessageEventHandler : BaseGatewayEventHandler() {
messageId,
guildId.value,
reaction,
messageAuthorId.value,
kord,
shard,
context?.get(),
Expand Down

0 comments on commit 122349f

Please sign in to comment.