Skip to content

Commit

Permalink
New fork of Lavaplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Niron3206 committed May 9, 2024
1 parent 542394a commit 336ad5f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ To compile this maven project into jar file, write it in console (don't forget t

You will see compiled jar file in target folder, you also need to copy your .env file with your parameters in target folder.

To open jar file you have to write `java -jar TouhouClub-1.5.jar` in console (you have to be in the same directory as the jar file).
To open jar file you have to write `java -jar TouhouClub-1.6.jar` in console (you have to be in the same directory as the jar file).
30 changes: 22 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ru.niron3206</groupId>
<artifactId>TouhouClub</artifactId>
<version>1.5</version>
<version>1.6</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -24,23 +24,37 @@
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
<repository>
<id>arbjergDev-releases</id>
<name>Lavalink Repository</name>
<url>https://maven.lavalink.dev/releases</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.DV8FromTheWorld</groupId>
<artifactId>JDA</artifactId>
<version>v5.0.0-beta.17</version>
<version>v5.0.0-beta.23</version>
</dependency>

<dependency>
<groupId>dev.arbjerg</groupId>
<artifactId>lavaplayer</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>dev.lavalink.youtube</groupId>
<artifactId>v2</artifactId>
<version>1.1.0</version>
</dependency>


<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.77</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -70,10 +84,10 @@
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ru/niron3206/audioplayer/AutoLeave.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;

import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -16,16 +17,19 @@ public AutoLeave(Guild guild) {

public void timer() {
MusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);

TimerTask timerTask = new TimerTask() {
@Override
public void run() {

GuildVoiceState selfVoiceState = guild.getSelfMember().getVoiceState();
System.out.println("I'm in voice chat (ID: " + selfVoiceState.getChannel().getId() + ")");
VoiceChannel channel = selfVoiceState.getChannel().asVoiceChannel();

System.out.println("I'm in voice chat (ID: " + channel.getId() + ")");

if ((musicManager.audioPlayer.getPlayingTrack() == null
&& musicManager.scheduler.queue.isEmpty())
|| selfVoiceState.getChannel().asVoiceChannel().getMembers().isEmpty()) {
|| channel.getMembers().isEmpty()) {
musicManager.scheduler.looping = false;
musicManager.audioPlayer.stopTrack();
guild.getAudioManager().closeAudioConnection();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/ru/niron3206/audioplayer/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

Expand All @@ -24,6 +25,9 @@ public PlayerManager() {
this.musicManager = new HashMap<>();
this.audioPlayerManager = new DefaultAudioPlayerManager();

YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
audioPlayerManager.registerSourceManager(youtube);

AudioSourceManagers.registerRemoteSources(audioPlayerManager);
AudioSourceManagers.registerLocalSource(audioPlayerManager);
}
Expand Down Expand Up @@ -93,7 +97,7 @@ public void noMatches() {

@Override
public void loadFailed(FriendlyException e) {
//
e.printStackTrace();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/niron3206/cmds/music/PlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void handle(CommandContext ctx) {
TextChannel channel = ctx.getEvent().getChannel().asTextChannel();
List<Message.Attachment> attachments = ctx.getEvent().getMessage().getAttachments();

if (ctx.getArgs() == null && attachments.size() == 0) {
if (ctx.getArgs() == null && attachments.isEmpty()) {
channel.sendMessage("\uD83D\uDD34 Ничего не понял, вот как должно быть: `~play <ютуб ссылка, ссылка на аудио или прикреплённый аудиофайл>`").queue();
return;
}
Expand Down

0 comments on commit 336ad5f

Please sign in to comment.