Compare commits

..

No commits in common. "be6036cd5d4718599eb8873e75200000217c9a88" and "3ff544d699d898c650912f76e5e80b6cf07a1b21" have entirely different histories.

7 changed files with 32 additions and 39 deletions

View File

@ -14,6 +14,5 @@ That way multiple projects can share the same settings (useful for formatting ru
Any value defined here will override the pom.xml file value but is only applicable to the current project. Any value defined here will override the pom.xml file value but is only applicable to the current project.
--> -->
<netbeans.hint.license>gpl30</netbeans.hint.license> <netbeans.hint.license>gpl30</netbeans.hint.license>
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
</properties> </properties>
</project-shared-configuration> </project-shared-configuration>

View File

@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>5.0.0-beta.6</version> <version>4.3.0_277</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>

View File

@ -1,3 +0,0 @@
ytdl-cmd: /usr/bin/yt-dlp
discord-token: ODkwNjU5MjI2NDE2OTg0MDY0.YUzBCw.jHZWpIZSYeaYA7Sc7h93W_jV-rk
local-addr: 192.168.1.84

View File

@ -27,10 +27,8 @@ import moe.nekojimi.musicsearcher.providers.Searcher;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
@ -63,7 +61,7 @@ public final class Chords extends ListenerAdapter
private final Command helpCommand; private final Command helpCommand;
private PlayCommand playCommand; private PlayCommand playCommand;
private AudioChannel currentVoiceChannel = null; private VoiceChannel currentVoiceChannel = null;
private int trackNumber = 1; private int trackNumber = 1;
@ -87,15 +85,13 @@ public final class Chords extends ListenerAdapter
GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGES,
// We need voice states to connect to the voice channel // We need voice states to connect to the voice channel
GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_VOICE_STATES,
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MEMBERS
GatewayIntent.MESSAGE_CONTENT
); );
settings = new Settings(new File(options.getSettingsPath())); settings = new Settings(new File(options.getSettingsPath()));
JDABuilder builder = JDABuilder.createDefault(settings.getDiscordToken(), intents); JDABuilder builder = JDABuilder.createDefault(settings.getDiscordToken(), intents);
builder.enableIntents(GatewayIntent.MESSAGE_CONTENT);
if (settings.getLocalAddr() != null) if (settings.getLocalAddr() != null)
{ {
System.out.println("Using local address: " + settings.getLocalAddr()); System.out.println("Using local address: " + settings.getLocalAddr());
@ -182,23 +178,21 @@ public final class Chords extends ListenerAdapter
} }
@Override @Override
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) public void onGuildVoiceLeave(GuildVoiceLeaveEvent event)
{ {
super.onGuildVoiceUpdate(event);
if (this.currentVoiceChannel == null) if (this.currentVoiceChannel == null)
return; return;
final AudioChannel channelLeft = event.getChannelLeft(); final VoiceChannel channelLeft = event.getChannelLeft();
if (channelLeft != null && channelLeft == currentVoiceChannel)
{ if (channelLeft.getMembers().isEmpty())
if (channelLeft.getMembers().isEmpty()) if (channelLeft == currentVoiceChannel)
disconnect(); disconnect();
}
} }
@Override @Override
public void onMessageReceived(MessageReceivedEvent event) public void onGuildMessageReceived(GuildMessageReceivedEvent event)
{ {
super.onMessageReceived(event); //To change body of generated methods, choose Tools | Templates.
Message message = event.getMessage(); Message message = event.getMessage();
User author = message.getAuthor(); User author = message.getAuthor();
String content = message.getContentRaw(); String content = message.getContentRaw();
@ -315,7 +309,7 @@ public final class Chords extends ListenerAdapter
* @param channel * @param channel
* The channel to connect to * The channel to connect to
*/ */
public void connectTo(AudioChannel channel) public void connectTo(VoiceChannel channel)
{ {
Guild guild = channel.getGuild(); Guild guild = channel.getGuild();
// Get an audio manager for this guild, this will be created upon first use for each guild // Get an audio manager for this guild, this will be created upon first use for each guild
@ -404,7 +398,7 @@ public final class Chords extends ListenerAdapter
return jda; return jda;
} }
public AudioChannel getCurrentVoiceChannel() public VoiceChannel getCurrentVoiceChannel()
{ {
return currentVoiceChannel; return currentVoiceChannel;
} }

View File

@ -18,8 +18,8 @@ package moe.nekojimi.chords.commands;
import java.util.List; import java.util.List;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.dv8tion.jda.api.requests.restaction.MessageAction;
/** /**
* *
@ -31,16 +31,16 @@ public class Invocation
private Message requestMessage; private Message requestMessage;
private Message responseMessage; private Message responseMessage;
private final MessageReceivedEvent event; private final GuildMessageReceivedEvent event;
private final List<String> args; private final List<String> args;
public Invocation(MessageReceivedEvent event, List<String> args) public Invocation(GuildMessageReceivedEvent event, List<String> args)
{ {
this.event = event; this.event = event;
this.args = args; this.args = args;
} }
public MessageReceivedEvent getEvent() public GuildMessageReceivedEvent getEvent()
{ {
return event; return event;
} }
@ -53,14 +53,17 @@ public class Invocation
@SuppressWarnings("null") @SuppressWarnings("null")
public void respond(String text) public void respond(String text)
{ {
MessageAction action = null;
if (responseMessage == null) if (responseMessage == null)
{ {
responseMessage = requestMessage.reply(text).complete(); action = requestMessage.reply(text);
} else } else
{ {
responseMessage = responseMessage.editMessage(text).complete(); action = responseMessage.editMessage(text);
} }
responseMessage = action.complete();
} }
public Message getRequestMessage() public Message getRequestMessage()

View File

@ -8,9 +8,7 @@ package moe.nekojimi.chords.commands;
import java.util.List; import java.util.List;
import moe.nekojimi.chords.Chords; import moe.nekojimi.chords.Chords;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class JoinCommand extends Command public class JoinCommand extends Command
{ {
@ -23,9 +21,9 @@ public class JoinCommand extends Command
@Override @Override
public void call(Invocation invocation) public void call(Invocation invocation)
{ {
MessageReceivedEvent event = invocation.getEvent(); GuildMessageReceivedEvent event = invocation.getEvent();
List<String> args = invocation.getArgs(); List<String> args = invocation.getArgs();
MessageChannel textChannel = event.getChannel(); TextChannel textChannel = event.getChannel();
VoiceChannel channel = null; VoiceChannel channel = null;
if (args.isEmpty() || args.get(0).isBlank()) if (args.isEmpty() || args.get(0).isBlank())
{ {
@ -33,8 +31,8 @@ public class JoinCommand extends Command
if (member != null) if (member != null)
{ {
GuildVoiceState voiceState = member.getVoiceState(); GuildVoiceState voiceState = member.getVoiceState();
if (voiceState != null && voiceState.inAudioChannel()) if (voiceState != null && voiceState.inVoiceChannel())
channel = voiceState.getChannel().asVoiceChannel(); channel = voiceState.getChannel();
} }
if (channel == null) if (channel == null)
{ {
@ -84,7 +82,7 @@ public class JoinCommand extends Command
* @param textChannel * @param textChannel
* The text channel to send the message in * The text channel to send the message in
*/ */
public void onConnecting(VoiceChannel channel, MessageChannel textChannel) public void onConnecting(VoiceChannel channel, TextChannel textChannel)
{ {
textChannel.sendMessage("Connecting to " + channel.getName()).queue(); // never forget to queue()! textChannel.sendMessage("Connecting to " + channel.getName()).queue(); // never forget to queue()!
} }

View File

@ -5,7 +5,9 @@
*/ */
package moe.nekojimi.chords.commands; package moe.nekojimi.chords.commands;
import java.util.List;
import moe.nekojimi.chords.Chords; import moe.nekojimi.chords.Chords;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class LeaveCommand extends Command public class LeaveCommand extends Command
{ {