mirror of
https://github.com/noobnuby/Notification-Bot.git
synced 2024-11-29 14:53:04 +00:00
update
This commit is contained in:
parent
0ce15945f4
commit
e3aa1b97b2
2 changed files with 31 additions and 38 deletions
|
@ -5,17 +5,32 @@ import com.noobnuby.plugin.data.SteamSaleData
|
||||||
import com.noobnuby.plugin.handler.ButtonClick
|
import com.noobnuby.plugin.handler.ButtonClick
|
||||||
import com.noobnuby.plugin.service.SteamApiService
|
import com.noobnuby.plugin.service.SteamApiService
|
||||||
import com.noobnuby.plugin.util.formatWon
|
import com.noobnuby.plugin.util.formatWon
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
import net.dv8tion.jda.api.EmbedBuilder
|
import net.dv8tion.jda.api.EmbedBuilder
|
||||||
|
import net.dv8tion.jda.api.entities.Message
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed
|
import net.dv8tion.jda.api.entities.MessageEmbed
|
||||||
import net.dv8tion.jda.api.entities.User
|
import net.dv8tion.jda.api.entities.User
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
|
||||||
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionHook
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow
|
||||||
|
import net.dv8tion.jda.api.interactions.components.LayoutComponent
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
||||||
|
import net.dv8tion.jda.api.requests.RestAction
|
||||||
import net.projecttl.p.x32.api.command.GlobalCommand
|
import net.projecttl.p.x32.api.command.GlobalCommand
|
||||||
import net.projecttl.p.x32.api.command.useCommand
|
import net.projecttl.p.x32.api.command.useCommand
|
||||||
import net.projecttl.p.x32.api.util.footer
|
import net.projecttl.p.x32.api.util.footer
|
||||||
|
import java.time.Duration
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
object Steam : GlobalCommand {
|
object Steam : GlobalCommand {
|
||||||
|
private val buttonTime = mutableMapOf<InteractionHook, Int>()
|
||||||
|
|
||||||
override val data = useCommand {
|
override val data = useCommand {
|
||||||
name = "스팀"
|
name = "스팀"
|
||||||
description = "스팀 관련 명령어 입니다."
|
description = "스팀 관련 명령어 입니다."
|
||||||
|
@ -40,24 +55,27 @@ object Steam : GlobalCommand {
|
||||||
SteamApiService.getHotSales().list
|
SteamApiService.getHotSales().list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
when (ev.subcommandName) {
|
when (ev.subcommandName) {
|
||||||
"할인목록" -> {
|
"할인목록" -> {
|
||||||
ev.replyEmbeds(steamSaleEmbed(sale, false, ev.user)).addActionRow(
|
ev.replyEmbeds(steamSaleEmbed(sale, false, ev.user)).addActionRow(
|
||||||
Button.secondary("previousSteamSale", "◀").asDisabled(),
|
Button.secondary("previousSteamSale", "◀").asDisabled(),
|
||||||
Button.secondary("nextSteamSale", "▶")
|
Button.secondary("nextSteamSale", "▶")
|
||||||
).queue()
|
).queue {
|
||||||
|
it.deleteComponents().queueAfter(10, TimeUnit.SECONDS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"인기할인" -> {
|
"인기할인" -> {
|
||||||
ev.replyEmbeds(steamSaleEmbed(hotSale, true, ev.user)).addActionRow(
|
ev.replyEmbeds(steamSaleEmbed(hotSale, true, ev.user)).addActionRow(
|
||||||
Button.secondary("previousSteamHotSale", "◀").asDisabled(),
|
Button.secondary("previousSteamHotSale", "◀").asDisabled(),
|
||||||
Button.secondary("nextSteamHotSale", "▶")
|
Button.secondary("nextSteamHotSale", "▶")
|
||||||
).queue()
|
).queue {
|
||||||
|
it.deleteComponents().queueAfter(10, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
private fun InteractionHook.deleteComponents() = editOriginalComponents()
|
||||||
|
|
||||||
fun steamSaleEmbed(list: List<SteamSaleData>, hot: Boolean,user: User): MessageEmbed {
|
fun steamSaleEmbed(list: List<SteamSaleData>, hot: Boolean,user: User): MessageEmbed {
|
||||||
val embed = EmbedBuilder()
|
val embed = EmbedBuilder()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
import net.dv8tion.jda.api.interactions.components.buttons.Button
|
||||||
|
import net.dv8tion.jda.api.interactions.components.buttons.ButtonInteraction
|
||||||
|
|
||||||
object ButtonClick : ListenerAdapter() {
|
object ButtonClick : ListenerAdapter() {
|
||||||
private val buttonState = mutableMapOf<String, ButtonState>()
|
private val buttonState = mutableMapOf<String, ButtonState>()
|
||||||
|
@ -15,12 +16,13 @@ object ButtonClick : ListenerAdapter() {
|
||||||
val buttonId = ev.componentId
|
val buttonId = ev.componentId
|
||||||
val currentState = buttonState.getOrDefault(ev.message.id, ButtonState(1, false))
|
val currentState = buttonState.getOrDefault(ev.message.id, ButtonState(1, false))
|
||||||
|
|
||||||
if (buttonId == "nextSteamSale" || buttonId == "nextSteamHotSale") {
|
ev.messageId
|
||||||
val isHotSale = buttonId == "nextSteamHotSale"
|
|
||||||
|
|
||||||
buttonState[ev.message.id] = currentState.copy(page = currentState.page + 1)
|
if (buttonId == "nextSteamSale" || buttonId == "nextSteamHotSale" || buttonId == "previousSteamSale" || buttonId == "previousSteamHotSale") {
|
||||||
|
val isHotSale = buttonId == "nextSteamHotSale" || buttonId == "previousSteamHotSale"
|
||||||
|
val isNext = buttonId.startsWith("next")
|
||||||
|
|
||||||
println("next " + buttonState[ev.message.id])
|
buttonState[ev.message.id] = currentState.copy(page = currentState.page + if (isNext) 1 else -1)
|
||||||
|
|
||||||
val sale = runBlocking {
|
val sale = runBlocking {
|
||||||
if (isHotSale) {
|
if (isHotSale) {
|
||||||
|
@ -38,36 +40,9 @@ object ButtonClick : ListenerAdapter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ev.editMessageEmbeds(Steam.steamSaleEmbed(sale, isHotSale, ev.user)).setActionRow(
|
ev.editMessageEmbeds(Steam.steamSaleEmbed(sale, isHotSale, ev.user)).setActionRow(
|
||||||
Button.secondary(if(isHotSale) "previousSteamHotSale" else "previousSteamSale", "◀"),
|
Button.secondary(if (isHotSale) "previousSteamHotSale" else "previousSteamSale", "◀")
|
||||||
Button.secondary("nextSteamSale", "▶").withDisabled(moreFl)
|
.withDisabled(buttonState[ev.message.id]!!.page <= 1),
|
||||||
).queue()
|
Button.secondary(if (isHotSale) "nextSteamHotSale" else "nextSteamSale", "▶").withDisabled(moreFl)
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
).queue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue