mirror of
https://github.com/noobnuby/Notification-Bot.git
synced 2024-11-26 05:13:05 +00:00
chlwjrghk rnlcksgdk
This commit is contained in:
parent
8f3681e004
commit
0ce15945f4
8 changed files with 114 additions and 20 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,6 +5,7 @@ build/
|
|||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
|
|
|
@ -9,17 +9,16 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
//tasks {
|
||||
// shadowJar {
|
||||
// archiveBaseName.set(rootProject.name)
|
||||
// archiveClassifier.set("")
|
||||
// archiveVersion.set("")
|
||||
//
|
||||
// manifest {
|
||||
// attributes["Main-Class"] = "com.noobnuby.plugin.MainKt"
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
tasks {
|
||||
shadowJar {
|
||||
doLast {
|
||||
copy {
|
||||
from(archiveFile)
|
||||
into(File("C:\\Users\\user\\Desktop\\px32\\plugins"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.noobnuby.plugin
|
||||
|
||||
import com.noobnuby.plugin.command.Steam
|
||||
import com.noobnuby.plugin.handler.ButtonClick
|
||||
import net.projecttl.p.x32.api.Plugin
|
||||
import net.projecttl.p.x32.api.command.commandHandler
|
||||
|
||||
|
@ -9,7 +10,7 @@ class Main : Plugin() {
|
|||
|
||||
logger.info("Enable Steam plugin!")
|
||||
|
||||
// addHandler(Ready)
|
||||
addHandler(ButtonClick)
|
||||
addHandler(commandHandler { handler ->
|
||||
handler.addCommand(Steam)
|
||||
})
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package com.noobnuby.plugin.command
|
||||
|
||||
import com.noobnuby.plugin.data.ButtonState
|
||||
import com.noobnuby.plugin.data.SteamSaleData
|
||||
import com.noobnuby.plugin.handler.ButtonClick
|
||||
import com.noobnuby.plugin.service.SteamApiService
|
||||
import com.noobnuby.plugin.util.formatWon
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.dv8tion.jda.api.EmbedBuilder
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed
|
||||
import net.dv8tion.jda.api.entities.User
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
||||
import net.projecttl.p.x32.api.command.GlobalCommand
|
||||
import net.projecttl.p.x32.api.command.useCommand
|
||||
import net.projecttl.p.x32.api.util.footer
|
||||
|
||||
object Steam : GlobalCommand {
|
||||
override val data = useCommand {
|
||||
|
@ -35,18 +40,26 @@ object Steam : GlobalCommand {
|
|||
SteamApiService.getHotSales().list
|
||||
}
|
||||
|
||||
|
||||
when (ev.subcommandName) {
|
||||
"할인목록" -> {
|
||||
ev.replyEmbeds(steamSaleEmbed(sale, false)).queue()
|
||||
ev.replyEmbeds(steamSaleEmbed(sale, false, ev.user)).addActionRow(
|
||||
Button.secondary("previousSteamSale", "◀").asDisabled(),
|
||||
Button.secondary("nextSteamSale", "▶")
|
||||
).queue()
|
||||
|
||||
}
|
||||
|
||||
"인기할인" -> {
|
||||
ev.replyEmbeds(steamSaleEmbed(hotSale, true)).queue()
|
||||
ev.replyEmbeds(steamSaleEmbed(hotSale, true, ev.user)).addActionRow(
|
||||
Button.secondary("previousSteamHotSale", "◀").asDisabled(),
|
||||
Button.secondary("nextSteamHotSale", "▶")
|
||||
).queue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun steamSaleEmbed(list: List<SteamSaleData>, hot: Boolean): MessageEmbed {
|
||||
fun steamSaleEmbed(list: List<SteamSaleData>, hot: Boolean,user: User): MessageEmbed {
|
||||
val embed = EmbedBuilder()
|
||||
if (hot) embed.setTitle("스팀 인기 할인목록")
|
||||
else embed.setTitle("스팀 할인목록")
|
||||
|
@ -54,10 +67,12 @@ object Steam : GlobalCommand {
|
|||
list.forEach {
|
||||
val saleInfo = """
|
||||
~~₩${it.full_price_va.formatWon()}~~ → ₩${it.sale_price_va.formatWon()}
|
||||
[link](${it.store_lk})
|
||||
""".trimIndent()
|
||||
|
||||
embed.addField("${it.title_nm} (${(it.discount_rt * 100).toInt()}%)", saleInfo, false)
|
||||
}
|
||||
embed.footer(user)
|
||||
|
||||
return embed.build()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.noobnuby.plugin.data
|
||||
|
||||
data class ButtonState(val page: Int,val hot: Boolean)
|
|
@ -15,5 +15,6 @@ data class SteamSaleData(
|
|||
val start_dt: String,
|
||||
val end_dt: String,
|
||||
val total_cn: Int,
|
||||
val list: List<SteamSaleData>
|
||||
val list: List<SteamSaleData>,
|
||||
val more_fl: Boolean
|
||||
)
|
|
@ -0,0 +1,74 @@
|
|||
package com.noobnuby.plugin.handler
|
||||
|
||||
import com.noobnuby.plugin.command.Steam
|
||||
import com.noobnuby.plugin.data.ButtonState
|
||||
import com.noobnuby.plugin.service.SteamApiService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
||||
|
||||
object ButtonClick : ListenerAdapter() {
|
||||
private val buttonState = mutableMapOf<String, ButtonState>()
|
||||
|
||||
override fun onButtonInteraction(ev: ButtonInteractionEvent) {
|
||||
val buttonId = ev.componentId
|
||||
val currentState = buttonState.getOrDefault(ev.message.id, ButtonState(1, false))
|
||||
|
||||
if (buttonId == "nextSteamSale" || buttonId == "nextSteamHotSale") {
|
||||
val isHotSale = buttonId == "nextSteamHotSale"
|
||||
|
||||
buttonState[ev.message.id] = currentState.copy(page = currentState.page + 1)
|
||||
|
||||
println("next " + buttonState[ev.message.id])
|
||||
|
||||
val sale = runBlocking {
|
||||
if (isHotSale) {
|
||||
SteamApiService.getHotSales(buttonState[ev.message.id]!!.page).list
|
||||
} else {
|
||||
SteamApiService.getSales(buttonState[ev.message.id]!!.page).list
|
||||
}
|
||||
}
|
||||
val moreFl = runBlocking {
|
||||
if (isHotSale) {
|
||||
!SteamApiService.getHotSales(buttonState[ev.message.id]!!.page).more_fl
|
||||
} else {
|
||||
!SteamApiService.getSales(buttonState[ev.message.id]!!.page).more_fl
|
||||
}
|
||||
}
|
||||
|
||||
ev.editMessageEmbeds(Steam.steamSaleEmbed(sale, isHotSale, ev.user)).setActionRow(
|
||||
Button.secondary(if(isHotSale) "previousSteamHotSale" else "previousSteamSale", "◀"),
|
||||
Button.secondary("nextSteamSale", "▶").withDisabled(moreFl)
|
||||
).queue()
|
||||
}
|
||||
|
||||
if (buttonId == "previousSteamSale" || buttonId == "previousSteamHotSale") {
|
||||
val isHotSale = buttonId == "previousSteamHotSale"
|
||||
|
||||
buttonState[ev.message.id] = currentState.copy(page = currentState.page - 1)
|
||||
|
||||
println("previous " + buttonState[ev.message.id])
|
||||
|
||||
val sale = runBlocking {
|
||||
if (isHotSale) {
|
||||
SteamApiService.getHotSales(buttonState[ev.message.id]!!.page).list
|
||||
} else {
|
||||
SteamApiService.getSales(buttonState[ev.message.id]!!.page).list
|
||||
}
|
||||
}
|
||||
val moreFl = runBlocking {
|
||||
if (isHotSale) {
|
||||
!SteamApiService.getHotSales(buttonState[ev.message.id]!!.page).more_fl
|
||||
} else {
|
||||
!SteamApiService.getSales(buttonState[ev.message.id]!!.page).more_fl
|
||||
}
|
||||
}
|
||||
|
||||
ev.editMessageEmbeds(Steam.steamSaleEmbed(sale, isHotSale, ev.user)).setActionRow(
|
||||
Button.secondary(buttonId, "◀").withDisabled(buttonState[ev.message.id]!!.page <= 1),
|
||||
Button.secondary(if(isHotSale) "nextSteamHotSale" else "nextSteamSale", "▶").withDisabled(moreFl)
|
||||
).queue()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,14 +17,14 @@ object SteamApiService {
|
|||
BrowserUserAgent()
|
||||
}
|
||||
|
||||
suspend fun getSales(): SteamSaleData {
|
||||
val url = "https://steamsale.windbell.co.kr/api/v1/sales/currents?keyword=&page=1&size=5"
|
||||
suspend fun getSales(page: Int = 1): SteamSaleData {
|
||||
val url = "https://steamsale.windbell.co.kr/api/v1/sales/currents?keyword=&page=${page}&size=5"
|
||||
|
||||
return client.get(url).body()
|
||||
}
|
||||
|
||||
suspend fun getHotSales(): SteamSaleData {
|
||||
val url = "https://steamsale.windbell.co.kr/api/v1/sales/tops?page=1&size=5"
|
||||
suspend fun getHotSales(page: Int = 1): SteamSaleData {
|
||||
val url = "https://steamsale.windbell.co.kr/api/v1/sales/tops?page=${page}&size=5"
|
||||
|
||||
return client.get(url).body()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue