Skip to content

Commit 972a407

Browse files
committed
Update some music command executions
1 parent 683de21 commit 972a407

File tree

5 files changed

+97
-33
lines changed

5 files changed

+97
-33
lines changed

bot/src/main/java/me/duncte123/skybot/CommandManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ public void executeSlashCommand(SlashCommandInteractionEvent event) {
764764
final MusicCommand command = (MusicCommand) this.getCommand(musicName);
765765

766766
if (command != null) {
767-
command.handleEvent(event, guild, variables);
767+
command.handleSlashWithAutoJoin(event, guild, variables);
768768
}
769769

770770
return;

bot/src/main/java/me/duncte123/skybot/objects/command/MusicCommand.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,45 @@ private boolean channelChecks(CommandContext ctx, AudioUtils audioUtils, String
111111
return true;
112112
}
113113

114-
private boolean isAbleToJoinChannel(CommandContext ctx) {
115-
if (isUserOrGuildPatron(ctx, false)) {
116-
return ctx.getMember().getVoiceState().inAudioChannel() &&
117-
!getLavalinkManager().isConnected(ctx.getGuild());
114+
private boolean canRunSlashCommand(SlashCommandInteractionEvent event, DunctebotGuild guild, AudioUtils audioUtils) {
115+
if (!event.getMember().getVoiceState().inAudioChannel()) {
116+
event.reply("Please join a voice channel first").setEphemeral(true).queue();
117+
return false;
118+
}
119+
120+
final LavalinkManager lavalinkManager = getLavalinkManager();
121+
122+
if (!lavalinkManager.isConnected(guild)) {
123+
event.reply("I'm not in a voice channel, use `/join` to make me join a channel")
124+
.setEphemeral(true)
125+
.queue();
126+
127+
return false;
128+
}
129+
130+
final AudioChannelUnion connectedChannel = lavalinkManager.getConnectedChannel(guild);
131+
132+
if (connectedChannel != null && !connectedChannel.getMembers().contains(event.getMember())) {
133+
event.reply("I'm sorry, but you have to be in the same channel as me to use any music related commands")
134+
.setEphemeral(true)
135+
.queue();
136+
137+
return false;
118138
}
119139

120-
return false;
140+
audioUtils.getMusicManager(guild.getIdLong()).setLatestChannelId(event.getChannel().getIdLong());
141+
return true;
142+
}
143+
144+
private boolean isAbleToJoinChannel(CommandContext ctx) {
145+
// if (isUserOrGuildPatron(ctx, false)) {
146+
// return ctx.getMember().getVoiceState().inAudioChannel() &&
147+
// !getLavalinkManager().isConnected(ctx.getGuild());
148+
// }
149+
150+
// return false
151+
return ctx.getMember().getVoiceState().inAudioChannel() &&
152+
!getLavalinkManager().isConnected(ctx.getGuild());
121153
}
122154

123155
protected static LavalinkManager getLavalinkManager() {
@@ -129,6 +161,21 @@ protected SubcommandData getSubData() {
129161
return new SubcommandData(getName(), getHelp(getName(), "/"));
130162
}
131163

164+
public void handleSlashWithAutoJoin(@Nonnull SlashCommandInteractionEvent event, DunctebotGuild guild, @Nonnull Variables variables) {
165+
if (this.mayAutoJoin) {
166+
// TODO: this will cause issues with the event not working properly, need to find a way to resolve this
167+
((MusicCommand) variables.getCommandManager()
168+
.getCommand("join"))
169+
.handleEvent(event, guild, variables);
170+
this.handleEvent(event, guild, variables);
171+
return;
172+
}
173+
174+
if (this.justRunLmao || canRunSlashCommand(event, guild, variables.getAudioUtils())) {
175+
this.handleEvent(event, guild, variables);
176+
}
177+
}
178+
132179
public abstract void handleEvent(@Nonnull SlashCommandInteractionEvent event, DunctebotGuild guild, @Nonnull Variables variables);
133180

134181
public static SlashCommandData getMusicCommandData(CommandManager mngr) {

bot/src/main/kotlin/me/duncte123/skybot/commands/music/ForceSkip.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import net.dv8tion.jda.api.Permission
3030
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
3131
import net.dv8tion.jda.api.interactions.commands.OptionType
3232
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData
33+
import java.util.Optional
3334
import kotlin.jvm.optionals.getOrNull
3435

3536
class ForceSkip : MusicCommand() {
@@ -110,6 +111,46 @@ class ForceSkip : MusicCommand() {
110111
guild: DunctebotGuild,
111112
variables: Variables,
112113
) {
113-
//
114+
val mng = variables.audioUtils.getMusicManager(guild.idLong)
115+
116+
val player = mng.player.getOrNull()
117+
val currTrack = player?.track
118+
119+
if (currTrack == null) {
120+
event.reply("The player is not playing.").queue()
121+
return
122+
}
123+
124+
val skipCount = Optional.ofNullable(event.getOption("skip_count"))
125+
.map { it.asInt }
126+
.orElse(1)
127+
val scheduler = mng.scheduler
128+
129+
val trackData = scheduler.getUserData(currTrack)
130+
131+
scheduler.skipTracks(skipCount, false)
132+
133+
// Return the console user if the requester is null
134+
val user = event.jda.getUserById(trackData.requester) ?: UnknownUser()
135+
136+
val newTrack = player.track
137+
138+
if (newTrack == null) {
139+
event.reply(
140+
"Successfully skipped $skipCount tracks.\n" +
141+
"Queue is now empty."
142+
).queue()
143+
return
144+
}
145+
146+
event.replyEmbeds(
147+
EmbedUtils.embedMessage(
148+
"Successfully skipped $skipCount tracks.\n" +
149+
"Now playing: ${newTrack.info.title}\n" +
150+
"Requester: ${user.asTag}"
151+
)
152+
.setThumbnail(newTrack.info.artworkUrl)
153+
.build()
154+
).queue()
114155
}
115156
}

bot/src/main/kotlin/me/duncte123/skybot/commands/music/LeaveCommand.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class LeaveCommand : MusicCommand() {
5555
guild: DunctebotGuild,
5656
variables: Variables,
5757
) {
58-
val guild = event.guild!!
59-
6058
if (!getLavalinkManager().isConnected(guild)) {
6159
event.reply("I'm not connected to any channels.").queue()
6260
return

bot/src/main/kotlin/me/duncte123/skybot/commands/music/PPlayCommand.kt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package me.duncte123.skybot.commands.music
2020

21-
import me.duncte123.botcommons.messaging.MessageUtils.sendError
2221
import me.duncte123.botcommons.messaging.MessageUtils.sendMsg
2322
import me.duncte123.skybot.Variables
2423
import me.duncte123.skybot.entities.jda.DunctebotGuild
@@ -35,35 +34,14 @@ class PPlayCommand : MusicCommand() {
3534
}
3635

3736
override fun run(ctx: CommandContext) {
38-
sendMsg(ctx, "Hey, this command will be going away soon. Please use the `/play` command instead.")
39-
40-
if (ctx.args.isEmpty()) {
41-
sendMsg(ctx, "To few arguments, use `${ctx.prefix}$name <media link>`")
42-
return
43-
}
44-
45-
val toPlay = ctx.argsRaw
46-
47-
if (toPlay.length > 1024) {
48-
sendError(ctx.message)
49-
sendMsg(ctx, "Input cannot be longer than 1024 characters.")
50-
return
51-
}
52-
53-
sendMsg(
54-
ctx,
55-
"Loading playlist.......\n" +
56-
"This may take a while depending on the size."
57-
)
58-
59-
ctx.audioUtils.loadAndPlay(ctx.audioData, toPlay, true)
37+
sendMsg(ctx, "This command has been removed. Please use the `/play` command instead.")
6038
}
6139

6240
override fun handleEvent(
6341
event: SlashCommandInteractionEvent,
6442
guild: DunctebotGuild,
6543
variables: Variables,
6644
) {
67-
event.reply("This command will be going away soon. Please use the `/play` command instead.").queue()
45+
event.reply("This command has been removed. Please use the `/play` command instead.").queue()
6846
}
6947
}

0 commit comments

Comments
 (0)