Skip to content

Commit

Permalink
Fix receiver issue when getting channel from guild (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Jul 19, 2020
1 parent 8c18d35 commit 359fc1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.5.9

## Fixes

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


# 0.5.8

## Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,30 +259,30 @@ interface GuildBehavior : Entity, Strategizable {
suspend fun getBanOrNull(userId: Snowflake): Ban? = supplier.getGuildBanOrNull(id, userId)

/**
* Requests to get the [GuildChannel] represented by the [id].
* Requests to get the [GuildChannel] represented by the [channelId].
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [EntityNotFoundException] if the [GuildChannel] wasn't present.
* @throws [ClassCastException] if the channel is not a [GuildChannel].
* @throws [IllegalArgumentException] if the channel is not part of this guild.
*/
suspend fun getChannel(id: Snowflake) : GuildChannel {
val channel = supplier.getChannelOf<GuildChannel>(id)
require(channel.guildId == id) { "channel ${id.value} is not in guild ${id.value}" }
suspend fun getChannel(channelId: Snowflake) : GuildChannel {
val channel = supplier.getChannelOf<GuildChannel>(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],
* Requests to get the [GuildChannel] represented by the [channelId],
* returns null if the [GuildChannel] isn't present.
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [ClassCastException] if the channel is not a [GuildChannel].
* @throws [IllegalArgumentException] if the channel is not part of this guild.
*/
suspend fun getChannelOrNull(id: Snowflake) : GuildChannel? {
val channel = supplier.getChannelOfOrNull<GuildChannel>(id) ?: return null
require(channel.guildId == id) { "channel ${id.value} is not in guild ${id.value}" }
suspend fun getChannelOrNull(channelId: Snowflake) : GuildChannel? {
val channel = supplier.getChannelOfOrNull<GuildChannel>(channelId) ?: return null
require(channel.guildId == this.id) { "channel ${channelId.value} is not in guild ${this.id.value}" }
return channel
}

Expand Down

0 comments on commit 359fc1a

Please sign in to comment.