io.github.ydwk.ydwk.impl.entities.guild.InviteImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydwk Show documentation
Show all versions of ydwk Show documentation
YDWK (Yusuf's Discord Wrapper Kotlin) My own Discord Wrapper in Kotlin
/*
* Copyright 2022 YDWK inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ydwk.ydwk.impl.entities.guild
import com.fasterxml.jackson.databind.JsonNode
import io.github.ydwk.ydwk.YDWK
import io.github.ydwk.ydwk.entities.Application
import io.github.ydwk.ydwk.entities.Guild
import io.github.ydwk.ydwk.entities.User
import io.github.ydwk.ydwk.entities.channel.GuildChannel
import io.github.ydwk.ydwk.entities.guild.GuildScheduledEvent
import io.github.ydwk.ydwk.entities.guild.Invite
import io.github.ydwk.ydwk.entities.guild.invite.TargetType
import io.github.ydwk.ydwk.impl.entities.ApplicationImpl
import io.github.ydwk.ydwk.impl.entities.UserImpl
import io.github.ydwk.ydwk.util.EntityToStringBuilder
import java.time.ZonedDateTime
class InviteImpl(override val ydwk: YDWK, override val json: JsonNode) : Invite {
override val code: String
get() = json["code"].asText()
override val guild: Guild
get() =
ydwk.getGuildById(json["guild"]["id"].asText())
?: throw IllegalStateException("Guild is null")
override val channel: GuildChannel
get() =
ydwk.getGuildChannelById(json["channel"]["id"].asText())
?: throw IllegalStateException("Channel is null")
override val inviter: User?
get() =
if (json["inviter"] != null)
UserImpl(json["inviter"], json["inviter"]["id"].asLong(), ydwk)
else null
override val targetType: TargetType
get() = TargetType.fromValue(json["target_type"].asInt())
override val targetUser: User?
get() =
if (json["target_user"] != null)
UserImpl(json["target_user"], json["target_user"]["id"].asLong(), ydwk)
else null
override val targetApplication: Application?
get() =
if (json["target_application"] != null)
ApplicationImpl(
json["target_application"], json["target_application"]["id"].asLong(), ydwk)
else null
override val approximatePresenceCount: Int
get() = json["approximate_presence_count"].asInt()
override val approximateMemberCount: Int
get() = json["approximate_member_count"].asInt()
override val expirationDate: ZonedDateTime
get() = ZonedDateTime.parse(json["expires_at"].asText())
override val guildScheduledEvent: GuildScheduledEvent
get() =
GuildScheduledEventImpl(
ydwk, json["guild_scheduled_event"], json["guild_scheduled_event"]["id"].asLong())
override fun toString(): String {
return EntityToStringBuilder(ydwk, this).toString()
}
}