Skip to content

Commit

Permalink
Add mention property for GuildEmoji and ReactionEmoji
Browse files Browse the repository at this point in the history
  • Loading branch information
HopeBaron committed Jun 20, 2020
1 parent 2b89620 commit 032bc64
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface MessageBehavior : Entity, Strategizable {
kord.rest.channel.getReactions(
channelId = channelId.value,
messageId = id.value,
emoji = emoji.formatted,
emoji = emoji.urlFormat,
limit = 100,
position = position
)
Expand All @@ -82,7 +82,7 @@ interface MessageBehavior : Entity, Strategizable {
* @throws [RestRequestException] if something went wrong during the request.
*/
suspend fun addReaction(emoji: ReactionEmoji) {
kord.rest.channel.createReaction(channelId = channelId.value, messageId = id.value, emoji = emoji.formatted)
kord.rest.channel.createReaction(channelId = channelId.value, messageId = id.value, emoji = emoji.urlFormat)
}

/**
Expand All @@ -100,7 +100,7 @@ interface MessageBehavior : Entity, Strategizable {
* @throws [RestRequestException] if something went wrong during the request.
*/
suspend fun deleteReaction(userId: Snowflake, emoji: ReactionEmoji) {
kord.rest.channel.deleteReaction(channelId = channelId.value, messageId = id.value, userId = userId.value, emoji = emoji.formatted)
kord.rest.channel.deleteReaction(channelId = channelId.value, messageId = id.value, userId = userId.value, emoji = emoji.urlFormat)
}

/**
Expand All @@ -109,7 +109,7 @@ interface MessageBehavior : Entity, Strategizable {
* @throws [RestRequestException] if something went wrong during the request.
*/
suspend fun deleteOwnReaction(emoji: ReactionEmoji) {
kord.rest.channel.deleteOwnReaction(channelId = channelId.value, messageId = id.value, emoji = emoji.formatted)
kord.rest.channel.deleteOwnReaction(channelId = channelId.value, messageId = id.value, emoji = emoji.urlFormat)
}

/**
Expand All @@ -127,7 +127,7 @@ interface MessageBehavior : Entity, Strategizable {
* @throws [RestRequestException] if something went wrong during the request.
*/
suspend fun deleteReaction(emoji: ReactionEmoji) {
kord.rest.channel.deleteAllReactionsForEmoji(channelId = channelId.value, messageId = id.value, emoji = emoji.formatted)
kord.rest.channel.deleteAllReactionsForEmoji(channelId = channelId.value, messageId = id.value, emoji = emoji.urlFormat)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class GuildEmoji(
val guildId: Snowflake
get() = Snowflake(data.guildId)

val mention: String
get() = if (isAnimated) "<a:$name:${id.value}>" else "<:$name:${id.value}>"

/**
* Whether this emoji can be used, may be false due to loss of Server Boosts.
*/
Expand Down Expand Up @@ -118,7 +121,7 @@ class GuildEmoji(

override fun hashCode(): Int = Objects.hash(id, guildId)

override fun equals(other: Any?): Boolean = when(other) {
override fun equals(other: Any?): Boolean = when (other) {
is GuildEmoji -> other.id == id && other.guildId == guildId
else -> super.equals(other)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ import com.gitlab.kordlib.common.entity.Snowflake
import com.gitlab.kordlib.core.cache.data.RemovedReactionData

sealed class ReactionEmoji {
abstract val formatted: String
abstract val urlFormat: String
abstract val name: String

data class Custom(val id: Snowflake, override val name: String, val isAnimated: Boolean) : ReactionEmoji() {
override val formatted: String
/**
*
* Format used in HTTP queries.
*
*/
override val urlFormat: String
get() = "$name:${id.value}"

val mention: String
get() = if (isAnimated) "<a:$name:${id.value}>" else "<:$name:${id.value}>"


override fun toString() = "Custom(id=$id, name=$name, isAnimated=$isAnimated)"
}

class Unicode(override val name: String) : ReactionEmoji() {
override val formatted: String get() = name
override val urlFormat: String get() = name
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class RestEntitySupplier(val kord: Kord) : EntitySupplier {
kord.rest.channel.getReactions(
channelId = channelId.value,
messageId = messageId.value,
emoji = emoji.formatted,
emoji = emoji.urlFormat,
limit = 100,
position = position
)
Expand Down

0 comments on commit 032bc64

Please sign in to comment.