Skip to content

Commit

Permalink
improve generic transformer for channel behavior (#451)
Browse files Browse the repository at this point in the history
* improve generic transformer for channel behavior

* Fix ReplaceWith expression
  • Loading branch information
HopeBaron authored Nov 23, 2021
1 parent 1840fc3 commit 01c9bf9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/src/main/kotlin/behavior/channel/ChannelBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,40 @@ public interface ChannelBehavior : KordEntity, Strategizable {
* @throws [RequestException] if anything went wrong during the request.
* @throws [ClassCastException] if the channel is not of type [T]
*/
@Deprecated("Deprecated in favor of asChannelOfOrNull",ReplaceWith("asChannelOfOrNull(id)"))
public suspend inline fun <reified T: Channel> ChannelBehavior.ofOrNull(): T? = supplier.getChannelOfOrNull(id)


/**
* Requests to get the [Channel] represented by the [id].
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [EntityNotFoundException] if the [Channel] wasn't present.
* @throws [ClassCastException] if the channel is not of type [T].
*/
@Deprecated("Deprecated in favor of asChannelOfOrNull",ReplaceWith("asChannelOfOrNull(id)"))
public suspend inline fun <reified T: Channel> ChannelBehavior.of(): T = supplier.getChannelOf(id)


/**
* Requests to get the [Channel] represented by the [id],
* returns null if the [Channel] isn't present.
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [ClassCastException] if the channel is not of type [T]
*/
public suspend inline fun <reified T: Channel> ChannelBehavior.asChannelOfOrNull(): T? = supplier.getChannelOfOrNull(id)


/**
* Requests to get the [Channel] represented by the [id].
*
* @throws [RequestException] if anything went wrong during the request.
* @throws [EntityNotFoundException] if the [Channel] wasn't present.
* @throws [ClassCastException] if the channel is not of type [T].
*/
public suspend inline fun <reified T: Channel> ChannelBehavior.asChannelOf(): T = supplier.getChannelOf(id)

public fun ChannelBehavior(id: Snowflake, kord: Kord, strategy: EntitySupplyStrategy<*> = kord.resources.defaultStrategy): ChannelBehavior =
object : ChannelBehavior {
override val id: Snowflake = id
Expand Down

0 comments on commit 01c9bf9

Please sign in to comment.