Skip to content

Commit

Permalink
Compatibility for ActivityFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Aug 21, 2023
1 parent dc864dc commit 4d7ce33
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public final class dev/kord/common/entity/ActivityFlagKt {

public final class dev/kord/common/entity/ActivityFlags {
public static final field Companion Ldev/kord/common/entity/ActivityFlags$Companion;
public fun <init> (I)V
public final fun contains (Ldev/kord/common/entity/ActivityFlag;)Z
public final fun contains (Ldev/kord/common/entity/ActivityFlags;)Z
public final fun copy (Lkotlin/jvm/functions/Function1;)Ldev/kord/common/entity/ActivityFlags;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

Expand Down Expand Up @@ -47,14 +46,14 @@ public sealed class ActivityFlag(
* [flag].
*/
public operator fun plus(flag: ActivityFlag): ActivityFlags =
ActivityFlags(this.value or flag.value)
ActivityFlags(this.value or flag.value, null)

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in `this` and
* [flags].
*/
public operator fun plus(flags: ActivityFlags): ActivityFlags =
ActivityFlags(this.value or flags.value)
ActivityFlags(this.value or flags.value, null)

final override fun equals(other: Any?): Boolean = this === other ||
(other is ActivityFlag && this.shift == other.shift)
Expand Down Expand Up @@ -356,7 +355,18 @@ public class ActivityFlags internal constructor(
* The raw value used by Discord.
*/
public val `value`: Int,
@Suppress("UNUSED_PARAMETER") unused: Nothing?,
) {
// TODO uncomment annotation in DiscordActivity.kt and delete this file when this constructor is removed after
// deprecation cycle
@Deprecated(
"Don't construct an instance of 'ActivityFlags' from a raw value. Use the factory functions described in the " +
"documentation instead.",
ReplaceWith("ActivityFlags.Builder(value).build()", "dev.kord.common.entity.ActivityFlags"),
DeprecationLevel.WARNING,
)
public constructor(value: Int) : this(value, null)

/**
* A [Set] of all [ActivityFlag]s contained in this instance of [ActivityFlags].
*/
Expand Down Expand Up @@ -398,28 +408,28 @@ public class ActivityFlags internal constructor(
* [flag].
*/
public operator fun plus(flag: ActivityFlag): ActivityFlags =
ActivityFlags(this.value or flag.value)
ActivityFlags(this.value or flag.value, null)

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in `this` and
* [flags].
*/
public operator fun plus(flags: ActivityFlags): ActivityFlags =
ActivityFlags(this.value or flags.value)
ActivityFlags(this.value or flags.value, null)

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in `this` except
* the bits that are set in [flag].
*/
public operator fun minus(flag: ActivityFlag): ActivityFlags =
ActivityFlags(this.value and flag.value.inv())
ActivityFlags(this.value and flag.value.inv(), null)

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in `this` except
* the bits that are set in [flags].
*/
public operator fun minus(flags: ActivityFlags): ActivityFlags =
ActivityFlags(this.value and flags.value.inv())
ActivityFlags(this.value and flags.value.inv(), null)

/**
* Returns a copy of this instance of [ActivityFlags] modified with [builder].
Expand Down Expand Up @@ -471,7 +481,7 @@ public class ActivityFlags internal constructor(
* Returns an instance of [ActivityFlags] that has all bits set that are currently set in
* this [Builder].
*/
public fun build(): ActivityFlags = ActivityFlags(value)
public fun build(): ActivityFlags = ActivityFlags(value, null)

/**
* @suppress
Expand All @@ -494,7 +504,7 @@ public class ActivityFlags internal constructor(
}

override fun deserialize(decoder: Decoder): ActivityFlags =
ActivityFlags(decoder.decodeSerializableValue(delegate))
ActivityFlags(decoder.decodeSerializableValue(delegate), null)
}
}

Expand Down
5 changes: 3 additions & 2 deletions common/src/commonMain/kotlin/entity/DiscordActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
],
)

/*
@file:Generate(
INT_FLAGS, name = "ActivityFlag", wasEnum = true, hadFlagsProperty = true, flagsPropertyWasSet = true,
INT_FLAGS, name = "ActivityFlag",
docUrl = "https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-flags",
entries = [
Entry(name = "Instance", shift = 0),
Expand All @@ -26,6 +27,7 @@
Entry(name = "Embedded", shift = 8),
],
)
*/

package dev.kord.common.entity

Expand All @@ -34,7 +36,6 @@ import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.serialization.InstantInEpochMilliseconds
import dev.kord.ksp.Generate
import dev.kord.ksp.Generate.EntityType.INT_FLAGS
import dev.kord.ksp.Generate.EntityType.INT_KORD_ENUM
import dev.kord.ksp.Generate.Entry
import kotlinx.serialization.*
Expand Down

0 comments on commit 4d7ce33

Please sign in to comment.