Skip to content

Commit

Permalink
V0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-liaoo committed Apr 12, 2017
1 parent 2f7fafb commit ad5d9de
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 14 deletions.
15 changes: 9 additions & 6 deletions src/main/java/Audio/AudioConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@
*/
public class AudioConnection {

public static VoiceChannel vc;
public static AudioManager am;
private static VoiceChannel vc;
private static AudioManager am;

public static void connect(MessageReceivedEvent e, boolean inform)
{
try {
vc = e.getMember().getVoiceState().getChannel();
Main.guilds.get(e.getGuild().getId()).setVc(e.getMember().getVoiceState().getChannel());
Main.guilds.get(e.getGuild().getId()).setTc(e.getTextChannel());

vc = Main.guilds.get(e.getGuild().getId()).getVc();
am = e.getGuild().getAudioManager();
am.openAudioConnection(vc);
am.openAudioConnection(Main.guilds.get(e.getGuild().getId()).getVc());
} catch (IllegalArgumentException iea) {
e.getChannel().sendMessage(Emoji.error + " You must connect to a voice channel first.").queue();
return;
} catch (PermissionException pe) {
e.getChannel().sendMessage(Emoji.error + " I don't have the permission to join `" + vc.getName() + "`.").queue();
e.getChannel().sendMessage(Emoji.error + " I don't have the permission to join `" + Main.guilds.get(e.getGuild().getId()).getVc().getName() + "`.").queue();
SmartLogger.errorLog(pe, e, "AudioConnection", "Do not have permission to join a voice channel");
return;
}
Expand All @@ -55,7 +58,7 @@ public static void disconnect(MessageReceivedEvent e, boolean inform)

//Inform the users that the bot joined a voice channel
if(inform)
e.getChannel().sendMessage(Emoji.globe + " Left Voice Channel `" + vc.getName() + "`").queue();
e.getChannel().sendMessage(Emoji.globe + " Left Voice Channel `" + Main.guilds.get(e.getGuild().getId()).getVc().getName() + "`").queue();
}


Expand Down
8 changes: 6 additions & 2 deletions src/main/java/Audio/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,30 @@ public static void play(String link, MessageReceivedEvent e)

if(m.find()){
Music.playerManager.loadItemOrdered(Music.playerManager, link, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
if(Main.guilds.get(e.getGuild().getId()).getPlayer().getPlayingTrack() != null)
e.getTextChannel().sendMessage(Emoji.success + " Queued `" + track.getInfo().title + "`").queue();
else
e.getTextChannel().sendMessage(Emoji.notes + " Now playing `" + track.getInfo().title + "`").queue();
//else
// e.getTextChannel().sendMessage(Emoji.notes + " Now playing `" + track.getInfo().title + "`").queue();

Main.guilds.get(e.getGuild().getId()).getScheduler().queue(track, e);
return;
}

@Override
public void playlistLoaded(AudioPlaylist playlist) {
e.getTextChannel().sendMessage(Emoji.success + " Playlist loaded successfully!").queue();
return;
}

@Override
public void noMatches() {
e.getTextChannel().sendMessage(Emoji.error + " No match found.").queue();
return;
}

@Override
public void loadFailed(FriendlyException exception) {
e.getTextChannel().sendMessage(Emoji.error + " Fail to load the video.").queue();
SmartLogger.errorLog(exception, e, this.getClass().getName(), "Failed to load this video: " + link);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/Audio/TrackScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

Expand All @@ -30,6 +31,8 @@ public class TrackScheduler extends AudioEventAdapter {
private final AudioPlayer player;
private final BlockingQueue<AudioTrack> queue;
private final ArrayList<User> requester;

private static TextChannel tc;

/**
* @param player The audio player this scheduler uses
Expand Down Expand Up @@ -67,7 +70,7 @@ public void nextTrack() {
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
super.onTrackStart(player, track);
//event.getTextChannel().sendMessage(Emoji.success + " Now playing `" + track.getInfo().title + "`. Track loaded successfully!").queue();
tc.sendMessage(Emoji.notes + " Now playing `" + track.getInfo().title + "`").queue();
}

@Override
Expand Down Expand Up @@ -99,5 +102,9 @@ public ArrayList<User> getRequester()
{
return requester;
}

public void setTc(TextChannel tc) {
this.tc = tc;
}
}

8 changes: 7 additions & 1 deletion src/main/java/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
Log type: Added, Changed, Deprecated, Removed, Fixed, Security

### V[0.1.0]
#### [0.1.0] - 2017-04-03
##### Changed
- Reconstruct the full HelpCommand from one crunch of String to two fields.
Expand Down Expand Up @@ -53,9 +54,14 @@ Log type: Added, Changed, Deprecated, Removed, Fixed, Security
- EmojisCommand: Add SayEmoji Function in which the bot will talk in Emoji Language.
- InfoServerCommand: Get Server Info By ID.


### V[0.2.0]
#### [0.2.0] - 2017-04-11
##### Added
-
- GuildSetting: Added TextChannel and VoiceChannel instance so the bot is able to detect
onTrackStart() event and send a message saying "Now playing ...".
- PlayCommand dynamic command for YouTube search (Show top 5 results)
- MusicCommand for getting a list of music commands.
##### Fixed
- NowPlayingCommand and QueueCommand was not able to get current track information.
- Several NullPointerExceptions from Music Module. Moved Music.musicStartup before jda start up.
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/Command/MusicModule/JoinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import Resource.Prefix;
import Resource.Info;
import Audio.*;
import static Audio.AudioConnection.vc;
import Command.Command;
import Main.*;
import Resource.Emoji;
import java.awt.Color;
import java.time.Instant;
import net.dv8tion.jda.core.EmbedBuilder;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Command/MusicModule/PlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Audio.Music;
import Command.Command;
import Resource.Emoji;
import Resource.Info;
import Resource.Prefix;
import Resource.SearchResult;
Expand Down Expand Up @@ -111,6 +112,7 @@ else if(args.length > 0 && "-m".equals(args[0]))
} catch (IOException ioe) {
SmartLogger.errorLog(ioe, e, this.getClass().getName(), "IOException at getting Youtube search result.");
} catch (IndexOutOfBoundsException ioobe) {
e.getChannel().sendMessage(Emoji.error + " No results.").queue();
SmartLogger.errorLog(ioobe, e, this.getClass().getName(), "Cannot get Yt search result correctly. Input: " + input);
}
}
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/Setting/GuildSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import Audio.AudioPlayerSendHandler;
import Audio.TrackScheduler;
import Audio.TrackScheduler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;

/**
*
Expand All @@ -28,6 +29,12 @@ public class GuildSetting {
* Track scheduler for the player.
*/
private final TrackScheduler scheduler;
/**
* Binded Voice Channel for the guild.
*/
private VoiceChannel vc;

private TextChannel tc;

/**
* @param voteSkip The vote for skipping current song
Expand Down Expand Up @@ -70,6 +77,23 @@ public AudioPlayer getPlayer()
{
return player;
}

public VoiceChannel getVc() {
return vc;
}

public void setVc(VoiceChannel vc) {
this.vc = vc;
}

public TextChannel getTc() {
return tc;
}

public void setTc(TextChannel tc) {
this.tc = tc;
scheduler.setTc(tc);
}

public String getPrefix()
{
Expand Down
Binary file modified target/classes/Audio/AudioConnection.class
Binary file not shown.
Binary file modified target/classes/Audio/Music$1.class
Binary file not shown.
Binary file modified target/classes/Audio/Music.class
Binary file not shown.
Binary file modified target/classes/Audio/TrackScheduler.class
Binary file not shown.
Binary file modified target/classes/Command/InformationModule/HelpCommand.class
Binary file not shown.
Binary file modified target/classes/Command/InformationModule/InfoServerCommand.class
Binary file not shown.
Binary file modified target/classes/Command/MusicModule/JoinCommand.class
Binary file not shown.
Binary file modified target/classes/Command/MusicModule/PlayCommand.class
Binary file not shown.
Binary file modified target/classes/Listener/CommandListener.class
Binary file not shown.
Binary file modified target/classes/Main/CommandParser$CommandContainer.class
Binary file not shown.
Binary file modified target/classes/Main/CommandParser.class
Binary file not shown.
Binary file modified target/classes/Main/Main.class
Binary file not shown.
Binary file modified target/classes/Resource/HelpText.class
Binary file not shown.
Binary file modified target/classes/Setting/GuildSetting.class
Binary file not shown.

0 comments on commit ad5d9de

Please sign in to comment.