Skip to content

Commit

Permalink
✨ some yiski4 stuff + unfinished osu command
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Sep 11, 2024
1 parent c2dd54e commit 731baed
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 11 deletions.
14 changes: 12 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ jda-ktx = { module = "club.minnced:jda-ktx", version.ref = "jda-ktx" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-cio-jvm = { module = "io.ktor:ktor-client-cio-jvm", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" }
ktor-server-cio = { module = "io.ktor:ktor-server-cio-jvm", version.ref = "ktor" }
ktor-server-config-yaml = { module = "io.ktor:ktor-server-config-yaml", version.ref = "ktor" }
ktor-server-content-negogiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
# Ktoml
ktoml-core = { module = "com.akuleshov7:ktoml-core", version.ref = "ktoml" }
ktoml-file = { module = "com.akuleshov7:ktoml-file", version.ref = "ktoml" }
Expand Down Expand Up @@ -106,13 +109,20 @@ kotlinx = [
"kotlinx-coroutines-core",
"kotlinx-serialization-json"
]
ktor = [
ktor-universal = [
"ktor-serialization-kotlinx-json"
]
ktor-client = [
"ktor-client-core",
"ktor-client-cio",
"ktor-client-cio-jvm",
"ktor-client-content-negotiation"
]
ktor-server = [
"ktor-server-core",
"ktor-server-cio",
"ktor-server-config-yaml"
"ktor-server-config-yaml",
"ktor-server-content-negogiation"
]
ktoml = [
"ktoml-core",
Expand Down
4 changes: 3 additions & 1 deletion yiski-dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ dependencies {
}

api(rootProject.libs.slf4j.api)
api(rootProject.libs.bundles.ktor)
api(rootProject.libs.bundles.ktor.universal)
api(rootProject.libs.bundles.ktor.client)
api(rootProject.libs.bundles.ktor.server)
api(rootProject.libs.bundles.ktoml)
api(rootProject.libs.bundles.kotlin)
api(rootProject.libs.bundles.kotlinx)
Expand Down
3 changes: 3 additions & 0 deletions yiski3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dependencies {

implementation(rootProject.libs.okhttp)
shade(rootProject.libs.okhttp)

implementation(files("libs/osu4j-2.0.1.jar"))
shade(files("libs/osu4j-2.0.1.jar"))
}

kotlin {
Expand Down
Binary file added yiski3/libs/osu4j-2.0.1.jar
Binary file not shown.
186 changes: 186 additions & 0 deletions yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Osu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package one.devos.yiski3.commands.silly

import com.oopsjpeg.osu4j.GameMode
import com.oopsjpeg.osu4j.backend.EndpointUsers
import com.oopsjpeg.osu4j.backend.Osu
import com.oopsjpeg.osu4j.exception.OsuAPIException
import dev.minn.jda.ktx.coroutines.await
import dev.minn.jda.ktx.messages.Embed
import one.devos.yiski.common.annotations.YiskiModule
import one.devos.yiski.common.utils.EmbedHelpers
import one.devos.yiski.common.utils.EmbedHelpers.videoUpload
import one.devos.yiski3.Yiski3
import xyz.artrinix.aviation.command.slash.SlashContext
import xyz.artrinix.aviation.command.slash.annotations.Description
import xyz.artrinix.aviation.command.slash.annotations.SlashCommand
import xyz.artrinix.aviation.command.slash.annotations.SlashSubCommand
import xyz.artrinix.aviation.entities.Scaffold

@YiskiModule
@SlashCommand(name = "osu", description = "View some basic osu! stats")
class Osu : Scaffold {
@SlashSubCommand("View information about an osu! player on Standard mode")
suspend fun playerStandard(ctx: SlashContext, @Description("Username of said osu! player") player: String) {
val response = ctx.interaction.deferReply().await()

val osu: Osu = Osu.getAPI(Yiski3.config.apiKeys.osu)
val user = osu.users.query(EndpointUsers.ArgumentsBuilder(player).setMode(GameMode.STANDARD).build())

try {
response.editOriginalEmbeds(Embed {
title = "Osu! data for ${user.username} - ${user.id} - osu! mode"
description = user.url.toString()
field("Rank", "#${user.rank}", true)
field("Country Rank", "#${user.countryRank}", true)
field("Ranked Score", "%,d".format(user.rankedScore), true)
field("Hit Accuracy", user.accuracy.toString(), true)
field("Play Count", user.playCount.toString(), true)
field("Total Score", "%,d".format(user.totalScore), true)
field("Total Hits", user.totalHits.toString(), true)
field("PP (performance points)", user.pp.toString(), true)
field(
"SS-A Scores", """
SSH: ${user.countRankSSH}
SS: ${user.countRankSS}
SH: ${user.countRankSH}
S: ${user.countRankS}
A: ${user.countRankA}
`*H - Hidden/Flashlight Mod`
""".trimIndent()
)
color = EmbedHelpers.infoColor()
}).await()
} catch (e: OsuAPIException) {
response.editOriginalEmbeds(Embed {
title = "ruh roh"
description = "Failed to get osu! data for this player, ${e.message}"
color = EmbedHelpers.failColor()
}).await()
ctx.channel.sendFiles(videoUpload(Yiski3.config.videos.osufailscreen)).await()
}
}

@SlashSubCommand("View information about an osu! player on Taiko mode")
suspend fun playerTaiko(ctx: SlashContext, @Description("Username of said osu! player") player: String) {
val response = ctx.interaction.deferReply().await()

val osu: Osu = Osu.getAPI(Yiski3.config.apiKeys.osu)
val user = osu.users.query(EndpointUsers.ArgumentsBuilder(player).setMode(GameMode.TAIKO).build())

try {
response.editOriginalEmbeds(Embed {
title = "Osu! data for ${user.username} - ${user.id} - osu!taiko mode"
description = user.url.toString()
field("Rank", "#${user.rank}", true)
field("Country Rank", "#${user.countryRank}", true)
field("Ranked Score", "%,d".format(user.rankedScore), true)
field("Hit Accuracy", user.accuracy.toString(), true)
field("Play Count", user.playCount.toString(), true)
field("Total Score", "%,d".format(user.totalScore), true)
field("Total Hits", user.totalHits.toString(), true)
field("PP (performance points)", user.pp.toString(), true)
field(
"SS-A Scores", """
SSH: ${user.countRankSSH}
SS: ${user.countRankSS}
SH: ${user.countRankSH}
S: ${user.countRankS}
A: ${user.countRankA}
`*H - Hidden/Flashlight Mod`
""".trimIndent()
)
color = EmbedHelpers.infoColor()
}).await()
} catch (e: OsuAPIException) {
response.editOriginalEmbeds(Embed {
title = "ruh roh"
description = "Failed to get osu! data for this player, ${e.message}"
color = EmbedHelpers.failColor()
}).await()
}
}

@SlashSubCommand("View information about an osu! player on Mania mode")
suspend fun playerMania(ctx: SlashContext, @Description("Username of said osu! player") player: String) {
val response = ctx.interaction.deferReply().await()

val osu: Osu = Osu.getAPI(Yiski3.config.apiKeys.osu)
val user = osu.users.query(EndpointUsers.ArgumentsBuilder(player).setMode(GameMode.MANIA).build())

try {
response.editOriginalEmbeds(Embed {
title = "Osu! data for ${user.username} - ${user.id} - osu!mania mode"
description = user.url.toString()
field("Rank", "#${user.rank}", true)
field("Country Rank", "#${user.countryRank}", true)
field("Ranked Score", "%,d".format(user.rankedScore), true)
field("Hit Accuracy", user.accuracy.toString(), true)
field("Play Count", user.playCount.toString(), true)
field("Total Score", "%,d".format(user.totalScore), true)
field("Total Hits", user.totalHits.toString(), true)
field("PP (performance points)", user.pp.toString(), true)
field(
"SS-A Scores", """
SSH: ${user.countRankSSH}
SS: ${user.countRankSS}
SH: ${user.countRankSH}
S: ${user.countRankS}
A: ${user.countRankA}
`*H - Hidden/Flashlight Mod`
""".trimIndent()
)
color = EmbedHelpers.infoColor()
}).await()
} catch (e: OsuAPIException) {
response.editOriginalEmbeds(Embed {
title = "ruh roh"
description = "Failed to get osu! data for this player, ${e.message}"
color = EmbedHelpers.failColor()
}).await()
}
}

@SlashSubCommand("View information about an osu! player on Catch mode")
suspend fun playerCatch(ctx: SlashContext, @Description("Username of said osu! player") player: String) {
val response = ctx.interaction.deferReply().await()

val osu: Osu = Osu.getAPI(Yiski3.config.apiKeys.osu)
val user = osu.users.query(EndpointUsers.ArgumentsBuilder(player).setMode(GameMode.CATCH_THE_BEAT).build())

try {
response.editOriginalEmbeds(Embed {
title = "Osu! data for ${user.username} - ${user.id} - osu!catch mode"
description = user.url.toString()
field("Rank", "#${user.rank}", true)
field("Country Rank", "#${user.countryRank}", true)
field("Ranked Score", "%,d".format(user.rankedScore), true)
field("Hit Accuracy", user.accuracy.toString(), true)
field("Play Count", user.playCount.toString(), true)
field("Total Score", "%,d".format(user.totalScore), true)
field("Total Hits", user.totalHits.toString(), true)
field("PP (performance points)", user.pp.toString(), true)
field(
"SS-A Scores", """
SSH: ${user.countRankSSH}
SS: ${user.countRankSS}
SH: ${user.countRankSH}
S: ${user.countRankS}
A: ${user.countRankA}
`*H - Hidden/Flashlight Mod`
""".trimIndent()
)
color = EmbedHelpers.infoColor()
}).await()
} catch (e: OsuAPIException) {
response.editOriginalEmbeds(Embed {
title = "ruh roh"
description = "Failed to get osu! data for this player, ${e.message}"
color = EmbedHelpers.failColor()
}).await()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package one.devos.yiski3.commands.headcrab
package one.devos.yiski3.commands.silly.headcrab

import dev.minn.jda.ktx.coroutines.await
import dev.minn.jda.ktx.messages.Embed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import one.devos.yiski.common.AbstractYiskiConfig
@Serializable
data class Yiski3ConfigData(
val images: ImageConfig,
val videos: VideosConfig
val videos: VideosConfig,
val apiKeys: ApiKeysConfig
) : AbstractYiskiConfig {
@Serializable
data class ImageConfig(
Expand All @@ -26,6 +27,12 @@ data class Yiski3ConfigData(
val memoryleak: String,
val rtx: String,
val whatareyoudoing: String,
val osufailscreen: String
)

@Serializable
data class ApiKeysConfig(
val osu: String
)
}

Expand Down
Binary file not shown.
13 changes: 11 additions & 2 deletions yiski4/src/main/kotlin/one/devos/yiski4/Yiski4.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package one.devos.yiski4

import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import net.dv8tion.jda.api.JDA
import one.devos.yiski.common.AbstractYiskiConfig
import one.devos.yiski.common.annotations.YiskiModule
import one.devos.yiski.common.database.DatabaseManager
import one.devos.yiski.common.entrypoints.YiskiModuleEntrypoint
import one.devos.yiski4.data.Yiski4ConfigData
import xyz.artrinix.aviation.Aviation

val logger = KotlinLogging.logger { }
Expand All @@ -15,16 +20,20 @@ class Yiski4(
// Change these to vals if they're needed!
database: DatabaseManager,
aviation: Aviation,
jda: JDA
jda: JDA,
private val config: Yiski4ConfigData
) : YiskiModuleEntrypoint(
database,
aviation,
jda,
object : AbstractYiskiConfig {}
config
) {
companion object {
lateinit var instance: Yiski4
private set

val config: Yiski4ConfigData
get() = instance.config
}

init {
Expand Down
39 changes: 39 additions & 0 deletions yiski4/src/main/kotlin/one/devos/yiski4/Yiski4Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package one.devos.yiski4

import kotlinx.serialization.serializer
import one.devos.yiski.common.annotations.YiskiModule
import one.devos.yiski.common.entrypoints.ConfigSetupEntrypoint
import one.devos.yiski.utils.TomlReader
import one.devos.yiski4.data.Yiski4ConfigData
import kotlin.system.exitProcess

@YiskiModule
class Yiski4Config : ConfigSetupEntrypoint {

private val configPath = System.getProperty("yiski4_config", "yiski4.config.toml")

override lateinit var config: Yiski4ConfigData

override fun read() {
config = try {
logger.info { "Attemping to load config" }
TomlReader.decodeFromFile(serializer(), configPath)
} catch (e: Exception) {
logger.error {
"""
#######################################################
# #
# oopsies woopsies we did a wittle fwucky wucky #
# #
#######################################################
""".trimIndent()
e
}
exitProcess(1)
}
}

}
Loading

0 comments on commit 731baed

Please sign in to comment.