From f54fdabc06d08f5dd3fff2893aa5a24d48d568fe Mon Sep 17 00:00:00 2001 From: NoComment <67918617+NoComment1105@users.noreply.github.com> Date: Tue, 4 Apr 2023 23:09:30 +0100 Subject: [PATCH] Add guild onboarding (#805) To get the GuildOnboarding object for a Guild just call guild.getOnboarding(). see https://github.com/discord/discord-api-docs/pull/5915 --------- Co-authored-by: Lukellmann --- common/api/common.api | 141 ++++++++++++ .../common/entity/OnboardingPromptType.kt | 81 +++++++ .../kotlin/entity/DiscordGuildOnboarding.kt | 45 ++++ core/api/core.api | 96 +++++++- .../src/main/kotlin/behavior/GuildBehavior.kt | 19 ++ .../kotlin/entity/{GuildEmoji.kt => Emoji.kt} | 40 +++- .../src/main/kotlin/entity/GuildOnboarding.kt | 205 ++++++++++++++++++ .../exception/EntityNotFoundException.kt | 3 + .../kotlin/supplier/RestEntitySupplier.kt | 20 ++ rest/api/rest.api | 5 + rest/src/main/kotlin/route/Route.kt | 3 + rest/src/main/kotlin/service/GuildService.kt | 5 + 12 files changed, 655 insertions(+), 8 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt create mode 100644 common/src/main/kotlin/entity/DiscordGuildOnboarding.kt rename core/src/main/kotlin/entity/{GuildEmoji.kt => Emoji.kt} (79%) create mode 100644 core/src/main/kotlin/entity/GuildOnboarding.kt diff --git a/common/api/common.api b/common/api/common.api index f0613df33ea..906ba8f23fb 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -3835,6 +3835,41 @@ public final class dev/kord/common/entity/DiscordGuildMember$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class dev/kord/common/entity/DiscordGuildOnboarding { + public static final field Companion Ldev/kord/common/entity/DiscordGuildOnboarding$Companion; + public synthetic fun (ILdev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Z)V + public final fun component1 ()Ldev/kord/common/entity/Snowflake; + public final fun component2 ()Ljava/util/List; + public final fun component3 ()Ljava/util/List; + public final fun component4 ()Z + public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Z)Ldev/kord/common/entity/DiscordGuildOnboarding; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordGuildOnboarding;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;ZILjava/lang/Object;)Ldev/kord/common/entity/DiscordGuildOnboarding; + public fun equals (Ljava/lang/Object;)Z + public final fun getDefaultChannelIds ()Ljava/util/List; + public final fun getEnabled ()Z + public final fun getGuildId ()Ldev/kord/common/entity/Snowflake; + public final fun getPrompts ()Ljava/util/List; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public static final fun write$Self (Ldev/kord/common/entity/DiscordGuildOnboarding;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V +} + +public final class dev/kord/common/entity/DiscordGuildOnboarding$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildOnboarding$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordGuildOnboarding; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordGuildOnboarding;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordGuildOnboarding$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/DiscordGuildPreview { public static final field Companion Ldev/kord/common/entity/DiscordGuildPreview$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IILjava/lang/String;Ljava/util/List;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V @@ -4672,6 +4707,86 @@ public final class dev/kord/common/entity/DiscordNull$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class dev/kord/common/entity/DiscordOnboardingPrompt { + public static final field Companion Ldev/kord/common/entity/DiscordOnboardingPrompt$Companion; + public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/OnboardingPromptType;Ljava/util/List;Ljava/lang/String;ZZZLkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/OnboardingPromptType;Ljava/util/List;Ljava/lang/String;ZZZ)V + public final fun component1 ()Ldev/kord/common/entity/Snowflake; + public final fun component2 ()Ldev/kord/common/entity/OnboardingPromptType; + public final fun component3 ()Ljava/util/List; + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Z + public final fun component6 ()Z + public final fun component7 ()Z + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/OnboardingPromptType;Ljava/util/List;Ljava/lang/String;ZZZ)Ldev/kord/common/entity/DiscordOnboardingPrompt; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordOnboardingPrompt;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/OnboardingPromptType;Ljava/util/List;Ljava/lang/String;ZZZILjava/lang/Object;)Ldev/kord/common/entity/DiscordOnboardingPrompt; + public fun equals (Ljava/lang/Object;)Z + public final fun getId ()Ldev/kord/common/entity/Snowflake; + public final fun getInOnboarding ()Z + public final fun getOptions ()Ljava/util/List; + public final fun getRequired ()Z + public final fun getSingleSelect ()Z + public final fun getTitle ()Ljava/lang/String; + public final fun getType ()Ldev/kord/common/entity/OnboardingPromptType; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public static final fun write$Self (Ldev/kord/common/entity/DiscordOnboardingPrompt;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V +} + +public final class dev/kord/common/entity/DiscordOnboardingPrompt$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/kord/common/entity/DiscordOnboardingPrompt$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordOnboardingPrompt; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordOnboardingPrompt;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordOnboardingPrompt$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordOnboardingPromptOption { + public static final field Companion Ldev/kord/common/entity/DiscordOnboardingPromptOption$Companion; + public synthetic fun (ILdev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Ldev/kord/common/entity/DiscordEmoji;Ljava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Ldev/kord/common/entity/DiscordEmoji;Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ldev/kord/common/entity/Snowflake; + public final fun component2 ()Ljava/util/List; + public final fun component3 ()Ljava/util/List; + public final fun component4 ()Ldev/kord/common/entity/DiscordEmoji; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Ldev/kord/common/entity/DiscordEmoji;Ljava/lang/String;Ljava/lang/String;)Ldev/kord/common/entity/DiscordOnboardingPromptOption; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordOnboardingPromptOption;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;Ldev/kord/common/entity/DiscordEmoji;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordOnboardingPromptOption; + public fun equals (Ljava/lang/Object;)Z + public final fun getChannelIds ()Ljava/util/List; + public final fun getDescription ()Ljava/lang/String; + public final fun getEmoji ()Ldev/kord/common/entity/DiscordEmoji; + public final fun getId ()Ldev/kord/common/entity/Snowflake; + public final fun getRoleIds ()Ljava/util/List; + public final fun getTitle ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public static final fun write$Self (Ldev/kord/common/entity/DiscordOnboardingPromptOption;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V +} + +public final class dev/kord/common/entity/DiscordOnboardingPromptOption$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/kord/common/entity/DiscordOnboardingPromptOption$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordOnboardingPromptOption; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordOnboardingPromptOption;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordOnboardingPromptOption$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/DiscordOptionallyMemberUser { public static final field Companion Ldev/kord/common/entity/DiscordOptionallyMemberUser$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V @@ -7393,6 +7508,32 @@ public final class dev/kord/common/entity/NsfwLevel$Unknown : dev/kord/common/en public fun (I)V } +public abstract class dev/kord/common/entity/OnboardingPromptType { + public static final field Companion Ldev/kord/common/entity/OnboardingPromptType$Companion; + public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z + public final fun getValue ()I + public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; +} + +public final class dev/kord/common/entity/OnboardingPromptType$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/OnboardingPromptType$Dropdown : dev/kord/common/entity/OnboardingPromptType { + public static final field INSTANCE Ldev/kord/common/entity/OnboardingPromptType$Dropdown; +} + +public final class dev/kord/common/entity/OnboardingPromptType$MultipleChoice : dev/kord/common/entity/OnboardingPromptType { + public static final field INSTANCE Ldev/kord/common/entity/OnboardingPromptType$MultipleChoice; +} + +public final class dev/kord/common/entity/OnboardingPromptType$Unknown : dev/kord/common/entity/OnboardingPromptType { + public fun (I)V +} + public abstract class dev/kord/common/entity/Option { public static final field Companion Ldev/kord/common/entity/Option$Companion; public abstract fun getName ()Ljava/lang/String; diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt new file mode 100644 index 00000000000..c4816f8c5ce --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt @@ -0,0 +1,81 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * See [OnboardingPromptType]s in the + * [Discord Developer Documentation](https://discord.com/developers/docs/resources/guild#guild-onboarding-object-prompt-types). + */ +@Serializable(with = OnboardingPromptType.Serializer::class) +public sealed class OnboardingPromptType( + /** + * The raw value used by Discord. + */ + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is OnboardingPromptType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + public final override fun toString(): String = + "OnboardingPromptType.${this::class.simpleName}(value=$value)" + + /** + * An unknown [OnboardingPromptType]. + * + * This is used as a fallback for [OnboardingPromptType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : OnboardingPromptType(value) + + public object MultipleChoice : OnboardingPromptType(0) + + public object Dropdown : OnboardingPromptType(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.OnboardingPromptType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: OnboardingPromptType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> MultipleChoice + 1 -> Dropdown + else -> Unknown(value) + } + } + + public companion object { + /** + * A [List] of all known [OnboardingPromptType]s. + */ + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + MultipleChoice, + Dropdown, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordGuildOnboarding.kt b/common/src/main/kotlin/entity/DiscordGuildOnboarding.kt new file mode 100644 index 00000000000..4b8df0f4003 --- /dev/null +++ b/common/src/main/kotlin/entity/DiscordGuildOnboarding.kt @@ -0,0 +1,45 @@ +@file:GenerateKordEnum( + name = "OnboardingPromptType", valueType = INT, + docUrl = "https://discord.com/developers/docs/resources/guild#guild-onboarding-object-prompt-types", + entries = [ + Entry("MultipleChoice", intValue = 0), + Entry("Dropdown", intValue = 1), + ], +) + +package dev.kord.common.entity + +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +public data class DiscordGuildOnboarding( + @SerialName("guild_id") val guildId: Snowflake, + val prompts: List, + @SerialName("default_channel_ids") val defaultChannelIds: List, + val enabled: Boolean, +) + +@Serializable +public data class DiscordOnboardingPrompt( + val id: Snowflake, + val type: OnboardingPromptType, + val options: List, + val title: String, + @SerialName("single_select") val singleSelect: Boolean, + val required: Boolean, + @SerialName("in_onboarding") val inOnboarding: Boolean, +) + +@Serializable +public data class DiscordOnboardingPromptOption( + val id: Snowflake, + @SerialName("channel_ids") val channelIds: List, + @SerialName("role_ids") val roleIds: List, + val emoji: DiscordEmoji, + val title: String, + val description: String?, +) diff --git a/core/api/core.api b/core/api/core.api index dba88513bfc..805b2fef01e 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -264,6 +264,8 @@ public abstract interface class dev/kord/core/behavior/GuildBehavior : dev/kord/ public abstract fun getMemberOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getMembers ()Lkotlinx/coroutines/flow/Flow; public abstract fun getMembers (Ljava/lang/String;I)Lkotlinx/coroutines/flow/Flow; + public abstract fun getOnboarding (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun getOnboardingOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getPresences ()Lkotlinx/coroutines/flow/Flow; public abstract fun getPreview (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getPreviewOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -337,6 +339,8 @@ public final class dev/kord/core/behavior/GuildBehavior$DefaultImpls { public static fun getMembers (Ldev/kord/core/behavior/GuildBehavior;)Lkotlinx/coroutines/flow/Flow; public static fun getMembers (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;I)Lkotlinx/coroutines/flow/Flow; public static synthetic fun getMembers$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;IILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; + public static fun getOnboarding (Ldev/kord/core/behavior/GuildBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun getOnboardingOrNull (Ldev/kord/core/behavior/GuildBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun getPresences (Ldev/kord/core/behavior/GuildBehavior;)Lkotlinx/coroutines/flow/Flow; public static fun getPreview (Ldev/kord/core/behavior/GuildBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun getPreviewOrNull (Ldev/kord/core/behavior/GuildBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -6038,6 +6042,11 @@ public final class dev/kord/core/entity/Embed$Video : dev/kord/core/KordObject { public fun toString ()Ljava/lang/String; } +public abstract interface class dev/kord/core/entity/Emoji { + public abstract fun getMention ()Ljava/lang/String; + public abstract fun getName ()Ljava/lang/String; +} + public abstract interface class dev/kord/core/entity/Entity : java/lang/Comparable { public static final field Companion Ldev/kord/core/entity/Entity$Companion; public abstract fun compareTo (Ldev/kord/core/entity/Entity;)I @@ -6134,6 +6143,8 @@ public final class dev/kord/core/entity/Guild : dev/kord/core/behavior/GuildBeha public final fun getMfaLevel ()Ldev/kord/common/entity/MFALevel; public final fun getName ()Ljava/lang/String; public final fun getNsfw ()Ldev/kord/common/entity/NsfwLevel; + public fun getOnboarding (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getOnboardingOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getOwner ()Ldev/kord/core/behavior/MemberBehavior; public final fun getOwner (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getOwnerId ()Ldev/kord/common/entity/Snowflake; @@ -6206,7 +6217,7 @@ public final class dev/kord/core/entity/Guild : dev/kord/core/behavior/GuildBeha public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; } -public final class dev/kord/core/entity/GuildEmoji : dev/kord/core/entity/KordEntity, dev/kord/core/entity/Strategizable { +public final class dev/kord/core/entity/GuildEmoji : dev/kord/core/entity/Emoji, dev/kord/core/entity/KordEntity, dev/kord/core/entity/Strategizable { public fun (Ldev/kord/core/cache/data/EmojiData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V public synthetic fun (Ldev/kord/core/cache/data/EmojiData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun compareTo (Ldev/kord/core/entity/Entity;)I @@ -6222,8 +6233,8 @@ public final class dev/kord/core/entity/GuildEmoji : dev/kord/core/entity/KordEn public fun getKord ()Ldev/kord/core/Kord; public final fun getMember ()Ldev/kord/core/behavior/MemberBehavior; public final fun getMember (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getMention ()Ljava/lang/String; - public final fun getName ()Ljava/lang/String; + public fun getMention ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; public final fun getRequiresColons ()Z public final fun getRoleBehaviors ()Ljava/util/Set; public final fun getRoleIds ()Ljava/util/Set; @@ -6241,6 +6252,71 @@ public final class dev/kord/core/entity/GuildEmoji : dev/kord/core/entity/KordEn public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; } +public final class dev/kord/core/entity/GuildOnboarding : dev/kord/core/KordObject, dev/kord/core/entity/Strategizable { + public fun (Ldev/kord/common/entity/DiscordGuildOnboarding;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V + public synthetic fun (Ldev/kord/common/entity/DiscordGuildOnboarding;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getData ()Ldev/kord/common/entity/DiscordGuildOnboarding; + public final fun getDefaultChannelBehaviors ()Ljava/util/List; + public final fun getDefaultChannelIds ()Ljava/util/List; + public final fun getDefaultChannels ()Lkotlinx/coroutines/flow/Flow; + public final fun getGuild ()Ldev/kord/core/behavior/GuildBehavior; + public final fun getGuild (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getGuildId ()Ldev/kord/common/entity/Snowflake; + public final fun getGuildOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getKord ()Ldev/kord/core/Kord; + public final fun getPrompts ()Ljava/util/List; + public fun getSupplier ()Ldev/kord/core/supplier/EntitySupplier; + public final fun isEnabled ()Z + public fun toString ()Ljava/lang/String; + public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/GuildOnboarding; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; +} + +public final class dev/kord/core/entity/GuildOnboarding$Prompt : dev/kord/core/entity/KordEntity { + public fun (Ldev/kord/common/entity/DiscordOnboardingPrompt;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;)V + public fun compareTo (Ldev/kord/core/entity/Entity;)I + public synthetic fun compareTo (Ljava/lang/Object;)I + public fun equals (Ljava/lang/Object;)Z + public final fun getData ()Ldev/kord/common/entity/DiscordOnboardingPrompt; + public final fun getGuildId ()Ldev/kord/common/entity/Snowflake; + public fun getId ()Ldev/kord/common/entity/Snowflake; + public fun getKord ()Ldev/kord/core/Kord; + public final fun getOptions ()Ljava/util/List; + public final fun getTitle ()Ljava/lang/String; + public final fun getType ()Ldev/kord/common/entity/OnboardingPromptType; + public fun hashCode ()I + public final fun isInOnboarding ()Z + public final fun isRequired ()Z + public final fun isSingleSelect ()Z + public fun toString ()Ljava/lang/String; +} + +public final class dev/kord/core/entity/GuildOnboarding$Prompt$Option : dev/kord/core/entity/KordEntity, dev/kord/core/entity/Strategizable { + public fun (Ldev/kord/common/entity/DiscordOnboardingPromptOption;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V + public synthetic fun (Ldev/kord/common/entity/DiscordOnboardingPromptOption;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun compareTo (Ldev/kord/core/entity/Entity;)I + public synthetic fun compareTo (Ljava/lang/Object;)I + public fun equals (Ljava/lang/Object;)Z + public final fun getChannelBehaviors ()Ljava/util/List; + public final fun getChannelIds ()Ljava/util/List; + public final fun getChannels ()Lkotlinx/coroutines/flow/Flow; + public final fun getData ()Ldev/kord/common/entity/DiscordOnboardingPromptOption; + public final fun getDescription ()Ljava/lang/String; + public final fun getEmoji ()Ldev/kord/core/entity/Emoji; + public final fun getGuildId ()Ldev/kord/common/entity/Snowflake; + public fun getId ()Ldev/kord/common/entity/Snowflake; + public fun getKord ()Ldev/kord/core/Kord; + public final fun getRoleBehaviors ()Ljava/util/List; + public final fun getRoleIds ()Ljava/util/List; + public final fun getRoles ()Lkotlinx/coroutines/flow/Flow; + public fun getSupplier ()Ldev/kord/core/supplier/EntitySupplier; + public final fun getTitle ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/GuildOnboarding$Prompt$Option; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; +} + public final class dev/kord/core/entity/GuildPreview : dev/kord/core/entity/KordEntity { public fun (Ldev/kord/core/cache/data/GuildPreviewData;Ldev/kord/core/Kord;)V public fun compareTo (Ldev/kord/core/entity/Entity;)I @@ -6674,6 +6750,8 @@ public final class dev/kord/core/entity/PartialGuild : dev/kord/core/behavior/Gu public fun getMembers (Ljava/lang/String;I)Lkotlinx/coroutines/flow/Flow; public final fun getName ()Ljava/lang/String; public final fun getNsfw ()Ldev/kord/common/entity/NsfwLevel; + public fun getOnboarding (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getOnboardingOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getOwner ()Ljava/lang/Boolean; public final fun getPermissions ()Ldev/kord/common/entity/Permissions; public fun getPresences ()Lkotlinx/coroutines/flow/Flow; @@ -6931,6 +7009,15 @@ public final class dev/kord/core/entity/StageInstance : dev/kord/core/behavior/S public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; } +public final class dev/kord/core/entity/StandardEmoji : dev/kord/core/entity/Emoji { + public fun (Ljava/lang/String;)V + public fun equals (Ljava/lang/Object;)Z + public fun getMention ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public class dev/kord/core/entity/Sticker : dev/kord/core/entity/KordEntity { public fun (Ldev/kord/core/cache/data/StickerData;Ldev/kord/core/Kord;)V public fun compareTo (Ldev/kord/core/entity/Entity;)I @@ -12833,6 +12920,7 @@ public final class dev/kord/core/exception/EntityNotFoundException$Companion { public final fun inviteNotFound (Ljava/lang/String;)Ljava/lang/Void; public final fun memberNotFound (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ljava/lang/Void; public final fun messageNotFound (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ljava/lang/Void; + public final fun onboardingNotFound (Ldev/kord/common/entity/Snowflake;)Ljava/lang/Void; public final fun roleNotFound (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ljava/lang/Void; public final fun selfNotFound ()Ljava/lang/Void; public final fun stageInstanceNotFound (Ldev/kord/common/entity/Snowflake;)Ljava/lang/Void; @@ -13499,6 +13587,8 @@ public final class dev/kord/core/supplier/RestEntitySupplier : dev/kord/core/sup public fun getGuildBans (Ldev/kord/common/entity/Snowflake;Ljava/lang/Integer;)Lkotlinx/coroutines/flow/Flow; public fun getGuildChannels (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; public fun getGuildMembers (Ldev/kord/common/entity/Snowflake;Ljava/lang/Integer;)Lkotlinx/coroutines/flow/Flow; + public final fun getGuildOnboarding (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getGuildOnboardingOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getGuildOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getGuildPreview (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getGuildPreviewOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/core/src/main/kotlin/behavior/GuildBehavior.kt b/core/src/main/kotlin/behavior/GuildBehavior.kt index d2eb16c0bf5..d557377c5af 100644 --- a/core/src/main/kotlin/behavior/GuildBehavior.kt +++ b/core/src/main/kotlin/behavior/GuildBehavior.kt @@ -547,6 +547,25 @@ public interface GuildBehavior : KordEntity, Strategizable { return WelcomeScreen(data, kord) } + /** + * Requests the [onboarding][GuildOnboarding] object for this guild. + * + * This is not resolvable through cache and will always use the [rest strategy][EntitySupplyStrategy.rest] instead. + * + * @throws RestRequestException if something went wrong during the request. + * @throws EntityNotFoundException if the [onboarding][GuildOnboarding] wasn't found. + */ + public suspend fun getOnboarding(): GuildOnboarding = kord.with(rest).getGuildOnboarding(id) + + /** + * Requests the [onboarding][GuildOnboarding] object for this guild. Returns `null` if it wasn't found. + * + * This is not resolvable through cache and will always use the [rest strategy][EntitySupplyStrategy.rest] instead. + * + * @throws RestRequestException if something went wrong during the request. + */ + public suspend fun getOnboardingOrNull(): GuildOnboarding? = kord.with(rest).getGuildOnboardingOrNull(id) + /** * Requests to get the vanity url of this guild, if present. * diff --git a/core/src/main/kotlin/entity/GuildEmoji.kt b/core/src/main/kotlin/entity/Emoji.kt similarity index 79% rename from core/src/main/kotlin/entity/GuildEmoji.kt rename to core/src/main/kotlin/entity/Emoji.kt index 549f076e5bc..e7e04d32d35 100644 --- a/core/src/main/kotlin/entity/GuildEmoji.kt +++ b/core/src/main/kotlin/entity/Emoji.kt @@ -18,14 +18,44 @@ import java.util.* import kotlin.contracts.InvocationKind import kotlin.contracts.contract +/** Either a [StandardEmoji] or a [GuildEmoji]. */ +public sealed interface Emoji { + /** + * Either the unicode representation of the emoji if it's a [StandardEmoji] or the emoji name if it's a + * [GuildEmoji]. + */ + public val name: String? + + /** + * Either the unicode representation of the emoji if it's a [StandardEmoji] or the + * [mention string](https://discord.com/developers/docs/reference#message-formatting) if it's a [GuildEmoji]. + */ + public val mention: String +} + +/** + * An instance of a + * [standard emoji](https://discord.com/developers/docs/resources/emoji#emoji-object-standard-emoji-example). + * + * @property name The unicode representation of this emoji. + */ +public class StandardEmoji(override val name: String) : Emoji { + /** The unicode representation of this emoji. */ + override val mention: String get() = name + override fun equals(other: Any?): Boolean = other is StandardEmoji && this.name == other.name + override fun hashCode(): Int = name.hashCode() + override fun toString(): String = "StandardEmoji(name=$name)" +} + /** - * An instance of a [Discord emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) belonging to a specific guild. + * An instance of an [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) belonging to a specific + * [Guild]. */ public class GuildEmoji( public val data: EmojiData, override val kord: Kord, override val supplier: EntitySupplier = kord.defaultSupplier -) : KordEntity, Strategizable { +) : Emoji, KordEntity, Strategizable { override val id: Snowflake get() = data.id @@ -33,7 +63,7 @@ public class GuildEmoji( public val guildId: Snowflake get() = data.guildId - public val mention: String + override val mention: String get() = if (isAnimated) "" else "<:$name:$id>" /** @@ -56,7 +86,7 @@ public class GuildEmoji( * * This property can be null when trying to get the name of an emoji that was deleted. */ - public val name: String? get() = data.name + override val name: String? get() = data.name /** * Whether this emoji needs to be wrapped in colons. @@ -72,7 +102,7 @@ public class GuildEmoji( * The behaviors of the [roles][Role] for which this emoji was whitelisted. */ public val roleBehaviors: Set - get() = data.roles.orEmpty().map { RoleBehavior(guildId = guildId, id = id, kord = kord) }.toSet() + get() = data.roles.orEmpty().map { roleId -> RoleBehavior(guildId = guildId, id = roleId, kord = kord) }.toSet() /** * The [roles][Role] for which this emoji was whitelisted. diff --git a/core/src/main/kotlin/entity/GuildOnboarding.kt b/core/src/main/kotlin/entity/GuildOnboarding.kt new file mode 100644 index 00000000000..f30aad2e088 --- /dev/null +++ b/core/src/main/kotlin/entity/GuildOnboarding.kt @@ -0,0 +1,205 @@ +package dev.kord.core.entity + +import dev.kord.common.entity.* +import dev.kord.common.exception.RequestException +import dev.kord.core.Kord +import dev.kord.core.KordObject +import dev.kord.core.behavior.GuildBehavior +import dev.kord.core.behavior.RoleBehavior +import dev.kord.core.behavior.channel.TopGuildChannelBehavior +import dev.kord.core.cache.data.toData +import dev.kord.core.entity.channel.TopGuildChannel +import dev.kord.core.exception.EntityNotFoundException +import dev.kord.core.supplier.EntitySupplier +import dev.kord.core.supplier.EntitySupplyStrategy +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.filter +import java.util.* + +/** + * Represents the [onboarding](https://support.discord.com/hc/en-us/articles/11074987197975-Community-Onboarding-FAQ) + * flow for a [Guild]. + */ +public class GuildOnboarding( + public val data: DiscordGuildOnboarding, + override val kord: Kord, + override val supplier: EntitySupplier = kord.defaultSupplier, +) : KordObject, Strategizable { + /** The ID of the [Guild] this onboarding is part of. */ + public val guildId: Snowflake get() = data.guildId + + /** The behavior of the [Guild] this onboarding is part of. */ + public val guild: GuildBehavior get() = GuildBehavior(guildId, kord) + + /** The [Prompt]s shown during onboarding and in customize community. */ + public val prompts: List get() = data.prompts.map { Prompt(it, guildId, kord) } + + /** The IDs of the [channels][TopGuildChannel] that [Member]s get opted into automatically. */ + public val defaultChannelIds: List get() = data.defaultChannelIds + + /** The behaviors of the [channels][TopGuildChannel] that [Member]s get opted into automatically. */ + public val defaultChannelBehaviors: List + get() = defaultChannelIds.map { channelId -> TopGuildChannelBehavior(guildId, id = channelId, kord) } + + /** Whether onboarding is enabled in the [guild]. */ + public val isEnabled: Boolean get() = data.enabled + + /** + * Requests the [Guild] this onboarding is part of. + * + * @throws RequestException if something went wrong while retrieving the guild. + * @throws EntityNotFoundException if the guild is null. + */ + public suspend fun getGuild(): Guild = supplier.getGuild(guildId) + + /** + * Requests the [Guild] this onboarding is part of, returns `null` when the guild isn't present. + * + * @throws RequestException if something went wrong while retrieving the guild. + */ + public suspend fun getGuildOrNull(): Guild? = supplier.getGuildOrNull(guildId) + + /** + * Requests the [channels][TopGuildChannel] that [Member]s get opted into automatically. + * + * The returned [Flow] is lazily executed, any [RequestException] will be thrown on + * [terminal operators](https://kotlinlang.org/docs/reference/coroutines/flow.html#terminal-flow-operators) instead. + */ + public val defaultChannels: Flow + get() { + val ids = defaultChannelIds + return if (ids.isEmpty()) emptyFlow() else supplier.getGuildChannels(guildId).filter { it.id in ids } + } + + override fun withStrategy(strategy: EntitySupplyStrategy<*>): GuildOnboarding = + GuildOnboarding(data, kord, strategy.supply(kord)) + + override fun toString(): String = "GuildOnboarding(data=$data, kord=$kord, supplier=$supplier)" + + + /** + * Represents a prompt for a [GuildOnboarding]. + * + * @property guildId The ID of the [Guild] the [onboarding][GuildOnboarding] is part of. + */ + public class Prompt( + public val data: DiscordOnboardingPrompt, + public val guildId: Snowflake, + override val kord: Kord, + ) : KordEntity { + override val id: Snowflake get() = data.id + + /** The [type][OnboardingPromptType] of this prompt. */ + public val type: OnboardingPromptType get() = data.type + + /** The [Option]s available within this prompt. */ + public val options: List