Refactored how the music handler was being referenced
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
This commit is contained in:
@ -76,6 +76,9 @@ public class Log implements Serializable {
|
||||
@Column(name = "date_added")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date dateAdded;
|
||||
@Lob
|
||||
@Column(name = "exception")
|
||||
private byte[] exception;
|
||||
@JoinColumn(name = "guild", referencedColumnName = "id")
|
||||
@ManyToOne(optional = false)
|
||||
private DiscordGuild guild;
|
||||
@ -126,6 +129,14 @@ public class Log implements Serializable {
|
||||
this.dateAdded = dateAdded;
|
||||
}
|
||||
|
||||
public byte[] getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
public void setException(byte[] exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public DiscordGuild getGuild() {
|
||||
return guild;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
||||
import net.dv8tion.jda.api.requests.ErrorResponse;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||
|
||||
public abstract class AbstractEvent {
|
||||
@ -48,7 +47,7 @@ public abstract class AbstractEvent {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public abstract void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands);
|
||||
public abstract void executeEvent(GuildMessageReceivedEvent event, List<String> commands);
|
||||
|
||||
|
||||
public abstract String help();
|
||||
|
@ -40,7 +40,6 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
@ -65,7 +64,7 @@ public class AdminPlaylistDeleteHandler extends AbstractAdminEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (!isAdmin(event)) return;
|
||||
|
||||
if (!checkCommands(event, commands, 2, "Must provide playlist and user's tag (in that order)")) return;
|
||||
@ -124,7 +123,7 @@ public class AdminPlaylistDeleteHandler extends AbstractAdminEventHandler {
|
||||
|
||||
@Override
|
||||
public String help() {
|
||||
return "delete";
|
||||
return "delete <playlist name> <user discord tag>";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
|
||||
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
|
||||
@Component
|
||||
@ -50,7 +49,7 @@ public class AdminPlaylistListHandler extends AbstractAdminEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (!isAdmin(event)) return;
|
||||
|
||||
List<GuildPlaylist> userPlaylist = guildRepoService.getGuildPlaylistRepo().findByGuildFetchSongs(event.getGuild().getIdLong());
|
||||
|
@ -36,7 +36,6 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.admin.AbstractAdminEventHandler;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -65,11 +64,11 @@ public class AdminPlaylistHandler extends AbstractMainEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (!isAdmin(event)) return;
|
||||
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
event.getChannel().sendMessage("Missing command for -playlist. Valid commands are: add, delete, list, play").queue();
|
||||
event.getChannel().sendMessage("Missing command for +playlist. Valid commands are: list, delete").queue();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@ -81,7 +80,7 @@ public class AdminPlaylistHandler extends AbstractMainEventHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
apeh.executeEvent(musicHandler, event, commands);
|
||||
apeh.executeEvent(event, commands);
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Unable to display playlist: " + ex.getMessage(), ex);
|
||||
|
@ -40,7 +40,6 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.ReactionHandler;
|
||||
import net.locusworks.discord.eighttrack.listeners.ReactionListener;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
@ -65,7 +64,7 @@ public class DeleteSongHandler extends AbstractMainEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if(!isAdmin(event)) return;
|
||||
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -45,14 +46,18 @@ public class NextSongHandler extends AbstractMainEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
public NextSongHandler() {
|
||||
super("-next");
|
||||
logger = ApplicationLoggerFactory.getLogger(NextSongHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
musicHandler.next(event, commands);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Unable to play next song: " + ex.getMessage(), ex);
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -45,14 +46,18 @@ public class PlaySongHandler extends AbstractMainEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
public PlaySongHandler() {
|
||||
super("-play");
|
||||
logger = ApplicationLoggerFactory.getLogger(PlaySongHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
musicHandler.play(event, commands);
|
||||
musicHandler.isPlaying(true);
|
||||
} catch (Exception ex) {
|
||||
|
@ -36,7 +36,6 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -65,7 +64,7 @@ public class PlaylistHandler extends AbstractMainEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
event.getChannel().sendMessage("Missing command for -playlist. Valid commands are: add, delete, list, play").queue();
|
||||
return;
|
||||
@ -79,7 +78,7 @@ public class PlaylistHandler extends AbstractMainEventHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
apeh.executeEvent(musicHandler, event, commands);
|
||||
apeh.executeEvent(event, commands);
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Unable to display playlist: " + ex.getMessage(), ex);
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -45,14 +46,18 @@ public class RepeatSongHandler extends AbstractMainEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
public RepeatSongHandler() {
|
||||
super("-repeat");
|
||||
logger = ApplicationLoggerFactory.getLogger(RepeatSongHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
musicHandler.repeat(event);
|
||||
musicHandler.isPlaying(true);
|
||||
} catch (Exception ex) {
|
||||
|
@ -34,7 +34,6 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -53,7 +52,7 @@ public class SongListHandler extends AbstractMainEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
listSongs(event, commands);
|
||||
} catch (Exception ex) {
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -45,14 +46,18 @@ public class StopSongHandler extends AbstractMainEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
public StopSongHandler() {
|
||||
super("-stop");
|
||||
logger = ApplicationLoggerFactory.getLogger(StopSongHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
musicHandler.isPlaying(false);
|
||||
musicHandler.stop(event);
|
||||
event.getGuild().getAudioManager().closeAudioConnection();
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -45,14 +46,18 @@ public class UpNextSongHandler extends AbstractMainEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService musicService;
|
||||
|
||||
public UpNextSongHandler() {
|
||||
super("-upnext");
|
||||
logger = ApplicationLoggerFactory.getLogger(UpNextSongHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
try {
|
||||
GuildMusicHandler musicHandler = musicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
musicHandler.repeat(event);
|
||||
musicHandler.isPlaying(true);
|
||||
} catch (Exception ex) {
|
||||
|
@ -49,7 +49,6 @@ import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.database.entities.GuildSong;
|
||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
@ -75,7 +74,7 @@ public class UploadHandler extends AbstractMainEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (!isAdmin(event)) return;
|
||||
|
||||
for(Attachment attachment : event.getMessage().getAttachments()) {
|
||||
|
@ -58,7 +58,7 @@ public class PlaylistAddHandler extends AbstractPlaylistEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if(!checkCommands(event, commands,
|
||||
event.getAuthor().getAsMention() + " you have to provide the playlist to create a new playlist (no spaces in name) and optionally a list of uuids for songs to add")) return;
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class PlaylistDeleteHandler extends AbstractPlaylistEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if(!checkCommands(event, commands,
|
||||
event.getAuthor().getAsMention() + " you have to provide the playlist name and optionally a list of uuids for songs to remove")) return;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class PlaylistListHandler extends AbstractPlaylistEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
List<GuildPlaylist> userPlaylist = guildRepoService.getGuildPlaylistRepo().findByGuildAndUserIdFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong());
|
||||
if (userPlaylist.isEmpty()) {
|
||||
|
@ -36,6 +36,7 @@ import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
|
||||
import net.locusworks.discord.eighttrack.database.entities.Song;
|
||||
import net.locusworks.discord.eighttrack.events.playlist.AbstractPlaylistEventHandler;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -46,6 +47,9 @@ public class PlaylistPlayHandler extends AbstractPlaylistEventHandler {
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
@Autowired
|
||||
private GuildMusicService guildMusicService;
|
||||
|
||||
private ApplicationLogger logger;
|
||||
public PlaylistPlayHandler() {
|
||||
super("play");
|
||||
@ -53,7 +57,7 @@ public class PlaylistPlayHandler extends AbstractPlaylistEventHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEvent(GuildMusicHandler musicHandler, GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void executeEvent(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue();
|
||||
return;
|
||||
@ -68,6 +72,8 @@ public class PlaylistPlayHandler extends AbstractPlaylistEventHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusicHandler musicHandler = guildMusicService.getMusicHandler(event.getGuild().getIdLong());
|
||||
|
||||
musicHandler.setCurrentPlaylist(currentPlaylist);
|
||||
|
||||
musicHandler.getTrackManager().clearTracks();
|
||||
|
@ -53,7 +53,6 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.events.main.AbstractMainEventHandler;
|
||||
import net.locusworks.discord.eighttrack.services.ConfigurationService;
|
||||
import net.locusworks.discord.eighttrack.services.GuildMusicService;
|
||||
import net.locusworks.discord.eighttrack.services.RepositoryService;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
@ -153,21 +152,13 @@ public class DiscordEventHandler extends ListenerAdapter {
|
||||
|
||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws Exception {
|
||||
|
||||
if (!GuildMusicService.getMap().containsKey(event.getGuild().getIdLong())) {
|
||||
GuildMusicService.getMap().put(event.getGuild().getIdLong(),
|
||||
new GuildMusicHandler(event.getGuild().getIdLong(), guildSongRepoService));
|
||||
}
|
||||
|
||||
GuildMusicHandler gmh = GuildMusicService.getMap().get(event.getGuild().getIdLong());
|
||||
gmh.accept((id) -> GuildMusicService.getMap().remove(id));
|
||||
|
||||
List<String> commands = new ArrayList<String>(Arrays.asList(event.getMessage().getContentRaw().trim().toLowerCase().split(" ")));
|
||||
|
||||
String command = commands.remove(0);
|
||||
|
||||
AbstractMainEventHandler aeh = events.get(command.toLowerCase());
|
||||
if (aeh != null) {
|
||||
aeh.executeEvent(gmh, event, commands);
|
||||
aeh.executeEvent(event, commands);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.handlers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -68,7 +67,7 @@ public class GuildMusicHandler {
|
||||
|
||||
private TrackManager trackManager;
|
||||
|
||||
public GuildMusicHandler(long guildId, RepositoryService guildSongRepoService) throws IOException {
|
||||
public GuildMusicHandler(long guildId, RepositoryService guildSongRepoService) {
|
||||
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
||||
this.playing = new AtomicBoolean(false);
|
||||
this.lastPlayed = OffsetDateTime.now();
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: DatabaseCleanupService.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* Copyright 2019-2020 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -27,11 +27,7 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.services;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -41,10 +37,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
|
||||
@Service
|
||||
public class DatabaseCleanupService {
|
||||
@ -59,58 +52,10 @@ public class DatabaseCleanupService {
|
||||
@Autowired
|
||||
private GuildRepository guildRepo;
|
||||
|
||||
private JDA client;
|
||||
|
||||
public void setClient(JDA client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close out connections that are no long being played. clean up resources
|
||||
*/
|
||||
@Scheduled(fixedRate = 5 * MINUTE)
|
||||
private void checkPlayers() {
|
||||
if (client == null) {
|
||||
logger.warn("Discord client is null. Unable to do cleanup");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("Checking players to see if anyone is listening");
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
for(Iterator<Entry<Long, GuildMusicHandler>> iterator = GuildMusicService.getMap().entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Long, GuildMusicHandler> entry = iterator.next();
|
||||
GuildMusicHandler gmh = entry.getValue();
|
||||
long guildId = entry.getKey();
|
||||
|
||||
Guild guild = client.getGuildById(guildId);
|
||||
if (guild == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
OffsetDateTime lastPlayed = gmh.getLastPlayed();
|
||||
Duration duration = Duration.between(lastPlayed, now);
|
||||
if (duration.toMillis() > 5 * MINUTE) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
Long voiceChannelId = gmh.getCurrentVoiceChannelId();
|
||||
if (voiceChannelId == null) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
} else {
|
||||
VoiceChannel vc = guild.getVoiceChannelById(voiceChannelId);
|
||||
if (vc != null && vc.getMembers().size() == 1) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = DAY)
|
||||
private void cleanDatabase() {
|
||||
JDA client = EightTrackService.getClient();
|
||||
|
||||
if (client == null) {
|
||||
logger.warn("Discord client is null. Unable to do cleanup");
|
||||
return;
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: EightTrackService.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* Copyright 2019-2020 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -44,7 +44,7 @@ public class EightTrackService {
|
||||
|
||||
private ApplicationLogger logger = ApplicationLoggerFactory.getLogger(EightTrackService.class);
|
||||
|
||||
private JDA client;
|
||||
private static JDA client;
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService confService;
|
||||
@ -52,17 +52,16 @@ public class EightTrackService {
|
||||
@Autowired
|
||||
private DiscordEventHandler eventListener;
|
||||
|
||||
@Autowired
|
||||
private DatabaseCleanupService dcs;
|
||||
|
||||
public void begin() throws LoginException {
|
||||
String token = confService.getDiscordToken();
|
||||
logger.debug("Logging in with token %s", token);
|
||||
|
||||
client = new JDABuilder(AccountType.BOT).setToken(token).build();
|
||||
client.addEventListener(eventListener);
|
||||
|
||||
dcs.setClient(client);
|
||||
}
|
||||
|
||||
public static JDA getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Project: Eight Track, File: GuildMusicService.java
|
||||
*
|
||||
* Copyright 2019-2019 Locusworks LLC.
|
||||
* Copyright 2019-2020 Locusworks LLC.
|
||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
||||
@ -27,17 +27,96 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.services;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
|
||||
import net.locusworks.discord.eighttrack.handlers.GuildMusicHandler;
|
||||
import net.locusworks.logger.ApplicationLogger;
|
||||
import net.locusworks.logger.ApplicationLoggerFactory;
|
||||
|
||||
@Service
|
||||
public class GuildMusicService {
|
||||
|
||||
private ApplicationLogger logger;
|
||||
|
||||
@Autowired
|
||||
private RepositoryService guildRepoService;
|
||||
|
||||
private static Map<Long, GuildMusicHandler> handlerMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<Long, GuildMusicHandler> getMap() {
|
||||
return handlerMap;
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
logger = ApplicationLoggerFactory.getLogger(GuildMusicService.class);
|
||||
for (DiscordGuild dg : guildRepoService.getGuildRepo().findAll()) {
|
||||
GuildMusicHandler gmh = new GuildMusicHandler(dg.getGuildId(), guildRepoService);
|
||||
gmh.accept((id) -> handlerMap.remove(id));
|
||||
handlerMap.put(dg.getGuildId(), gmh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close out connections that are no long being played. clean up resources
|
||||
*/
|
||||
@Scheduled(fixedRate = 5 * 60 * 1000)
|
||||
private void checkPlayers() {
|
||||
JDA client = EightTrackService.getClient();
|
||||
if (client == null) {
|
||||
logger.warn("Discord client is null. Unable to do cleanup");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("Checking players to see if anyone is listening");
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
for(Iterator<Entry<Long, GuildMusicHandler>> iterator = handlerMap.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Long, GuildMusicHandler> entry = iterator.next();
|
||||
GuildMusicHandler gmh = entry.getValue();
|
||||
long guildId = entry.getKey();
|
||||
|
||||
Guild guild = client.getGuildById(guildId);
|
||||
if (guild == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
OffsetDateTime lastPlayed = gmh.getLastPlayed();
|
||||
Duration duration = Duration.between(lastPlayed, now);
|
||||
if (duration.toMillis() > 5 * 60 * 1000) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
Long voiceChannelId = gmh.getCurrentVoiceChannelId();
|
||||
if (voiceChannelId == null) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
} else {
|
||||
VoiceChannel vc = guild.getVoiceChannelById(voiceChannelId);
|
||||
if (vc != null && vc.getMembers().size() == 1) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuildMusicHandler getMusicHandler(Long guildId) {
|
||||
if (!handlerMap.containsKey(guildId)) {
|
||||
GuildMusicHandler gmh = new GuildMusicHandler(guildId, guildRepoService);
|
||||
gmh.accept((id) -> handlerMap.remove(id));
|
||||
handlerMap.put(guildId, gmh);
|
||||
}
|
||||
|
||||
return handlerMap.get(guildId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,8 +27,8 @@
|
||||
*/
|
||||
package net.locusworks.discord.eighttrack.services;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Date;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -75,23 +75,24 @@ public class RepositoryService {
|
||||
if (dg == null) return;
|
||||
|
||||
String msg = String.format(msgFmt, args);
|
||||
if (ex != null) {
|
||||
msg += "\n" + printTrace(ex);
|
||||
}
|
||||
|
||||
Log log = new Log();
|
||||
log.setDateAdded(new Date());
|
||||
log.setGuild(dg);
|
||||
log.setIsException(ex != null);
|
||||
log.setLog(msg);
|
||||
|
||||
if (ex != null) {
|
||||
log.setException(printTrace(ex));
|
||||
}
|
||||
|
||||
|
||||
guildLogRepo.save(log);
|
||||
}
|
||||
|
||||
private String printTrace(Throwable ex) {
|
||||
StringWriter sw = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(sw));
|
||||
return sw.toString();
|
||||
private byte[] printTrace(Throwable ex) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ex.printStackTrace(new PrintWriter(baos));
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE eighttrack.log ADD exception longblob;
|
Reference in New Issue
Block a user