Skip to content

Commit

Permalink
Added getChannelOf
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Sep 4, 2020
1 parent f2f7b4c commit aef4399
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Additions

* Added a new `Field` builder function. #57
* Added a new `Field` builder function. #57
* Added `Kord#getChannelOf` to request a type of channel.

## Changes

Expand Down
13 changes: 13 additions & 0 deletions core/src/main/kotlin/com/gitlab/kordlib/core/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.gitlab.kordlib.common.annotation.KordUnsafe
import com.gitlab.kordlib.common.entity.DiscordShard
import com.gitlab.kordlib.common.entity.Snowflake
import com.gitlab.kordlib.common.entity.Status
import com.gitlab.kordlib.common.exception.RequestException
import com.gitlab.kordlib.core.builder.kord.KordBuilder
import com.gitlab.kordlib.core.builder.kord.KordRestOnlyBuilder
import com.gitlab.kordlib.core.cache.data.GuildData
Expand All @@ -20,6 +21,7 @@ import com.gitlab.kordlib.core.gateway.MasterGateway
import com.gitlab.kordlib.core.gateway.handler.GatewayEventInterceptor
import com.gitlab.kordlib.core.supplier.EntitySupplier
import com.gitlab.kordlib.core.supplier.EntitySupplyStrategy
import com.gitlab.kordlib.core.supplier.getChannelOfOrNull
import com.gitlab.kordlib.gateway.Gateway
import com.gitlab.kordlib.gateway.builder.PresenceBuilder
import com.gitlab.kordlib.rest.builder.guild.GuildCreateBuilder
Expand Down Expand Up @@ -103,6 +105,17 @@ class Kord(

suspend fun getChannel(id: Snowflake, strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): Channel? = strategy.supply(this).getChannelOrNull(id)

/**
* Requests to get the [Channel] as type [T] through the [strategy],
* returns null if the [Channel] isn't present or is not of type [T].
*
* @throws [RequestException] if anything went wrong during the request.
*/
suspend inline fun <reified T : Channel> getChannelOf(
id: Snowflake,
strategy: EntitySupplyStrategy<*> = resources.defaultStrategy,
): T? = strategy.supply(this).getChannelOfOrNull(id)

suspend fun getGuild(id: Snowflake, strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): Guild? = strategy.supply(this).getGuildOrNull(id)

suspend fun getSelf(strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): User =
Expand Down

0 comments on commit aef4399

Please sign in to comment.