Skip to content

Commit

Permalink
fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYusufIsmail committed Apr 4, 2024
1 parent a0ccb1b commit fbd0992
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 502 deletions.
3 changes: 2 additions & 1 deletion yde-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
api("uk.org.lidalia:sysout-over-slf4j:" + properties["sysoutOverSlf4jVersion"])

// Http
api("io.ktor:ktor-client-core-jvm:" + properties["ktorClientCoreJvmVersion"])
api("io.ktor:ktor-client-core-jvm:" + properties["ktorClientVersion"])
api("io.ktor:ktor-client-okhttp:" + properties["ktorClientVersion"])

// kotlin
api(
Expand Down
2 changes: 1 addition & 1 deletion yde-api/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jacksonModuleKotlinVersion = 2.16.1
logBackClassicVersion = 1.5.0
logBackCoreVersion = 1.5.0
sysoutOverSlf4jVersion = 1.0.2
ktorClientCoreJvmVersion = 3.0.0-beta-1
ktorClientVersion = 3.0.0-beta-1
kotlinxCoroutinesCoreVersion = 1.7.3
jsr305Version = 3.0.2
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import io.github.ydwk.yde.interaction.message.actionrow.ActionRowInteraction
import io.github.ydwk.yde.interaction.message.button.ButtonInteraction
import io.github.ydwk.yde.interaction.message.selectmenu.SelectMenuInteraction
import io.github.ydwk.yde.interaction.message.selectmenu.interaction.type.*
import io.github.ydwk.yde.interaction.message.textinput.TextInputInteraction
import io.github.ydwk.yde.util.GetterSnowFlake
import java.net.URL

Expand Down Expand Up @@ -723,6 +724,18 @@ interface EntityInstanceBuilder {
interactionId: GetterSnowFlake
): ChannelSelectMenuInteraction

/**
* Used to build an instance of [TextInputInteraction]
*
* @param json the json
* @param interactionId the interaction id
* @return [TextInputInteraction] the text input interaction
*/
fun buildTextInputInteraction(
json: JsonNode,
interactionId: GetterSnowFlake
): TextInputInteraction

// Application Command entities

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package io.github.ydwk.yde.interaction.application.sub

import io.github.ydwk.yde.entities.interaction.Component
import io.github.ydwk.yde.entities.interaction.actionrow.ActionRow
import io.github.ydwk.yde.entities.interaction.actionrow.creator.ActionRowCreator
import io.github.ydwk.yde.entities.message.MessageFlag
import io.github.ydwk.yde.rest.RestResult
import io.github.ydwk.yde.rest.result.NoResult
Expand Down Expand Up @@ -60,12 +60,12 @@ interface Reply {
fun addFlags(flags: List<MessageFlag>): Reply

/**
* Adds an [ActionRow] to the reply.
* Adds an [ActionRow] to the reply. Use [ActionRowCreator] to create an [ActionRow].
*
* @param actionRow The [ActionRow] to add.
* @return The [Reply] instance.
*/
fun addActionRow(actionRow: Component.ComponentCreator): Reply
fun addActionRow(actionRow: ActionRow): Reply

/**
* Triggers the reply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import io.github.ydwk.yde.interaction.message.actionrow.ActionRowInteraction
import io.github.ydwk.yde.interaction.message.button.ButtonInteraction
import io.github.ydwk.yde.interaction.message.selectmenu.SelectMenuInteraction
import io.github.ydwk.yde.interaction.message.selectmenu.interaction.type.*
import io.github.ydwk.yde.interaction.message.textinput.TextInputInteraction
import io.github.ydwk.yde.interaction.sub.InteractionType
import io.github.ydwk.yde.rest.error.RestAPIException
import io.github.ydwk.yde.util.*
Expand Down Expand Up @@ -384,9 +385,12 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
else null,
json["bot_public"].asBoolean(),
json["bot_require_code_grant"].asBoolean(),
if (json.has("terms_of_service_url")) URL(json["terms_of_service_url"].asText())
if (json.has("terms_of_service_url"))
@Suppress("DEPRECATION") URL(json["terms_of_service_url"].asText())
else null,
if (json.has("privacy_policy_url"))
@Suppress("DEPRECATION") URL(json["privacy_policy_url"].asText())
else null,
if (json.has("privacy_policy_url")) URL(json["privacy_policy_url"].asText()) else null,
if (json.has("owner")) buildUser(json["owner"]) else null,
if (json.has("verify_key")) json["verify_key"].asText() else null,
if (json.has("guild_id")) yde.getGuildById(json["guild_id"].asLong()) else null,
Expand Down Expand Up @@ -797,7 +801,7 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
if (json.has("title")) json["title"].asText() else null,
if (json.has("type")) EmbedType.getValue(json["type"].asText()) else null,
if (json.has("description")) json["description"].asText() else null,
if (json.has("url")) URL(json["url"].asText()) else null,
if (json.has("url")) @Suppress("DEPRECATION") URL(json["url"].asText()) else null,
if (json.has("timestamp")) json["timestamp"].asText() else null,
if (json.has("color")) Color(json["color"].asInt()) else null,
if (json.has("footer")) buildFooter(json["footer"]) else null,
Expand All @@ -816,8 +820,8 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
json["id"].asLong(),
if (json.has("description")) json["description"].asText() else null,
if (json.has("media_type")) json["media_type"].asText() else null,
URL(json["url"].asText()),
URL(json["proxy_url"].asText()),
@Suppress("DEPRECATION") URL(json["url"].asText()),
@Suppress("DEPRECATION") URL(json["proxy_url"].asText()),
json["size"].asInt(),
if (json.has("height")) json["height"].asInt() else null,
if (json.has("width")) json["width"].asInt() else null,
Expand All @@ -844,15 +848,15 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
}

override fun buildPartialEmoji(json: JsonNode): PartialEmoji {
return TODO()
TODO("Not yet implemented")
}

override fun buildAuthor(json: JsonNode): Author {
return AuthorImpl(
yde,
json,
json["name"].asText(),
if (json.has("url")) URL(json["url"].asText()) else null,
if (json.has("url")) @Suppress("DEPRECATION") URL(json["url"].asText()) else null,
if (json.has("icon_url")) json["icon_url"].asText() else null,
if (json.has("proxy_icon_url")) json["proxy_icon_url"].asText() else null)
}
Expand All @@ -879,8 +883,9 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
return ImageImpl(
yde,
json,
URL(json["url"].asText()),
if (json.has("proxy_url")) URL(json["proxy_url"].asText()) else null,
@Suppress("DEPRECATION") URL(json["url"].asText()),
if (json.has("proxy_url")) @Suppress("DEPRECATION") URL(json["proxy_url"].asText())
else null,
if (json.has("height")) json["height"].asInt() else null,
if (json.has("width")) json["width"].asInt() else null)
}
Expand All @@ -897,7 +902,7 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
return ThumbnailImpl(
yde,
json,
URL(json["url"].asText()),
@Suppress("DEPRECATION") URL(json["url"].asText()),
if (json.has("proxy_url")) json["proxy_url"].asText() else null,
if (json.has("height")) json["height"].asInt() else null,
if (json.has("width")) json["width"].asInt() else null)
Expand All @@ -907,7 +912,7 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
return VideoImpl(
yde,
json,
URL(json["url"].asText()),
@Suppress("DEPRECATION") URL(json["url"].asText()),
if (json.has("proxy_url")) json["proxy_url"].asText() else null,
if (json.has("height")) json["height"].asInt() else null,
if (json.has("width")) json["width"].asInt() else null)
Expand Down Expand Up @@ -1090,6 +1095,13 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
TODO("Not yet implemented")
}

override fun buildTextInputInteraction(
json: JsonNode,
interactionId: GetterSnowFlake
): TextInputInteraction {
TODO("Not yet implemented")
}

override fun buildApplicationCommand(json: JsonNode): ApplicationCommand {
TODO("Not yet implemented")
}
Expand All @@ -1103,31 +1115,18 @@ class EntityInstanceBuilderImpl(val yde: YDEImpl) : EntityInstanceBuilder {
val user = buildUser(json["data"]["resolved"]["users"])

return UserCommandImpl(
yde,
json,
json["id"].asLong(),
i,
user,
buildMember(json["data"]["resolved"]["members"], i.guild!!, user))
yde, json, i, user, buildMember(json["data"]["resolved"]["members"], i.guild!!, user))
}

override fun buildSlashCommand(json: JsonNode, interaction: Interaction?): SlashCommand {
return SlashCommandImpl(
yde, json, json["id"].asLong(), interaction ?: buildInteraction(json))
return SlashCommandImpl(yde, json, interaction ?: buildInteraction(json))
}

override fun buildMessageCommand(json: JsonNode, interaction: Interaction?): MessageCommand {
return MessageCommandImpl(
yde,
json,
json["id"].asLong(),
interaction ?: buildInteraction(json),
buildMessage(json["data"]["resolved"]["messages"]))
}

// infix fun Int.test(bitCount: Int): Long {
// return this.toLong() shl bitCount
// }

// val permissions = 5 test 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,30 @@ abstract class ApplicationCommandImpl(
override val token: String,
override val message: Message?,
override val permissions: Long?,
) : ApplicationCommand, ToStringEntityImpl<ApplicationCommand>(yde, ApplicationCommand::class.java)
) :
ApplicationCommand,
ToStringEntityImpl<ApplicationCommand>(yde, ApplicationCommand::class.java) {
constructor(
applicationCommand: ApplicationCommand,
interaction: Interaction
) : this(
applicationCommand.yde,
applicationCommand.json,
applicationCommand.idAsLong,
interaction,
applicationCommand.applicationId,
applicationCommand.guild,
applicationCommand.name,
applicationCommand.description,
applicationCommand.isDmPermissions,
applicationCommand.isNsfw,
applicationCommand.version,
applicationCommand.targetId,
applicationCommand.user,
applicationCommand.member,
applicationCommand.interactionType,
applicationCommand.channel,
applicationCommand.token,
applicationCommand.message,
applicationCommand.permissions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package io.github.ydwk.yde.impl.interaction.application.sub
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ArrayNode
import io.github.ydwk.yde.YDE
import io.github.ydwk.yde.entities.interaction.Component
import io.github.ydwk.yde.entities.interaction.actionrow.ActionRow
import io.github.ydwk.yde.entities.message.Embed
import io.github.ydwk.yde.entities.message.MessageFlag
import io.github.ydwk.yde.interaction.application.sub.Reply
Expand All @@ -40,7 +40,7 @@ internal class ReplyImpl(
) : Reply {
private var isEphemeral: Boolean = false
private var isTTS: Boolean = false
private var actionRows = mutableListOf<Component.ComponentCreator>()
private var actionRows = mutableListOf<ActionRow>()
private var flags = mutableListOf<MessageFlag>()

override fun setEphemeral(isEphemeral: Boolean): Reply {
Expand All @@ -63,7 +63,7 @@ internal class ReplyImpl(
return this
}

override fun addActionRow(actionRow: Component.ComponentCreator): Reply {
override fun addActionRow(actionRow: ActionRow): Reply {
actionRows.add(actionRow)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import io.github.ydwk.yde.interaction.application.type.MessageCommand
class MessageCommandImpl(
yde: YDE,
json: JsonNode,
idAsLong: Long,
interaction: Interaction,
override val targetMessage: Message
) : ApplicationCommandImpl(yde, json, idAsLong, interaction), MessageCommand {
) :
ApplicationCommandImpl(yde.entityInstanceBuilder.buildApplicationCommand(json), interaction),
MessageCommand {
override fun reply(content: String): Reply {
return ReplyImpl(yde, content, null, interaction.id, token)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import io.github.ydwk.yde.entities.message.Embed
import io.github.ydwk.yde.entities.util.GenericEntity
import io.github.ydwk.yde.impl.YDEImpl
import io.github.ydwk.yde.impl.interaction.application.ApplicationCommandImpl
import io.github.ydwk.yde.impl.interaction.application.ApplicationCommandOptionImpl
import io.github.ydwk.yde.impl.interaction.application.sub.ReplyImpl
import io.github.ydwk.yde.interaction.Interaction
import io.github.ydwk.yde.interaction.application.sub.Reply
import io.github.ydwk.yde.interaction.application.type.SlashCommand
import io.github.ydwk.yde.util.EntityToStringBuilder

class SlashCommandImpl(yde: YDE, json: JsonNode, idAsLong: Long, interaction: Interaction) :
ApplicationCommandImpl(yde, json, idAsLong, interaction), SlashCommand {
/** TODO: have a look at the [SlashCommandImpl] to see if it is possible to refactor the code */
class SlashCommandImpl(yde: YDE, json: JsonNode, interaction: Interaction) :
ApplicationCommandImpl(yde.entityInstanceBuilder.buildApplicationCommand(json), interaction),
SlashCommand {

override val locale: String? = interaction.locale

Expand Down Expand Up @@ -116,7 +117,7 @@ class SlashCommandImpl(yde: YDE, json: JsonNode, idAsLong: Long, interaction: In
val list: MutableList<SlashOptionGetter> = mutableListOf()

options?.forEach { node ->
val option = ApplicationCommandOptionImpl(yde, node)
val option = yde.entityInstanceBuilder.buildApplicationCommandOption(node)
list.add(SlashOptionGetterImpl(option, map))
}
?: return emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import io.github.ydwk.yde.interaction.application.type.UserCommand
class UserCommandImpl(
yde: YDE,
json: JsonNode,
idAsLong: Long,
interaction: Interaction,
override val targetUser: User,
override val targetMember: Member
) : ApplicationCommandImpl(yde, json, idAsLong, interaction), UserCommand {
) :
ApplicationCommandImpl(yde.entityInstanceBuilder.buildApplicationCommand(json), interaction),
UserCommand {
override fun reply(content: String): Reply {
return ReplyImpl(yde, content, null, interaction.id, token)
}
Expand Down
1 change: 1 addition & 0 deletions ydwk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {

// guava
api("com.google.guava:guava:" + properties["guavaVersion"])
implementation("io.ktor:ktor-client-okhttp-jvm:3.0.0-beta-1")

// test
testImplementation("org.jetbrains.kotlin:kotlin-test:" + properties["kotlinTestVersion"])
Expand Down
7 changes: 5 additions & 2 deletions ydwk/src/main/kotlin/io/github/ydwk/ydwk/BotBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import io.github.ydwk.yde.cache.CacheIds
import io.github.ydwk.yde.util.exception.LoginException
import io.github.ydwk.ydwk.impl.YDWKImpl
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import kotlinx.coroutines.CoroutineDispatcher

internal class BotBuilder
private constructor(
private val token: String,
private val httpClient: HttpClient = HttpClient(),
private val httpClient: HttpClient = HttpClient(OkHttp),
private val intents: List<GateWayIntent> = GateWayIntent.getDefaultIntents(),
private val allowedCache: Set<CacheIds> = CacheIds.getDefaultCache(),
private val disallowedCache: Set<CacheIds> = emptySet(),
Expand Down Expand Up @@ -135,7 +136,9 @@ private constructor(
ydwk.setWebSocketManager(token, intents, userStatus, activity, etfInsteadOfJson)
ydwk.setAllowedCache(allowedCache)
ydwk.setDisallowedCache(disallowedCache)
ydwk.enableShutDownHook()
if (enableShutDownHook) {
ydwk.enableShutDownHook()
}
dispatcher?.let { ydwk.coroutineDispatcher = it }
return ydwk
}
Expand Down
14 changes: 1 addition & 13 deletions ydwk/src/main/kotlin/io/github/ydwk/ydwk/YDWKInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@ enum class YDWKInfo(private val url: String) {
JSON_ENCODING("&encoding=json"),
VOICE_GATEWAY_VERSION("/?v=4"),
GITHUB_URL("https://github.com/ydwk/ydwk"),
YDWK_VERSION("2.0.0");

companion object {
/**
* Get the full discord gateway url.
*
* @param info The [YDWKInfo] to get the full url from.
* @return The full discord gateway url.
*/
fun fromString(info: YDWKInfo): String {
return info.url
}
}
YDWK_VERSION("2.0.0.alpha.1");

/**
* The url of the [YDWKInfo].
Expand Down
Loading

0 comments on commit fbd0992

Please sign in to comment.