-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa92bea
commit 3956fbf
Showing
2 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/io/ileukocyte/hibernum/commands/music/ExportCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.ileukocyte.hibernum.commands.music | ||
|
||
import io.ileukocyte.hibernum.audio.audioPlayer | ||
import io.ileukocyte.hibernum.audio.exportQueueAsJson | ||
import io.ileukocyte.hibernum.commands.CommandException | ||
import io.ileukocyte.hibernum.commands.TextCommand | ||
import io.ileukocyte.hibernum.extensions.EmbedType | ||
import io.ileukocyte.hibernum.extensions.defaultEmbed | ||
|
||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.serializer | ||
|
||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent | ||
import net.dv8tion.jda.api.utils.FileUpload | ||
|
||
class ExportCommand : TextCommand { | ||
override val name = "export" | ||
override val description = "Sends the current queue and parameters of the player as a JSON file" | ||
override val aliases = setOf("export-queue", "save-queue") | ||
override val cooldown = 10L | ||
|
||
private val json = Json { prettyPrint = true } | ||
|
||
override suspend fun invoke(event: MessageReceivedEvent, args: String?) { | ||
val audioPlayer = event.guild.audioPlayer ?: return | ||
|
||
if (audioPlayer.player.playingTrack === null) { | ||
throw CommandException("No track is currently playing!") | ||
} | ||
|
||
val queue = audioPlayer.exportQueueAsJson(false) | ||
val file = FileUpload.fromData( | ||
json.encodeToString(serializer(), queue).toByteArray(), | ||
"queue.json", | ||
) | ||
|
||
val embed = defaultEmbed("The queue has been exported as a file!", EmbedType.SUCCESS) | ||
|
||
event.channel.sendFiles(file).setEmbeds(embed).queue(null) { file.close() } | ||
} | ||
|
||
override suspend fun invoke(event: SlashCommandInteractionEvent) { | ||
val audioPlayer = event.guild?.audioPlayer ?: return | ||
|
||
if (audioPlayer.player.playingTrack === null) { | ||
throw CommandException("No track is currently playing!") | ||
} | ||
|
||
val queue = audioPlayer.exportQueueAsJson(false) | ||
val file = FileUpload.fromData( | ||
json.encodeToString(serializer(), queue).toByteArray(), | ||
"queue.json", | ||
) | ||
|
||
val embed = defaultEmbed("The queue has been exported as a file!", EmbedType.SUCCESS) | ||
|
||
event.replyFiles(file).setEmbeds(embed).queue(null) { | ||
event.channel.sendFiles(file).setEmbeds(embed).queue(null) { | ||
file.close() | ||
} | ||
} | ||
} | ||
} |