Feature Major updates and bug fixes
Some checks failed
Locusworks Team/eight-track/pipeline/head There was a failure building this commit
Some checks failed
Locusworks Team/eight-track/pipeline/head There was a failure building this commit
#4 Added logic to disconnect the bot if no song is playing or no one is listening #10 Added functionality to play song from local source and ability to upload songs #10 No longer cashes songs in memory but queries the database for random song #10 Whatsnext will push a song on the queue if it doesn't exist #10 Next will get a random song from the database
This commit is contained in:
@@ -40,7 +40,6 @@ import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.GuildSongRepoService;
|
||||
@@ -57,18 +56,12 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
@Autowired
|
||||
private ConfigurationService confService;
|
||||
|
||||
@Autowired
|
||||
private GuildRepository guildRepo;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
@Autowired
|
||||
private Mp3UploadHandler uploadHandler;
|
||||
|
||||
@Autowired
|
||||
private GuildSongRepoService guildSongRepoService;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() throws IOException {
|
||||
this.musicDir = confService.getMusicDirectory();
|
||||
@@ -81,7 +74,7 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
public void onGuildJoin(GuildJoinEvent event) {
|
||||
try {
|
||||
long guildId = event.getGuild().getIdLong();
|
||||
DiscordGuild discordGuild = guildRepo.findByGuildId(guildId);
|
||||
DiscordGuild discordGuild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
|
||||
if (discordGuild != null) return;
|
||||
|
||||
logger.debug("Joining Server: " + event.getGuild().getName());
|
||||
@@ -91,7 +84,7 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
discordGuild.setGuildName(event.getGuild().getName());
|
||||
discordGuild.setDateJoined(new Date());
|
||||
|
||||
guildRepo.save(discordGuild);
|
||||
guildSongRepoService.getGuildRepo().save(discordGuild);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Unable to persist server information to database: " + ex.getMessage(), ex);
|
||||
}
|
||||
@@ -107,14 +100,15 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws IOException {
|
||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws Exception {
|
||||
|
||||
if (!musicService.containsKey(event.getGuild().getIdLong())) {
|
||||
musicService.put(event.getGuild().getIdLong(),
|
||||
if (!GuildMusicService.getMap().containsKey(event.getGuild().getIdLong())) {
|
||||
GuildMusicService.getMap().put(event.getGuild().getIdLong(),
|
||||
new GuildMusicHandler(musicDir, event.getGuild().getIdLong(), uploadHandler, guildSongRepoService));
|
||||
}
|
||||
GuildMusicHandler gmh = musicService.get(event.getGuild().getIdLong());
|
||||
gmh.accept((id) -> musicService.remove(id));
|
||||
|
||||
GuildMusicHandler gmh = GuildMusicService.getMap().get(event.getGuild().getIdLong());
|
||||
gmh.accept((id) -> GuildMusicService.getMap().remove(id));
|
||||
|
||||
String command = event.getMessage().getContentRaw().trim().toLowerCase();
|
||||
|
||||
@@ -129,6 +123,7 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
case "-stop":
|
||||
gmh.isPlaying(false);
|
||||
gmh.stop(event);
|
||||
event.getGuild().getAudioManager().closeAudioConnection();
|
||||
return;
|
||||
case "-next":
|
||||
gmh.next(event);
|
||||
@@ -140,9 +135,6 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
case "-whatsnext":
|
||||
gmh.whatsNext(event);
|
||||
break;
|
||||
case "-index":
|
||||
gmh.index(event);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user