From 041723b9e64ea73985037d2467ab8223d9708054 Mon Sep 17 00:00:00 2001 From: Hope <34831095+HopeBaron@users.noreply.github.com> Date: Wed, 23 Jun 2021 19:42:08 +0300 Subject: [PATCH] 0.7.1 (#332) * Ci tests improvement (#264) * allow running dokkaHtml on push * Implement voice stage channel (#239) * compute All * implement rest endpoints * JSON representation * implement core representation * handle stage channels * Apply suggestions Co-authored-by: BartArys * Remove duplicated factory function Co-authored-by: BartArys * add documentation * Document the requestToSpeak variable Co-authored-by: BartArys * Fix CI triggers * Add "Competing" activity type (Fix #270) (#272) * Make Updatestatus activities not-null (#274) As per Discord's documentation: https://github.com/discord/discord-api-docs/pull/2789 * Fix memory issues related to Permission combining (#277) * Do not octuple bitset size on copy the pure plus and minus function create a new array to work with, this incorrectly created an array of a size equal to the amount of bits that were allocated, instead the amount of longs. Thus, octupling the internal size. * Optimize Permission All The All Permission folded each DiscordBitSet of each value into eachother, resulting in n + 1 bitsets being created. This commit changes that to use the internal `add` which instead, which only mutates the single bitset created. * Add Stream permission It was missing * Add Permission All regression tests * Update deprecated message (#280) * Expose the creation of application commands behavior (#281) * Fix GuildUpdate core handling (#284) * Expose the creation of application commands behavior * Fix type of emitted event * Sealed message types (#282) * Expose the creation of application commands behavior * Make message types sealed * make Unknown a class * Add missing message types * make MessageTypeSerializer internal * Add buttons to Activity (#287) * Add buttons to Activity * Also pass buttons in constructor * Add missing fields to Guild (#288) * Add missing fields to Guild - Add welcome_screen - Add nsfw * Fix failing tests * Fix another failing tests * Add Message.applicationId (#289) * Message interaction (#283) * Expose the creation of application commands behavior * Add interaction message * Apply suggestions * reference the MessageInteraction in docs * Implement Strategizable for MessageInteraction * cache user from interaction message * Fix compilation errors * Fix withStrategy return type Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Implement Stage instances (#291) * Add low-level implementation of stage instances * Add helper functions * Add core entities and api representations * Expose creation of StageInstanceBehavior to unsafe - Revert outdated change * Final additions - Add StageInstanceBehavior.asStageInstance - Fix compiler issue - Add StageChannelBehavior.getStageInstance() * Add StageInstances to EntitySupplier.kt * Add StageInstances to EntitySupplier.kt * Fix typo * Apply requested changes * Fix return type of channel in VoiceState (#295) * Fix return type of channel in VoiceState * Fix GuildService#modifyVoiceState endpoint * Fix MessageInteraction#user id * Add missing session start limit field (#306) - Adds the max_concurrency field to the session start limit data class * Update to Kotlin 1.5 (#299) * Update to 1.5.0-RC * trigger on branch pushes * Port to Kotlin 1.5 (#268) * Port dependencies to Kotlin 1.5 - Convert AbstractRateLimiter.AbstractRequestToken to a static rather than an inner class due to a compiler bug - Downgrade kx.ser-json to 1.0.0 to avoid a compiler bug - Bump other Kotlin dependencies to latest fixup! Port dependencies to Kotlin 1.5 - Convert AbstractRateLimiter.AbstractRequestToken to a static rather than an inner class due to a compiler bug - Downgrade kx.ser-json to 1.0.0 to avoid a compiler bug - Bump other Kotlin dependencies to latest * Replace deprecated kotlin.time APIs * Replace more deprecated APIs & inline classes * Replace deprecated usage of time API in tests * Possibly fix test Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> * Port to Kotlin 1.5 - Bump dependencies to 1.5 recommended versions - Remove inline classes in favor of value classes - Add required opt-ins - Migrate some more deprecated apis * Fix some gradle issues * Fix Gradle compilation issue * Remove documentationFileName as the new dokka version doesn't support it anymore and there is no replacement yet * Port kotlinx.serialization to 1.2.0 (#279) * Port kotlinx.serialization to 1.2.0 - Convert local classes to top level classes (See Kotlin/kotlinx.serialization#1472) - Improve handling of empty JSON bodies (See Kotlin/kotlinx.serialization#678) - Fix Failing Command test * Fix failing test * Properly decode null in gateway events (#286) * Properly decode null in gateway events * Update gateway/src/main/kotlin/Event.kt Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Update Kotlinx.serialization (#290) * Update Kotlin 1.5 branch to upstream (#292) * Implement voice stage channel (#239) * compute All * implement rest endpoints * JSON representation * implement core representation * handle stage channels * Apply suggestions Co-authored-by: BartArys * Remove duplicated factory function Co-authored-by: BartArys * add documentation * Document the requestToSpeak variable Co-authored-by: BartArys * Fix CI triggers * Add "Competing" activity type (Fix #270) (#272) * Make Updatestatus activities not-null (#274) As per Discord's documentation: https://github.com/discord/discord-api-docs/pull/2789 * Fix memory issues related to Permission combining (#277) * Do not octuple bitset size on copy the pure plus and minus function create a new array to work with, this incorrectly created an array of a size equal to the amount of bits that were allocated, instead the amount of longs. Thus, octupling the internal size. * Optimize Permission All The All Permission folded each DiscordBitSet of each value into eachother, resulting in n + 1 bitsets being created. This commit changes that to use the internal `add` which instead, which only mutates the single bitset created. * Add Stream permission It was missing * Add Permission All regression tests * Update deprecated message (#280) * Expose the creation of application commands behavior (#281) * Fix GuildUpdate core handling (#284) * Expose the creation of application commands behavior * Fix type of emitted event * Sealed message types (#282) * Expose the creation of application commands behavior * Make message types sealed * make Unknown a class * Add missing message types * make MessageTypeSerializer internal * Add buttons to Activity (#287) * Add buttons to Activity * Also pass buttons in constructor * Add missing fields to Guild (#288) * Add missing fields to Guild - Add welcome_screen - Add nsfw * Fix failing tests * Fix another failing tests * Add Message.applicationId (#289) Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: BartArys Co-authored-by: HopeBaron Co-authored-by: Bart Arys Co-authored-by: Noah Hendrickson * Fix broken CI (#293) * Migrate to kotlinx-datetime (#297) * Migrate API code to kotlinx-datetime * Update tests * Remove dead code * Replace iso serializing with kx.dt * Bump dependencies to Kotlin 1.5.10 (#305) * Bump dependencies to Kotlin 1.5.10 - Fix sample code * Update remaining dependencies * Update ktor to 1.6.0 Co-authored-by: HopeBaron Co-authored-by: Michael Rittmeister Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: Noah Hendrickson * Filter out non-guilds when fetching rest guilds (#301) This is a side-effect from the system we currently employ when it comes to creating channels. Unknown channels are instantiated as an anonymous channel without hierarchy. While we could assume it is a guild channel, it's not in actuality. So the solution, as we did with cache, is to filter out channels that don't inherit the hierarchy. * close InputStreams used for attachments (#309) * Ephemeral embed support (#296) * Fix return type of channel in VoiceState * support embeds in ephemeral messages * supply modify request with embeds * Common builders for interaction response needs more work * Common builders for interaction response needs more work * Seal base builders for interaction response * make embeds list final * make allowedMentions additive * Fix tests * revert tests * Fix stream closed exception I still haven't managed to know the root of the problem but changing the append process fixed it... * use readBytes for Java 8 compatibility * Interaction create improvements (#294) * Expose the creation of application commands behavior * make message type sealed * Fix typo * document interaction create event * apply suggestions and add more details * replace the quotes * proper grammar, Hope * Improve slash command API and add support for components (#310) * Make slash command creation eager createGuildApplicationCommands and createGlobalApplicationCommands should eagerly create new commands to be more in line with the rest of the API * Fix typo in InteractionBehavior ackowledgePublic -> acknowledgePublic * Don't compute supplier in InteractionBehavior It's a waste of resources, and might result in unexpected behavior for non-Kord suppliers. * Specify withStrategy for Interactions Return types are important! * Introduce type to command options Also add Mentionable. Seems like Discord consistently tells us what kind of option an object is via the type field, this allows us to more clearly represent the json data in the lower level APIs. I ended up deleting DiscordOptionValue and replacing it with a more fleshed out CommandArgument. * Add KordDsl to builders * Add allowedMentions builder functions * Add permission edits to guild commands * Make full member available for guild contexts * Support buttons/components (#303) * Add new API models and properties * Add new InteractionCallbackType * Add ability to send components * Update core entities * Update tests * Add @KordPreview annotations * Convert don't trust doc comments to normal comments * Fix compilation issue * Optimize interaction serializing * Add builder * Fix tests * Apply some requested changes * Hopefully fix formatting * Make builders enforce Discord restrictions * Improve builders again * Remove LinkButtonBuilder.style * Improve builders - Add components to more supported builders - Make required fields parameters - Make builders appending * Update deprecated message (#280) * Expose the creation of application commands behavior (#281) * Fix GuildUpdate core handling (#284) * Expose the creation of application commands behavior * Fix type of emitted event * Sealed message types (#282) * Expose the creation of application commands behavior * Make message types sealed * make Unknown a class * Add missing message types * make MessageTypeSerializer internal * Add buttons to Activity (#287) * Add buttons to Activity * Also pass buttons in constructor * Add missing fields to Guild (#288) * Add missing fields to Guild - Add welcome_screen - Add nsfw * Fix failing tests * Fix another failing tests * Add Message.applicationId (#289) * Message interaction (#283) * Expose the creation of application commands behavior * Add interaction message * Apply suggestions * reference the MessageInteraction in docs * Implement Strategizable for MessageInteraction * cache user from interaction message * Fix compilation errors * Fix withStrategy return type Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Implement Stage instances (#291) * Add low-level implementation of stage instances * Add helper functions * Add core entities and api representations * Expose creation of StageInstanceBehavior to unsafe - Revert outdated change * Final additions - Add StageInstanceBehavior.asStageInstance - Fix compiler issue - Add StageChannelBehavior.getStageInstance() * Add StageInstances to EntitySupplier.kt * Add StageInstances to EntitySupplier.kt * Fix typo * Apply requested changes * Fix return type of channel in VoiceState (#295) * Fix return type of channel in VoiceState * Fix GuildService#modifyVoiceState endpoint * Fix MessageInteraction#user id * Add missing session start limit field (#306) - Adds the max_concurrency field to the session start limit data class * Update to Kotlin 1.5 (#299) * Update to 1.5.0-RC * trigger on branch pushes * Port to Kotlin 1.5 (#268) * Port dependencies to Kotlin 1.5 - Convert AbstractRateLimiter.AbstractRequestToken to a static rather than an inner class due to a compiler bug - Downgrade kx.ser-json to 1.0.0 to avoid a compiler bug - Bump other Kotlin dependencies to latest fixup! Port dependencies to Kotlin 1.5 - Convert AbstractRateLimiter.AbstractRequestToken to a static rather than an inner class due to a compiler bug - Downgrade kx.ser-json to 1.0.0 to avoid a compiler bug - Bump other Kotlin dependencies to latest * Replace deprecated kotlin.time APIs * Replace more deprecated APIs & inline classes * Replace deprecated usage of time API in tests * Possibly fix test Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> * Port to Kotlin 1.5 - Bump dependencies to 1.5 recommended versions - Remove inline classes in favor of value classes - Add required opt-ins - Migrate some more deprecated apis * Fix some gradle issues * Fix Gradle compilation issue * Remove documentationFileName as the new dokka version doesn't support it anymore and there is no replacement yet * Port kotlinx.serialization to 1.2.0 (#279) * Port kotlinx.serialization to 1.2.0 - Convert local classes to top level classes (See Kotlin/kotlinx.serialization#1472) - Improve handling of empty JSON bodies (See Kotlin/kotlinx.serialization#678) - Fix Failing Command test * Fix failing test * Properly decode null in gateway events (#286) * Properly decode null in gateway events * Update gateway/src/main/kotlin/Event.kt Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Update Kotlinx.serialization (#290) * Update Kotlin 1.5 branch to upstream (#292) * Implement voice stage channel (#239) * compute All * implement rest endpoints * JSON representation * implement core representation * handle stage channels * Apply suggestions Co-authored-by: BartArys * Remove duplicated factory function Co-authored-by: BartArys * add documentation * Document the requestToSpeak variable Co-authored-by: BartArys * Fix CI triggers * Add "Competing" activity type (Fix #270) (#272) * Make Updatestatus activities not-null (#274) As per Discord's documentation: https://github.com/discord/discord-api-docs/pull/2789 * Fix memory issues related to Permission combining (#277) * Do not octuple bitset size on copy the pure plus and minus function create a new array to work with, this incorrectly created an array of a size equal to the amount of bits that were allocated, instead the amount of longs. Thus, octupling the internal size. * Optimize Permission All The All Permission folded each DiscordBitSet of each value into eachother, resulting in n + 1 bitsets being created. This commit changes that to use the internal `add` which instead, which only mutates the single bitset created. * Add Stream permission It was missing * Add Permission All regression tests * Update deprecated message (#280) * Expose the creation of application commands behavior (#281) * Fix GuildUpdate core handling (#284) * Expose the creation of application commands behavior * Fix type of emitted event * Sealed message types (#282) * Expose the creation of application commands behavior * Make message types sealed * make Unknown a class * Add missing message types * make MessageTypeSerializer internal * Add buttons to Activity (#287) * Add buttons to Activity * Also pass buttons in constructor * Add missing fields to Guild (#288) * Add missing fields to Guild - Add welcome_screen - Add nsfw * Fix failing tests * Fix another failing tests * Add Message.applicationId (#289) Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: BartArys Co-authored-by: HopeBaron Co-authored-by: Bart Arys Co-authored-by: Noah Hendrickson * Fix broken CI (#293) * Migrate to kotlinx-datetime (#297) * Migrate API code to kotlinx-datetime * Update tests * Remove dead code * Replace iso serializing with kx.dt * Bump dependencies to Kotlin 1.5.10 (#305) * Bump dependencies to Kotlin 1.5.10 - Fix sample code * Update remaining dependencies * Update ktor to 1.6.0 Co-authored-by: HopeBaron Co-authored-by: Michael Rittmeister Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: Noah Hendrickson * Filter out non-guilds when fetching rest guilds (#301) This is a side-effect from the system we currently employ when it comes to creating channels. Unknown channels are instantiated as an anonymous channel without hierarchy. While we could assume it is a guild channel, it's not in actuality. So the solution, as we did with cache, is to filter out channels that don't inherit the hierarchy. * Improve builders again - Merge in upstream * Fix builder requirements - Fix error when sending a emoji button * Fix merge related syntax errors * Restore default sample * Fix formatting isssue in documentation Co-authored-by: Bart Arys * Max component list a val Co-authored-by: Bart Arys * Apply suggestions from code review Co-authored-by: Bart Arys * Apply requested changes * No longer make DiscordInteraction a sealed class * Fix DiscordInteraction serialization * Add some documentation for components * Remove unused imports from builder Co-authored-by: Noah Hendrickson Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: Bart Arys Co-authored-by: 2D Co-authored-by: HopeBaron * Add core versions of components * Restructure and document ButtonBuilder * Remove ActionRowContainerBuilder * Make ComponentInteraction message nullable ephemeral messages in the interaction contain a id, which is not a message id, and the flags. We can't construct a behaviour from this (since the id isn't real), so I decided to drop the data if the message is ephemeral. * Add missing components to interaction builders * Add missing ComponentInteraction behavior * Fix withStrategy for ComponentInteractionBehavior * Implement ComponentInteractionBehavior * Move component builders directory We use singular for package names * Fix interaction embeds optionality * Make CommandInteraction#guildId optional * Make MessageModifyBuilder components vals Co-authored-by: Michael Rittmeister Co-authored-by: Noah Hendrickson Co-authored-by: Hope <34831095+HopeBaron@users.noreply.github.com> Co-authored-by: 2D Co-authored-by: HopeBaron * interaction code cleanup (#312) * clean up * clean up builders * remove content parameter * Apply suggestions * Make serialization of Snowflake consistent (#316) Snowflakes are decoded as Longs but encoded as Strings. Mixing these types is allowed in JSON (and is done by Discord quite frequently) but does lead to other encoding types failing. This commit changes snowflakes to be encoded and decoded as long values exclusively, and should fix the issue. * Add missing components (#318) * clean up * Add missing component builders * expose default permission * cosmetic changes * add missing overrides * remove actionRow from public interaction response builder * Apply formatting suggestion Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Guild nsfw level (#320) * Fix return type of channel in VoiceState * support embeds in ephemeral messages * supply modify request with embeds * add NsfwLevel * update docs [ci skip] * clean up * Fix documentation Co-authored-by: Bart Arys Co-authored-by: Bart Arys * Add non-builder editMessage overload (#323) * Fix followups method signiture (#321) * Fix followups * rename followup functions * Improve live entity life cycle (#315) * fix: Resolve issue about the onShutDown function for Live entities Add deprecated annotation on previous onShutDown extension method Add onShutDown value in LiveEntity to apply action in event or manual case of shutdown * feat: Use coroutine dispatcher for lifecycle of live entity classes Manage the interception of events with the lifecycle of the Live entity. * feat: Use default dispatcher in constructor of live entity * chore: Remove deprecated annotation on onShutDown methods * use and extract SupervisorJob where possible * allow handling a live entity completion * Add structured concurrency to live entity (#285) * test: Begin test for LiveMessage * test: Add tests for LiveMessage class Add tests for listen events Ignore tests where the lifecycle is break by event * chore: Remove useless imports * fix: shutdown action for live entity Deprecate the listening where the live entity is shutdown because the methods are never called Create a property to apply action when the entity is shutdown * fix: Cancel live entity when kord is cancel Add parent of coroutine in constructor of AbstractLiveKordEntity to automatically cancelled the live entity when kord is cancelled * fix: Resolve issue listening for onShutdown, chore: Refactor name shutdown Rename shutDown method to shudown to agree with the method shutdown in kord Resolve issue to listening event for onShutdown action with an empty action job * test: Add abstract class to tests live entity * test: Add tests for abstract live entity and general behavior * chore: Add generic type live entity in abstract class test * chore: Deprecate onCreate method never called by entity * test: Add tests for Member, Role and User live entity Add tests for LiveMember Add tests for LiveRole Add tests for LiveUser * feat: Support BanAddEvent in live guild * test: Change test classes to simulate event and manage it * chore: Remove annotation need token bot * chore: Adapt Role & User live test with send manual event * chore: Adapt Role & User live test with send manual event * test: Add check equality field of event, implements member live test * chore: Remove optIn no used * fix: Correction tests to send fake event instead of real interaction * test: Refactor test to build test with valid and random id * fix: Fix flow issue with delay .. * fix: Rename package to resolve gradle issue I don't know why * test: Add Atomic counter to test event * test: End tests for guild live entity * chore: Place deprecated annotation on live entity Place Deprecated annotation for create event * test: Live category test * chore: Use sequence random id from other tests * test: Tests for all live entities category * test: Add Integrations update for guild live entity * fix: Add delay between creation job and send event Apply a delay between creation jobs and send events to be sure that all jobs are ready to listen the events in flow Without that, this is possible that the test failed * chore: Add deprecated annotation on GuildCreateEvent for live channel * fix: Use guild test channel type (according to GuildMessageChannel) * chore: format * chore: change package name and function name * chore: Use randomID, refactor send event * chore: Doc about shutdown action * chore: Change ReplaceWith in Deprecated annotation, rename shutdown method to shutDown * fix: Remove shutdown action property Remove the onShutDownAction and shutdownAction property to exploit the function invokeOnCompletion from job. Change constructor of live entity to be able to set final the kord instance and launch event in the scope of the live entity * feat: Add cause of shut down live entity * chore: Set deprecate level to Error * test: Add test for LiveGuild with method onGuildCreate * chore: Rename method about completion of job * feat: Add cancellation exception class for live entity Add the class LiveCancellationException to be able to retrieve the event causing the completion of live entity * feat: Add cause of cancellation to retrieve event for each live entity Use the LiveCancellationException class in parameter of shutDown method to be able to retrieve the source event for each live entity * chore: format * tests: Remove delay and use queue to manage action Remove delay between event and replace by Queue to send event when the previous event is received * tests: Add tests for LiveCancellationException constructor Check if there is an error when the exception is called with or not reason message * chore: Refactor property of LiveCancellationException * fix: Null pointer in live entities tests Remove job property, remove delay to use kord.launch and invoke the first event only when the job is ready * chore: try to add delay in tests Add delay in test to help CI * chore: Create constante for delay time in tests * chore: try old system for tests with CI * fix: Remove non-existent code * Retry github action * tests: Check data event caused shutDown Check the data into the event causing the shutDown of the live entity * Retry github action * Retry github action * Retry github action * chore: Change sentence in deprecated annotation * chore: Remove replaceWith Remove replaceWith where the code cannot be correctly generated without instance of object * chore: Homogenize cancel message * chore: Fix imports and ReplaceWith for Deprecated annotation * chore: Remove ReplaceWith for forgotten Deprecated annotation * Fix duplicate update on live entitites (#298) * fix: Resolve issue about several call update function Use the default job children in live entity to call once times the update function * chore: Remove inline doc in test * fix: Use ShareFlow to manage update method * Retry github action * chore: format * Retry github action * feat: Add possibility to define Job parent to create live entities (#304) * feat: Add possibility to define Job parent to create live entities * fix: Use CoroutineScope to define parent * feat: Allows to set CoroutineScope for each method 'on' * feat: Set coroutineScope into constructor of Live entities Change the parameters of AbstractLiveKordEntity to use coroutineScope by delegation * Reload Github workflow * fix: Use kord.coroutineContext to build default CoroutineScope for live entities * Fix compilation issues * tests: Remove test file (#319) * inline supervisor job Co-authored-by: Distractic Co-authored-by: Distractic <46402441+Distractic@users.noreply.github.com> * 0.7.0: Update Readme/Changelog (#314) * clean up * update changelog: 0.7.0 * add dependencies * remove copy paste left-overs * Update maven central badge (#267) * improve readme and changelog * remove the dashes * use h2 for changes * Add #304 to the changelog * update changelog * api dump Co-authored-by: Michael Rittmeister * Add components to webhook builders (#324) * Add components to webhook builders This adds component fields and DSLs to webhook message builders * Fix webhook builders allowed_mentions SerialName * update readme * api dump * clean rebuilt api files * Allow properties in message edits to be empty/null (#327) * Allow properties in message edits to be empty/null This gives properties in message edit builders the ability to encode values as null or empty lists when applicable, allowing you to remove fields from a message. This is how it should have been from the start, but was missed in code review. * Update CHANGELOG.md * api dump * Fixes/fix followup nullability (#330) * Allow properties in message edits to be empty/null This gives properties in message edit builders the ability to encode values as null or empty lists when applicable, allowing you to remove fields from a message. This is how it should have been from the start, but was missed in code review. * Fix followup nullability This gives properties in follow up edit builders the ability to encode values as null or empty lists when applicable, allowing you to remove fields from a message. It also removes tts from the common interfaces, since only message creates can tts. * Update CHANGELOG.md * Fix components in interactions (#331) * Store components in ComponentData * Correctly retrieve the invoked component from an interaction * Update CHANGELOG.md * api dump Co-authored-by: BartArys Co-authored-by: Michael Rittmeister Co-authored-by: Bart Arys Co-authored-by: Noah Hendrickson Co-authored-by: 2D Co-authored-by: SirNapkin1334 Co-authored-by: qbosst <60557521+qbosst@users.noreply.github.com> Co-authored-by: Distractic Co-authored-by: Distractic <46402441+Distractic@users.noreply.github.com> --- CHANGELOG.md | 13 +++ .../main/kotlin/cache/data/ComponentData.kt | 6 +- .../kotlin/entity/interaction/Interaction.kt | 20 ++-- rest/api/rest.api | 18 ++-- .../interaction/FollowupMessageBuilders.kt | 99 +++++++++++++------ .../json/request/InteractionsRequests.kt | 8 +- 6 files changed, 106 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1fbc69857..9e895e42333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,24 @@ * `MessageModifyBuilder` * `EditWebhookMessageBuilder` * `InteractionResponseModifyRequest` +* `FollowupMessageBuilder` +* `PublicFollowupMessageModifyBuilder` +* `EphemeralFollowupMessageModifyBuilder` +* `PublicFollowupMessageCreateBuilder` +* `EphemeralFollowupMessageCreateBuilder` +* `FollowupMessageModifyRequest` +* `ComponentInteraction` ## Changes * Message-related builders have been changed to accept `null` (for non-collections) and "empty list" (for collections) when editing a message. This makes it possible to remove fields from a message without providing a substitution. +* `FollowupMessageBuilder` no longer has the `tts` field, since it does not apply to all its subclasses. + +## Fixes + +* `ActionRowComponent` properly returns its children. +* `ComponentInteraction#button` is now nullable as its documentation implies. # 0.7.0 diff --git a/core/src/main/kotlin/cache/data/ComponentData.kt b/core/src/main/kotlin/cache/data/ComponentData.kt index 8d53f3c391e..db68257d90e 100644 --- a/core/src/main/kotlin/cache/data/ComponentData.kt +++ b/core/src/main/kotlin/cache/data/ComponentData.kt @@ -6,6 +6,7 @@ import dev.kord.common.entity.DiscordComponent import dev.kord.common.entity.DiscordPartialEmoji import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.common.entity.optional.mapList import kotlinx.serialization.Serializable @Serializable @@ -23,7 +24,7 @@ data class ComponentData( companion object { - fun from(entity: DiscordComponent) = with(entity) { + fun from(entity: DiscordComponent): ComponentData = with(entity) { ComponentData( type, style, @@ -31,7 +32,8 @@ data class ComponentData( emoji, customId, url, - disabled + disabled, + components.mapList { from(it) } ) } diff --git a/core/src/main/kotlin/entity/interaction/Interaction.kt b/core/src/main/kotlin/entity/interaction/Interaction.kt index a399fa2acf3..bd1424603fc 100644 --- a/core/src/main/kotlin/entity/interaction/Interaction.kt +++ b/core/src/main/kotlin/entity/interaction/Interaction.kt @@ -1,7 +1,10 @@ package dev.kord.core.entity.interaction import dev.kord.common.annotation.KordPreview -import dev.kord.common.entity.* +import dev.kord.common.entity.CommandArgument +import dev.kord.common.entity.InteractionType +import dev.kord.common.entity.Permissions +import dev.kord.common.entity.Snowflake import dev.kord.common.entity.optional.* import dev.kord.core.Kord import dev.kord.core.KordObject @@ -11,25 +14,18 @@ import dev.kord.core.behavior.MemberBehavior import dev.kord.core.behavior.UserBehavior import dev.kord.core.behavior.channel.GuildMessageChannelBehavior import dev.kord.core.behavior.interaction.ComponentInteractionBehavior -import dev.kord.core.behavior.interaction.EphemeralInteractionResponseBehavior import dev.kord.core.behavior.interaction.InteractionBehavior -import dev.kord.core.behavior.interaction.PublicInteractionResponseBehavior import dev.kord.core.cache.data.ApplicationInteractionData import dev.kord.core.cache.data.InteractionData import dev.kord.core.cache.data.ResolvedObjectsData import dev.kord.core.entity.* import dev.kord.core.entity.channel.DmChannel import dev.kord.core.entity.channel.ResolvedChannel +import dev.kord.core.entity.component.ActionRowComponent import dev.kord.core.entity.component.ButtonComponent import dev.kord.core.entity.component.Component import dev.kord.core.supplier.EntitySupplier import dev.kord.core.supplier.EntitySupplyStrategy -import dev.kord.rest.builder.interaction.UpdateMessageInteractionResponseCreateBuilder -import dev.kord.rest.json.request.InteractionApplicationCommandCallbackData -import dev.kord.rest.json.request.InteractionResponseCreateRequest -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract /** * An instance of [Interaction] (https://discord.com/developers/docs/interactions/slash-commands#interaction) @@ -385,9 +381,11 @@ class ComponentInteraction( * * @see Component */ - val component: ButtonComponent + val component: ButtonComponent? get() = message?.components.orEmpty() - .filterIsInstance().first { it.customId == componentId } + .filterIsInstance() + .flatMap { it.buttons } + .firstOrNull { it.customId == componentId } override fun withStrategy(strategy: EntitySupplyStrategy<*>): ComponentInteraction = ComponentInteraction( diff --git a/rest/api/rest.api b/rest/api/rest.api index 46f00d8e9ac..e00724704cb 100644 --- a/rest/api/rest.api +++ b/rest/api/rest.api @@ -695,10 +695,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageCre public fun getComponents ()Ljava/util/List; public fun getContent ()Ljava/lang/String; public fun getEmbeds ()Ljava/util/List; - public fun getTts ()Ljava/lang/Boolean; + public final fun getTts ()Ljava/lang/Boolean; public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V public fun setContent (Ljava/lang/String;)V - public fun setTts (Ljava/lang/Boolean;)V + public final fun setTts (Ljava/lang/Boolean;)V public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest; public synthetic fun toRequest ()Ljava/lang/Object; } @@ -709,10 +709,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageMod public fun getComponents ()Ljava/util/List; public fun getContent ()Ljava/lang/String; public fun getEmbeds ()Ljava/util/List; - public fun getTts ()Ljava/lang/Boolean; public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V + public fun setComponents (Ljava/util/List;)V public fun setContent (Ljava/lang/String;)V - public fun setTts (Ljava/lang/Boolean;)V + public fun setEmbeds (Ljava/util/List;)V public fun toRequest ()Ldev/kord/rest/json/request/FollowupMessageModifyRequest; public synthetic fun toRequest ()Ljava/lang/Object; } @@ -748,9 +748,7 @@ public abstract interface class dev/kord/rest/builder/interaction/FollowupMessag public abstract fun getComponents ()Ljava/util/List; public abstract fun getContent ()Ljava/lang/String; public abstract fun getEmbeds ()Ljava/util/List; - public abstract fun getTts ()Ljava/lang/Boolean; public abstract fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V - public abstract fun setTts (Ljava/lang/Boolean;)V } public final class dev/kord/rest/builder/interaction/FollowupMessageBuildersKt { @@ -794,10 +792,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageCreate public fun getContent ()Ljava/lang/String; public fun getEmbeds ()Ljava/util/List; public final fun getFiles ()Ljava/util/List; - public fun getTts ()Ljava/lang/Boolean; + public final fun getTts ()Ljava/lang/Boolean; public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V public fun setContent (Ljava/lang/String;)V - public fun setTts (Ljava/lang/Boolean;)V + public final fun setTts (Ljava/lang/Boolean;)V public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest; public synthetic fun toRequest ()Ljava/lang/Object; } @@ -811,10 +809,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageModify public fun getContent ()Ljava/lang/String; public fun getEmbeds ()Ljava/util/List; public final fun getFiles ()Ljava/util/List; - public fun getTts ()Ljava/lang/Boolean; public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V + public fun setComponents (Ljava/util/List;)V public fun setContent (Ljava/lang/String;)V - public fun setTts (Ljava/lang/Boolean;)V + public fun setEmbeds (Ljava/util/List;)V public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageModifyRequest; public synthetic fun toRequest ()Ljava/lang/Object; } diff --git a/rest/src/main/kotlin/builder/interaction/FollowupMessageBuilders.kt b/rest/src/main/kotlin/builder/interaction/FollowupMessageBuilders.kt index 59bd08b20c0..5f7adfdba10 100644 --- a/rest/src/main/kotlin/builder/interaction/FollowupMessageBuilders.kt +++ b/rest/src/main/kotlin/builder/interaction/FollowupMessageBuilders.kt @@ -6,12 +6,16 @@ import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.delegate.delegate import dev.kord.common.entity.optional.map +import dev.kord.common.entity.optional.mapList import dev.kord.rest.builder.RequestBuilder import dev.kord.rest.builder.component.ActionRowBuilder import dev.kord.rest.builder.component.MessageComponentBuilder import dev.kord.rest.builder.message.AllowedMentionsBuilder import dev.kord.rest.builder.message.EmbedBuilder -import dev.kord.rest.json.request.* +import dev.kord.rest.json.request.FollowupMessageCreateRequest +import dev.kord.rest.json.request.FollowupMessageModifyRequest +import dev.kord.rest.json.request.MultipartFollowupMessageCreateRequest +import dev.kord.rest.json.request.MultipartFollowupMessageModifyRequest import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.InputStream @@ -24,13 +28,11 @@ import kotlin.contracts.contract @KordPreview sealed interface FollowupMessageBuilder : RequestBuilder { - var tts: Boolean? - var allowedMentions: AllowedMentionsBuilder? - val embeds: MutableList + val embeds: MutableList? - val components: MutableList + val components: MutableList? val content: String? @@ -42,13 +44,52 @@ inline fun FollowupMessageBuilder.actionRow(builder: ActionRowBuilder.() callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } - components.add(ActionRowBuilder().apply(builder)) + when (this) { + is EphemeralFollowupMessageCreateBuilder -> { + components.add(ActionRowBuilder().apply(builder)) + } + + is EphemeralFollowupMessageModifyBuilder -> { + components = (components ?: mutableListOf()).also { + it.add(ActionRowBuilder().apply(builder)) + } + } + + is PublicFollowupMessageCreateBuilder -> { + components.add(ActionRowBuilder().apply(builder)) + } + + is PublicFollowupMessageModifyBuilder -> { + components = (components ?: mutableListOf()).also { + it.add(ActionRowBuilder().apply(builder)) + } + } + } + } @KordPreview @OptIn(ExperimentalContracts::class) inline fun FollowupMessageBuilder.embed(builder: EmbedBuilder.() -> Unit) { contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } - embeds += EmbedBuilder().apply(builder) + + when(this){ + is EphemeralFollowupMessageCreateBuilder -> { + embeds.add(EmbedBuilder().apply(builder)) + } + is EphemeralFollowupMessageModifyBuilder -> { + embeds = (embeds ?: mutableListOf()).also { + it.add(EmbedBuilder().apply(builder)) + } + } + is PublicFollowupMessageCreateBuilder -> { + embeds.add(EmbedBuilder().apply(builder)) + } + is PublicFollowupMessageModifyBuilder -> { + embeds = (embeds ?: mutableListOf()).also { + it.add(EmbedBuilder().apply(builder)) + } + } + } } /** @@ -69,22 +110,19 @@ inline fun FollowupMessageBuilder.allowedMentions(block: AllowedMentionsB @KordDsl class PublicFollowupMessageModifyBuilder : FollowupMessageBuilder { - private var _content: Optional = Optional.Missing() + private var _content: Optional = Optional.Missing() override var content: String? by ::_content.delegate() - override val embeds: MutableList = mutableListOf() - - private var _tts: OptionalBoolean = OptionalBoolean.Missing - override var tts: Boolean? by ::_tts.delegate() + private var _embeds: Optional> = Optional.Missing() + override var embeds: MutableList? by ::_embeds.delegate() val files: MutableList> = mutableListOf() - - private var _allowedMentions: Optional = Optional.Missing() + private var _allowedMentions: Optional = Optional.Missing() override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate() - override val components: MutableList = mutableListOf() - + private var _components: Optional> = Optional.Missing() + override var components: MutableList? by ::_components.delegate() fun addFile(name: String, content: InputStream) { files += name to content @@ -93,13 +131,14 @@ class PublicFollowupMessageModifyBuilder : suspend fun addFile(path: Path) = withContext(Dispatchers.IO) { addFile(path.fileName.toString(), Files.newInputStream(path)) } + override fun toRequest(): MultipartFollowupMessageModifyRequest { return MultipartFollowupMessageModifyRequest( FollowupMessageModifyRequest( _content, - Optional.missingOnEmpty(embeds.map(EmbedBuilder::toRequest)), + _embeds.mapList { it.toRequest() }, _allowedMentions.map { it.build() }, - Optional.missingOnEmpty(components.map(MessageComponentBuilder::build)) + _components.mapList { it.build() }, ), files ) @@ -111,24 +150,24 @@ class PublicFollowupMessageModifyBuilder : @KordDsl class EphemeralFollowupMessageModifyBuilder : FollowupMessageBuilder { - private var _content: Optional = Optional.Missing() + private var _content: Optional = Optional.Missing() override var content: String? by ::_content.delegate() - private var _tts: OptionalBoolean = OptionalBoolean.Missing - override var tts: Boolean? by ::_tts.delegate() - - override val embeds: MutableList = mutableListOf() + private var _embeds: Optional> = Optional.Missing() + override var embeds: MutableList? by ::_embeds.delegate() private var _allowedMentions: Optional = Optional.Missing() override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate() - override val components: MutableList = mutableListOf() + private var _components: Optional> = Optional.Missing() + override var components: MutableList? by ::_components.delegate() override fun toRequest(): FollowupMessageModifyRequest { return FollowupMessageModifyRequest( content = _content, allowedMentions = _allowedMentions.map { it.build() }, - components = Optional.missingOnEmpty(components.map(MessageComponentBuilder::build)) + embeds = _embeds.mapList { it.toRequest() }, + components = _components.mapList { it.build() } ) } } @@ -141,20 +180,18 @@ class PublicFollowupMessageCreateBuilder : FollowupMessageBuilder = Optional.Missing() override var content: String? by ::_content.delegate() - private var _tts: OptionalBoolean = OptionalBoolean.Missing - override var tts: Boolean? by ::_tts.delegate() + var tts: Boolean? by ::_tts.delegate() private var _allowedMentions: Optional = Optional.Missing() override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate() val files: MutableList> = mutableListOf() + override val embeds: MutableList = mutableListOf() override val components: MutableList = mutableListOf() - - override fun toRequest(): MultipartFollowupMessageCreateRequest = MultipartFollowupMessageCreateRequest( FollowupMessageCreateRequest( @@ -178,7 +215,7 @@ class EphemeralFollowupMessageCreateBuilder : FollowupMessageBuilder = Optional.Missing() override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate() @@ -200,4 +237,4 @@ class EphemeralFollowupMessageCreateBuilder : FollowupMessageBuilder = Optional.Missing(), - val embeds: Optional> = Optional.Missing(), + val content: Optional = Optional.Missing(), + val embeds: Optional?> = Optional.Missing(), @SerialName("allowed_mentions") - val allowedMentions: Optional = Optional.Missing(), - val components: Optional> = Optional.Missing() + val allowedMentions: Optional = Optional.Missing(), + val components: Optional?> = Optional.Missing() ) @KordPreview