Skip to content

Commit

Permalink
Change type of DiscordGuildBan.guildId from String to Snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Aug 30, 2021
1 parent 1f5d807 commit d109712
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
17 changes: 9 additions & 8 deletions common/src/main/kotlin/entity/DiscordGuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ data class DiscordGuild(
@SerialName("welcome_screen")
val welcomeScreen: Optional<DiscordWelcomeScreen> = Optional.Missing(),
@SerialName("nsfw_level")
val nsfwLevel: NsfwLevel
)
val nsfwLevel: NsfwLevel,
)

/**
* A partial representation of a [Discord Guild structure](https://discord.com/developers/docs/resources/guild#guild-object
Expand All @@ -176,7 +176,7 @@ class DiscordPartialGuild(
val permissions: Optional<Permissions> = Optional.Missing(),
val features: List<GuildFeature>,
@SerialName("welcome_screen")
val welcomeScreen: Optional<DiscordWelcomeScreen> = Optional.Missing()
val welcomeScreen: Optional<DiscordWelcomeScreen> = Optional.Missing(),
)

/**
Expand Down Expand Up @@ -242,7 +242,7 @@ sealed class GuildFeature(val value: String) {

/** Guild has access to the seven day archive time for threads */
object SevenDayThreadArchive : GuildFeature("SEVEN_DAY_THREAD_ARCHIVE")

/** Guild has access to create private threads */
object PrivateThreads : GuildFeature("PRIVATE_THREADS")

Expand Down Expand Up @@ -320,7 +320,7 @@ enum class SystemChannelFlag(val code: Int) {
@Serializable
data class DiscordGuildBan(
@SerialName("guild_id")
val guildId: String,
val guildId: Snowflake,
val user: DiscordUser,
)

Expand Down Expand Up @@ -402,7 +402,7 @@ data class DiscordVoiceState(
val selfStream: OptionalBoolean = OptionalBoolean.Missing,
val suppress: Boolean,
@SerialName("request_to_speak_timestamp")
val requestToSpeakTimestamp: String?
val requestToSpeakTimestamp: String?,
)

/**
Expand Down Expand Up @@ -526,6 +526,7 @@ sealed class MFALevel(val value: Int) {
}
}
}

/**
* A representation of a [Discord Guild NSFW Level](https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level).
*/
Expand Down Expand Up @@ -613,12 +614,12 @@ data class DiscordWelcomeScreenChannel(
@SerialName("emoji_id")
val emojiId: Snowflake?,
@SerialName("emoji_name")
val emojiName: String?
val emojiName: String?,
)

@Serializable
data class DiscordWelcomeScreen(
val description: String?,
@SerialName("welcome_channels")
val welcomeChannels: List<DiscordWelcomeScreenChannel>
val welcomeChannels: List<DiscordWelcomeScreenChannel>,
)
9 changes: 4 additions & 5 deletions core/src/main/kotlin/gateway/handler/GuildEventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class GuildEventHandler(
kord: Kord,
gateway: MasterGateway,
cache: DataCache,
coreFlow: MutableSharedFlow<CoreEvent>
coreFlow: MutableSharedFlow<CoreEvent>,
) : BaseGatewayEventHandler(kord, gateway, cache, coreFlow) {

override suspend fun handle(event: Event, shard: Int) = when (event) {
Expand Down Expand Up @@ -107,15 +107,15 @@ internal class GuildEventHandler(
cache.put(user)
val user = User(data, kord)

coreFlow.emit(BanAddEvent(user, Snowflake(guildId), shard))
coreFlow.emit(BanAddEvent(user, guildId, shard))
}

private suspend fun handle(event: GuildBanRemove, shard: Int) = with(event.ban) {
val data = UserData.from(user)
cache.put(user)
val user = User(data, kord)

coreFlow.emit(BanRemoveEvent(user, Snowflake(guildId), shard))
coreFlow.emit(BanRemoveEvent(user, guildId, shard))
}

private suspend fun handle(event: GuildEmojisUpdate, shard: Int) = with(event.emoji) {
Expand Down Expand Up @@ -243,5 +243,4 @@ internal class GuildEventHandler(
val data = InviteDeleteData.from(invite)
coreFlow.emit(InviteDeleteEvent(data, kord, shard))
}

}
}
6 changes: 3 additions & 3 deletions core/src/test/kotlin/live/LiveGuildTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class LiveGuildTest : AbstractLiveEntityTest<LiveGuild>() {
sendEventValidAndRandomId(guildId) {
GuildBanAdd(
DiscordGuildBan(
guildId = it.asString,
guildId = it,
user = DiscordUser(
id = randomId(),
username = "",
Expand All @@ -129,7 +129,7 @@ class LiveGuildTest : AbstractLiveEntityTest<LiveGuild>() {
sendEventValidAndRandomId(guildId) {
GuildBanRemove(
DiscordGuildBan(
guildId = it.asString,
guildId = it,
user = DiscordUser(
id = randomId(),
username = "",
Expand Down Expand Up @@ -779,4 +779,4 @@ class LiveGuildTest : AbstractLiveEntityTest<LiveGuild>() {
}
}
}
}
}
4 changes: 2 additions & 2 deletions core/src/test/kotlin/live/LiveKordEntityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LiveKordEntityTest : AbstractLiveEntityTest<LiveKordEntityTest.LiveEntityM

val eventGuildBan = GuildBanAdd(
DiscordGuildBan(
guildId = guildId.asString,
guildId = guildId,
user = DiscordUser(
id = randomId(),
username = "",
Expand Down Expand Up @@ -174,4 +174,4 @@ class LiveKordEntityTest : AbstractLiveEntityTest<LiveKordEntityTest.LiveEntityM

kord = createKord()
}
}
}
4 changes: 2 additions & 2 deletions core/src/test/kotlin/live/LiveMemberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class LiveMemberTest : AbstractLiveEntityTest<LiveMember>() {
sendEventValidAndRandomIdCheckLiveActive(userId) {
GuildBanAdd(
DiscordGuildBan(
guildId = randomId().asString,
guildId = randomId(),
user = DiscordUser(
id = it,
username = "",
Expand Down Expand Up @@ -162,4 +162,4 @@ class LiveMemberTest : AbstractLiveEntityTest<LiveMember>() {
}
}
}
}
}

0 comments on commit d109712

Please sign in to comment.