Skip to content

Commit

Permalink
I dont remember what I did but here are some changes I guess
Browse files Browse the repository at this point in the history
  • Loading branch information
bombies committed Jan 10, 2024
1 parent 073c665 commit 417ff6d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 76 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.bombies</groupId>
<artifactId>Robertify</artifactId>
<version>6.0.2</version>
<version>6.0.3</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-beta.18</version>
<version>5.0.0-beta.17</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down
105 changes: 41 additions & 64 deletions src/main/kotlin/main/commands/slashcommands/audio/NowPlayingCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import main.constants.Toggle
import main.utils.GeneralUtils
import main.utils.GeneralUtils.isUrl
import main.utils.RobertifyEmbedUtils
import main.utils.RobertifyEmbedUtils.Companion.replyEmbed
import main.utils.RobertifyEmbedUtils.Companion.sendEmbed
import main.utils.api.robertify.imagebuilders.AbstractImageBuilder
import main.utils.api.robertify.imagebuilders.ImageBuilderException
Expand Down Expand Up @@ -42,83 +43,59 @@ class NowPlayingCommand : AbstractSlashCommand(
override suspend fun handle(event: SlashCommandInteractionEvent) {
event.deferReply().queue()


val guild = event.guild!!
val memberVoiceState = event.member!!.voiceState!!
val selfVoiceState = guild.selfMember.voiceState!!
val acChecks = audioChannelChecks(memberVoiceState, selfVoiceState, true, true)
if (acChecks != null) {
event.replyEmbed { acChecks }.setEphemeral(true).queue()
return
}

val musicManager = RobertifyAudioManager[guild]
val player = musicManager.player
val track = player.playingTrack

val embed: MessageEmbed? = when {
!selfVoiceState.inAudioChannel() -> RobertifyEmbedUtils.embedMessage(
guild,
GeneralMessages.NOTHING_PLAYING
).build()

!memberVoiceState.inAudioChannel() -> RobertifyEmbedUtils.embedMessage(
guild,
GeneralMessages.USER_VOICE_CHANNEL_NEEDED
).build()

memberVoiceState.channel != selfVoiceState.channel ->
RobertifyEmbedUtils.embedMessage(
guild,
GeneralMessages.SAME_VOICE_CHANNEL_LOC,
Pair("{channel}", selfVoiceState.channel!!.asMention)
).build()

track == null -> RobertifyEmbedUtils.embedMessage(
guild,
GeneralMessages.NOTHING_PLAYING
).build()

else -> null
val sendBackupEmbed: suspend () -> Unit = {
event.hook.sendEmbed(guild) {
getNowPlayingEmbed(guild, event.channel.asGuildMessageChannel(), selfVoiceState, memberVoiceState)
}.queue()
}

if (embed != null) {
event.hook.sendEmbed(guild) { embed }
.queue()
} else {
val sendBackupEmbed: suspend () -> Unit = {
event.hook.sendEmbed(guild) {
getNowPlayingEmbed(guild, event.channel.asGuildMessageChannel(), selfVoiceState, memberVoiceState)
}.queue()
}

try {
val defaultImage = ThemesConfig(guild).getTheme().nowPlayingBanner
val builder = NowPlayingImageBuilder(
title = track!!.title,
artistName = track.author,
albumImage = try {
track.artworkUrl ?: defaultImage
} catch (e: MissingFieldException) {
defaultImage
}
)

val image = if (!track.isStream)
builder.copy(
duration = track.length,
currentTime = player.position,
isLiveStream = false
).build()
else builder.copy(
try {
val defaultImage = ThemesConfig(guild).getTheme().nowPlayingBanner
val builder = NowPlayingImageBuilder(
title = track!!.title,
artistName = track.author,
albumImage = try {
track.artworkUrl ?: defaultImage
} catch (e: MissingFieldException) {
defaultImage
}
)

val image = if (!track.isStream)
builder.copy(
duration = track.length,
currentTime = player.position,
isLiveStream = false
).build()
else builder.copy(
isLiveStream = false
).build()

if (image == null)
sendBackupEmbed()
else
event.hook.sendFiles(
FileUpload.fromData(
image,
AbstractImageBuilder.RANDOM_FILE_NAME
)
).queue()
} catch (e: ImageBuilderException) {
if (image == null)
sendBackupEmbed()
}
else
event.hook.sendFiles(
FileUpload.fromData(
image,
AbstractImageBuilder.RANDOM_FILE_NAME
)
).queue()
} catch (e: ImageBuilderException) {
sendBackupEmbed()
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/kotlin/main/main/Robertify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,10 @@ object Robertify {
logger.info("Watching ${event.guildAvailableCount} guilds on shard #${jda.shardInfo.shardId} (${event.guildUnavailableCount} unavailable)")
BotDBCache.instance.lastStartup = System.currentTimeMillis()
jda.shardManager?.setPresence(OnlineStatus.ONLINE, Activity.listening("/help"))

shardManager.guildCache.forEach { guild ->
RequestChannelConfig(guild).updateMessage()
}
}

private fun ShardManager.handleGuildReady() = listener<GuildReadyEvent> { event ->
val guild = event.guild
val locale = LocaleConfig(guild).getLocale()
try {
LocaleManager[guild].setLocale(locale)
} catch (e: ReaderException) {
logger.error("I couldn't set the locale for ${guild.name}")
}
loadNeededSlashCommands(guild)
rescheduleUnbans(guild)
RemindersConfig(guild).scheduleReminders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ abstract class AbstractSlashCommand protected constructor(val info: SlashCommand
)
}

/**
* Executes the necessary checks for audio commands.
* @param memberVoiceState The voice state of the user executing the command.
* @param selfVoiceState The voice state of the bot.
* @param selfChannelNeeded If the bot needs to be in a voice channel for the command to be executed.
* @param songMustBePlaying If the bot needs to be playing a song for the command to be executed.
* @return An embed of the error message, null if all the checks passed.
*/
suspend fun audioChannelChecks(
memberVoiceState: GuildVoiceState,
selfVoiceState: GuildVoiceState,
Expand Down

0 comments on commit 417ff6d

Please sign in to comment.