Skip to content

Commit

Permalink
Add guild onboarding (#805)
Browse files Browse the repository at this point in the history
To get the GuildOnboarding object for a Guild just call
guild.getOnboarding().

see discord/discord-api-docs#5915

---------

Co-authored-by: Lukellmann <[email protected]>
  • Loading branch information
NoComment1105 and lukellmann committed Apr 4, 2023
1 parent 2937cbb commit f54fdab
Show file tree
Hide file tree
Showing 12 changed files with 655 additions and 8 deletions.
141 changes: 141 additions & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (ILdev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/util/List;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (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 <init> (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
Expand Down Expand Up @@ -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 <init> (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/OnboardingPromptType;Ljava/util/List;Ljava/lang/String;ZZZLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (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 <init> (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 <init> (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 <init> (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
Expand Down Expand Up @@ -7393,6 +7508,32 @@ public final class dev/kord/common/entity/NsfwLevel$Unknown : dev/kord/common/en
public fun <init> (I)V
}

public abstract class dev/kord/common/entity/OnboardingPromptType {
public static final field Companion Ldev/kord/common/entity/OnboardingPromptType$Companion;
public synthetic fun <init> (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 <init> (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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OnboardingPromptType> {
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<OnboardingPromptType> by lazy(mode = PUBLICATION) {
listOf(
MultipleChoice,
Dropdown,
)
}

}
}
45 changes: 45 additions & 0 deletions common/src/main/kotlin/entity/DiscordGuildOnboarding.kt
Original file line number Diff line number Diff line change
@@ -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<DiscordOnboardingPrompt>,
@SerialName("default_channel_ids") val defaultChannelIds: List<Snowflake>,
val enabled: Boolean,
)

@Serializable
public data class DiscordOnboardingPrompt(
val id: Snowflake,
val type: OnboardingPromptType,
val options: List<DiscordOnboardingPromptOption>,
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<Snowflake>,
@SerialName("role_ids") val roleIds: List<Snowflake>,
val emoji: DiscordEmoji,
val title: String,
val description: String?,
)
Loading

0 comments on commit f54fdab

Please sign in to comment.