Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KDocs to the kord/core package #967

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3c75c23
Lets get this show on the road
NoComment1105 Nov 21, 2022
cd1df72
Merge branch 'kordlib:0.8.x' into docs-docs-docs
NoComment1105 Nov 21, 2022
d73ff4c
More doc progress
NoComment1105 Nov 21, 2022
5c2bac4
Documents Documents Documents
NoComment1105 Nov 24, 2022
e85b597
More Docs yey
NoComment1105 Nov 24, 2022
197690e
Merge branch 'kordlib:0.8.x' into docs-docs-docs
NoComment1105 Dec 6, 2022
c6a506b
I'm going to run out of commit names
NoComment1105 Dec 6, 2022
7231550
Merge branch '0.8.x' into docs-docs-docs
NoComment1105 Feb 20, 2023
5db1987
Add docs to new nulllable guild functions
NoComment1105 Feb 20, 2023
083719c
Document remaining events
NoComment1105 Feb 20, 2023
943b33b
Document the outlying files for the core package
NoComment1105 Feb 21, 2023
7eb9042
Document the exception, supplier and builder packages for the core pa…
NoComment1105 Feb 21, 2023
b270f22
Document live and gateway pacakge
NoComment1105 Feb 22, 2023
89a6c4e
Work on entity packages
NoComment1105 Feb 23, 2023
91e609f
Merge branch '0.9.x' into docs-docs-docs
lukellmann Apr 6, 2023
fd92e97
More docs for core entites
NoComment1105 Apr 6, 2023
ec1be50
Merge remote-tracking branch 'upstream/main' into docs-docs-docs
NoComment1105 Aug 2, 2023
bf3f1ff
Change joined_at field to optional due to guest invites existing now
NoComment1105 Jul 5, 2024
c670a50
Revert "Change joined_at field to optional due to guest invites exist…
NoComment1105 Jul 5, 2024
9c66705
I did it wrong lol, just null it
NoComment1105 Jul 5, 2024
138ab3f
Merge branch 'kordlib:main' into main
NoComment1105 Aug 14, 2024
51c7187
Merge branch 'main' into docs-docs-docs
NoComment1105 Aug 14, 2024
dc848e0
Remove file that no longer exists in the main branch
NoComment1105 Aug 14, 2024
fa56efa
Doc new stuff from update and start work on behavior package
NoComment1105 Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/commonMain/kotlin/ClientResources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.gateway.builder.Shards
import io.ktor.client.*

/**
* The resources for the Kord Instance.
*
* @param token The Bots token
* @param applicationId The ID of the application
* @param shards The [Shards] for the application
* @param maxConcurrency The maximum concurrency for the bot. Can be obtained by calling the `Route.GatewayBotGet` endpoint.
* @param httpClient The [HttpClient] the client is connected through
* @param defaultStrategy The default [EntitySupplyStrategy] for the client.
*/
public class ClientResources(
public val token: String,
public val applicationId: Snowflake,
Expand Down
159 changes: 148 additions & 11 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public class Kord(
private val interceptor: GatewayEventInterceptor,
) : CoroutineScope {

/**
* Returns a [Flow] of Nitro [StickerPack]s
*/
public val nitroStickerPacks: Flow<StickerPack>
get() = defaultSupplier.getNitroStickerPacks()


/**
* The default supplier, obtained through Kord's [resources] and configured through [KordBuilder.defaultStrategy].
* By default a strategy from [EntitySupplyStrategy.rest].
* By default, a strategy from [EntitySupplyStrategy.rest].
*
* All [strategizable][Strategizable] [entities][KordEntity] created through this instance will use this supplier by default.
*/
Expand Down Expand Up @@ -99,9 +102,15 @@ public class Kord(

override val coroutineContext: CoroutineContext = SupervisorJob() + dispatcher

/**
* Returns a [Flow] of [Region]s know to the bot.
*/
public val regions: Flow<Region>
get() = defaultSupplier.regions

/**
* Returns a [Flow] of [Guild]s know to the bot.
*/
public val guilds: Flow<Guild>
get() = defaultSupplier.guilds

Expand Down Expand Up @@ -148,6 +157,12 @@ public class Kord(

public fun <T : EntitySupplier> with(strategy: EntitySupplyStrategy<T>): T = strategy.supply(this)

/**
* Requests to get the information of the current application using the [EntitySupplyStrategy.rest] supplier.
*
* Entities will be fetched from Discord directly, ignoring any cached values.
* @throws RestRequestException when the request failed.
*/
public suspend fun getApplicationInfo(): Application = with(EntitySupplyStrategy.rest).getApplicationInfo()

/**
Expand Down Expand Up @@ -366,6 +381,11 @@ public class Kord(
): Invite? = with(EntitySupplyStrategy.rest).getInviteOrNull(code, withCounts, withExpiration, scheduledEventId)


/**
* Gets a [Sticker] from its [id].
*
* @return [EntityNotFoundException.stickerNotFound] if the sticker is not found
*/
public suspend fun getSticker(id: Snowflake): Sticker = defaultSupplier.getSticker(id)


Expand Down Expand Up @@ -426,67 +446,132 @@ public class Kord(
}
}


/**
* Gets the [GlobalApplicationCommand]s for this bot.
*
* @param withLocalizations Whether to get the commands with localisations or not. Defaults to `null`
* @return a [Flow] of [GlobalApplicationCommand]s for this bot.
*/
public fun getGlobalApplicationCommands(withLocalizations: Boolean? = null): Flow<GlobalApplicationCommand> {
return defaultSupplier.getGlobalApplicationCommands(resources.applicationId, withLocalizations)
}

/**
* Gets the [GuildApplicationCommand]s for a given [guildId].
*
* @param guildId The ID of the guild to get the commands for
* @param withLocalizations Whether to get the commands with localizations or not. Defaults to `null`
* @return a [Flow] of [GuildApplicationCommand]s for the given [guildId].
*/
public fun getGuildApplicationCommands(
guildId: Snowflake,
withLocalizations: Boolean? = null,
): Flow<GuildApplicationCommand> {
return defaultSupplier.getGuildApplicationCommands(resources.applicationId, guildId, withLocalizations)
}

/**
* Gets a [GuildApplicationCommand] based on the [guildId] and [commandId].
*
* @param guildId The ID of the guild to get the command for
* @param commandId The ID of the command to get
* @return The [GuildApplicationCommand] or [EntityNotFoundException.applicationCommandNotFound] if it was not found.
*/
public suspend fun getGuildApplicationCommand(guildId: Snowflake, commandId: Snowflake): GuildApplicationCommand {
return defaultSupplier.getGuildApplicationCommand(resources.applicationId, guildId, commandId)
}


/**
* Gets a [GuildApplicationCommand] based on the [guildId] and [commandId].
*
* @param guildId The ID of the guild to get the command from
* @param commandId The ID of the command to get
* @return The [GuildApplicationCommand] or `null` if it was not found.
*/
public suspend fun getGuildApplicationCommandOrNull(
guildId: Snowflake,
commandId: Snowflake
): GuildApplicationCommand? {
return defaultSupplier.getGuildApplicationCommandOrNull(resources.applicationId, guildId, commandId)
}


/**
* Gets a Guild application command of type [T], based on the [guildId] and [commandId]
*
* @param guildId The ID the guild to get the command from
* @param commandId The ID of the command to get
* @return The command of type [T] or [EntityNotFoundException.applicationCommandNotFound] if it was not found.
*/
public suspend inline fun <reified T : GuildApplicationCommand> getGuildApplicationCommandOf(
guildId: Snowflake,
commandId: Snowflake
): T {
return defaultSupplier.getGuildApplicationCommandOf(resources.applicationId, guildId, commandId)
}


/**
* Gets a Guild application command of type [T], based on the [guildId] and [commandId]
*
* @param guildId The ID the guild to get the command from
* @param commandId The ID of the command to get
* @return The command of type [T] or `null` if it was not found.
*/
public suspend inline fun <reified T : GuildApplicationCommand> getGuildApplicationCommandOfOrNull(
guildId: Snowflake,
commandId: Snowflake
): T? {
return defaultSupplier.getGuildApplicationCommandOfOrNull(resources.applicationId, guildId, commandId)
}


/**
* Gets a [GlobalApplicationCommand] based off the [commandId].
*
* @param commandId The ID of the command to get.
* @return The [GlobalApplicationCommand] or [EntityNotFoundException.applicationCommandNotFound] if it was not found.
*/
public suspend fun getGlobalApplicationCommand(commandId: Snowflake): GlobalApplicationCommand {
return defaultSupplier.getGlobalApplicationCommand(resources.applicationId, commandId)
}


/**
* Gets a [GlobalApplicationCommand] based off the [commandId].
*
* @param commandId The ID of the command to get.
* @return The [GlobalApplicationCommand] or `null` if it was not found.
*/
public suspend fun getGlobalApplicationCommandOrNull(commandId: Snowflake): GlobalApplicationCommand? {
return defaultSupplier.getGlobalApplicationCommandOrNull(resources.applicationId, commandId)
}


/**
* Gets a Global application command of type [T] based off the [commandId].
*
* @param commandId The ID of the command to get.
* @return The application command of type [T] or [EntityNotFoundException.applicationCommandNotFound] if it was not found.
*/
public suspend fun <T> getGlobalApplicationCommandOf(commandId: Snowflake): T {
return defaultSupplier.getGlobalApplicationCommandOf(resources.applicationId, commandId)
}


/**
* Gets a Global application command of type [T] based off the [commandId].
*
* @param commandId The ID of the command to get.
* @return The application command of type [T] or `null` if it was not found.
*/
public suspend fun <T> getGlobalApplicationCommandOfOrNull(commandId: Snowflake): T? {
return defaultSupplier.getGlobalApplicationCommandOfOrNull(resources.applicationId, commandId)
}


/**
* Creates a [GlobalChatInputCommand] for this bot.
*
* @param name The command name
* @param description The command description
* @param builder A [GlobalChatInputCreateBuilder] to modify the command.
* @return The [GlobalChatInputCommand] for the bot.
*/
public suspend inline fun createGlobalChatInputCommand(
name: String,
description: String,
Expand All @@ -503,6 +588,13 @@ public class Kord(
return GlobalChatInputCommand(data, rest.interaction)
}

/**
* Creates a [GlobalMessageCommand] for this bot.
*
* @param name The command name
* @param builder A [GlobalMessageCommandCreateBuilder] to modify the command.
* @return The [GlobalMessageCommand] for the bot.
*/
public suspend inline fun createGlobalMessageCommand(
name: String,
builder: GlobalMessageCommandCreateBuilder.() -> Unit = {},
Expand All @@ -514,6 +606,13 @@ public class Kord(
return GlobalMessageCommand(data, rest.interaction)
}

/**
* Creates a [GlobalUserCommand] for this bot.
*
* @param name The command name
* @param builder A [GlobalUserCommandCreateBuilder] to modify the command.
* @return The [GlobalUserCommand] for the bot.
*/
public suspend inline fun createGlobalUserCommand(
name: String,
builder: GlobalUserCommandCreateBuilder.() -> Unit = {},
Expand All @@ -525,7 +624,12 @@ public class Kord(
return GlobalUserCommand(data, rest.interaction)
}


/**
* Creates multiple [GlobalApplicationCommand]s.
*
* @param builder A [GlobalMultiApplicationCommandBuilder] to create the commands in.
* @return A [Flow] of [GlobalApplicationCommand]s for the bot.
*/
public suspend inline fun createGlobalApplicationCommands(
builder: GlobalMultiApplicationCommandBuilder.() -> Unit,
): Flow<GlobalApplicationCommand> {
Expand All @@ -540,6 +644,16 @@ public class Kord(
}
}

/**
* Creates a [GuildChatInputCommand] for a given [guildId]
*
* @param guildId The ID of the guild to create the command
* @param name The name of the command
* @param description The description of the command
* @param builder A [ChatInputCreateBuilder] to modify the command
*
* @return a [GuildChatInputCommand] object for the command
*/
public suspend inline fun createGuildChatInputCommand(
guildId: Snowflake,
name: String,
Expand All @@ -560,6 +674,15 @@ public class Kord(
}


/**
* Creates a [GuildMessageCommand] for a given [guildId]
*
* @param guildId The ID of the guild to create the command
* @param name The name of the command
* @param builder A [MessageCommandCreateBuilder] to modify the command
*
* @return a [GuildMessageCommand] object for the command
*/
public suspend inline fun createGuildMessageCommand(
guildId: Snowflake,
name: String,
Expand All @@ -576,6 +699,15 @@ public class Kord(
return GuildMessageCommand(data, rest.interaction)
}

/**
* Creates a [GuildUserCommand] for a given [guildId]
*
* @param guildId The ID of the guild to create the command
* @param name The name of the command
* @param builder A [UserCommandCreateBuilder] to modify the command
*
* @return a [GuildUserCommand] object for the command
*/
public suspend inline fun createGuildUserCommand(
guildId: Snowflake,
name: String,
Expand All @@ -593,7 +725,12 @@ public class Kord(
return GuildUserCommand(data, rest.interaction)
}


/**
* Creates multiple [GuildApplicationCommand]s.
*
* @param builder A [GuildMultiApplicationCommandBuilder] to create the commands in.
* @return A [Flow] of [GuildApplicationCommand]s for the bot.
*/
public suspend inline fun createGuildApplicationCommands(
guildId: Snowflake,
builder: GuildMultiApplicationCommandBuilder.() -> Unit,
Expand Down
Loading