Skip to content

Commit

Permalink
Merge pull request #72 from nano-devs/development
Browse files Browse the repository at this point in the history
Development: Update LyricCommand and Minor fixes
  • Loading branch information
madeyoga authored Nov 24, 2020
2 parents 2794b51 + c7cc273 commit f9b7017
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 22 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/sedmelluq/com.sedmelluq' }
}

dependencies {
Expand All @@ -24,6 +25,7 @@ dependencies {
compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
compile 'joda-time:joda-time:2.10.6'
implementation 'com.sedmelluq:lavaplayer:1.3.61'
implementation("com.sedmelluq:lavaplayer-ext-youtube-rotator:0.2.1")
compile 'com.github.natanbc:lavadsp:0.7.4'
implementation 'com.github.Shiroechi:YoutubeSearchApi-Java:1.2.6'
implementation 'mysql:mysql-connector-java:8.0.21'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions scripts/global_reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 global_reset.py
1 change: 1 addition & 0 deletions scripts/run_bot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nohup java -jar discordbot/Nano.Jda_2020-11-23.jar &
1 change: 1 addition & 0 deletions scripts/run_mysql_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo mysqld --skip-grant-tables --lower-case-table-names=1 &
File renamed without changes.
17 changes: 17 additions & 0 deletions src/main/java/client/NanoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.lava.extensions.youtuberotator.YoutubeIpRotatorSetup;
import com.sedmelluq.lava.extensions.youtuberotator.planner.NanoIpRoutePlanner;
import com.sedmelluq.lava.extensions.youtuberotator.tools.ip.Ipv6Block;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import org.apache.http.client.config.RequestConfig;
import org.jetbrains.annotations.Nullable;
import service.music.*;

import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -36,6 +43,16 @@ public NanoClient(MusicService musicService, EventWaiter waiter) {
this.playerManager = new DefaultAudioPlayerManager();
AudioSourceManagers.registerRemoteSources(playerManager);
AudioSourceManagers.registerLocalSource(playerManager);
this.playerManager.setHttpRequestConfigurator((config) ->
RequestConfig.copy(config).setConnectTimeout(10000).build());

YoutubeAudioSourceManager youtubeSource = new YoutubeAudioSourceManager();

String ipv6Block = System.getenv("ipv6block") + "/64";
new YoutubeIpRotatorSetup(
new NanoIpRoutePlanner(Collections.singletonList(new Ipv6Block(ipv6Block)), true))
.forSource(youtubeSource)
.setup();

this.waiter = waiter;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/command/music/JoinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ protected void execute(CommandEvent event) {
}
event.getGuild().getAudioManager().openAudioConnection(channel);

if (!event.getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS) &&
!event.getSelfMember().getVoiceState().isDeafened()) {
CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
"Please don't undeafen me! I work better by being deafened because: " +
"Less lag, more clear, better quality, and doesn't randomly disconnect",
true);
event.reply(embedBuilder.build());
}
// if (!event.getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS) &&
// !event.getSelfMember().getVoiceState().isDeafened()) {
// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
// "Please don't undeafen me! I work better by being deafened because: " +
// "Less lag, more clear, better quality, and doesn't randomly disconnect",
// true);
// event.reply(embedBuilder.build());
// }

event.reply(":white_check_mark: | Connected to :loud_sound: `" + channel.getName() + "`");
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/command/music/LeaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ protected void execute(CommandEvent event) {
}
}

musicManager.player.destroy();
musicManager.scheduler.setInLoopState(false);
musicManager.scheduler.getQueue().clear();
musicManager.player.destroy();
nanoClient.getMusicManagers().remove(guild.getIdLong());

event.getMessage().addReaction("\u23F9").queue();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/command/music/LyricCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public LyricCommand(NanoClient client)
this.arguments = "<song-title>";
this.help = "Get lyric for music.\n" +
"If `song-title` is empty, the title of the currently playing music will be used.\n";
this.aliases = new String[]{"lyrics"};
this.guildOnly = true;
this.cooldown = 2;
this.category = new Category("Music");
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/listener/MemberVoiceListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ public void onGuildVoiceJoin(@NotNull GuildVoiceJoinEvent event) {
if (event.getGuild().getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS)) {
event.getMember().deafen(true).queue();
}
// else {
// TextChannel textChannel = nanoClient.getGuildAudioPlayer(event.getGuild()).scheduler.textChannel;
//
// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
// "Please don't undeafen me! I work better by being deafened because: " +
// "Less lag, more clear, better quality, and doesn't randomly disconnect",
// true);
//
// textChannel.sendMessage(embedBuilder.build()).queue();
// }
else {
TextChannel textChannel = nanoClient.getGuildAudioPlayer(event.getGuild()).scheduler.textChannel;

CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
"Please don't undeafen me! I work better by being deafened because: " +
"Less lag, more clear, better quality.",
true);

textChannel.sendMessage(embedBuilder.build()).queue();
}
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/service/music/MusicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public void leaveVoiceChannel(Guild guild, GuildMusicManager musicManager){
AudioManager audioManager = guild.getAudioManager();
audioManager.closeAudioConnection();

musicManager.player.destroy();
musicManager.scheduler.setInLoopState(false);
musicManager.scheduler.getQueue().clear();
musicManager.player.destroy();
}

public boolean isMemberInVoiceState(Member member) {
Expand Down

0 comments on commit f9b7017

Please sign in to comment.