Skip to content

Commit

Permalink
Fix receiver issue when getting channel from guild
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Jul 11, 2020
1 parent 7ac384b commit 21100f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.5.8

## Fixes

* Fixed an issue where getting a channel from a guild would incorrectly throw an exception during the guild id check.

# 0.5.7

## Additions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.gitlab.kordlib.core.supplier.getChannelOfOrNull
import com.gitlab.kordlib.rest.builder.ban.BanCreateBuilder
import com.gitlab.kordlib.rest.builder.channel.*
import com.gitlab.kordlib.rest.builder.guild.EmojiCreateBuilder
import com.gitlab.kordlib.rest.builder.guild.EmojiModifyBuilder
import com.gitlab.kordlib.rest.builder.guild.GuildModifyBuilder
import com.gitlab.kordlib.rest.builder.role.RoleCreateBuilder
import com.gitlab.kordlib.rest.builder.role.RolePositionsModifyBuilder
Expand Down Expand Up @@ -509,29 +508,29 @@ suspend inline fun GuildBehavior.ban(userId: Snowflake, builder: BanCreateBuilde
}

/**
* Requests to get the [GuildChannel] represented by the [id] as type [T].
* Requests to get the [GuildChannel] represented by the [channelId] as type [T].
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [EntityNotFoundException] if the [T] wasn't present.
* @throws [ClassCastException] if the channel is not of type [T].
* @throws [IllegalArgumentException] if the channel is not part of this guild.
*/
suspend inline fun<reified T: GuildChannel> GuildBehavior.getChannelOf(id: Snowflake) : T {
val channel = supplier.getChannelOf<T>(id)
require(channel.guildId == id) { "channel ${id.value} is not in guild ${id.value}" }
suspend inline fun<reified T: GuildChannel> GuildBehavior.getChannelOf(channelId: Snowflake) : T {
val channel = supplier.getChannelOf<T>(channelId)
require(channel.guildId == this.id) { "channel ${channelId.value} is not in guild ${this.id.value}" }
return channel
}

/**
* Requests to get the [GuildChannel] represented by the [id] as type [T],
* Requests to get the [GuildChannel] represented by the [channelId] as type [T],
* returns null if the [GuildChannel] isn't present.
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [ClassCastException] if the channel is not of type [T].
* @throws [IllegalArgumentException] if the channel is not part of this guild.
*/
suspend inline fun<reified T: GuildChannel> GuildBehavior.getChannelOfOrNull(id: Snowflake) : T? {
val channel = supplier.getChannelOfOrNull<T>(id) ?: return null
require(channel.guildId == id) { "channel ${id.value} is not in guild ${id.value}" }
suspend inline fun<reified T: GuildChannel> GuildBehavior.getChannelOfOrNull(channelId: Snowflake) : T? {
val channel = supplier.getChannelOfOrNull<T>(channelId) ?: return null
require(channel.guildId == this.id) { "channel ${channelId.value} is not in guild ${this.id.value}" }
return channel
}

0 comments on commit 21100f0

Please sign in to comment.