|
|
@ -5,22 +5,27 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package moe.nekojimi.chords; |
|
|
|
package moe.nekojimi.chords; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.amihaiemil.eoyaml.Yaml; |
|
|
|
|
|
|
|
import com.amihaiemil.eoyaml.YamlMapping; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FilenameFilter; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.function.Consumer; |
|
|
|
|
|
|
|
import java.util.logging.Level; |
|
|
|
|
|
|
|
import java.util.logging.Logger; |
|
|
|
import javax.security.auth.login.LoginException; |
|
|
|
import javax.security.auth.login.LoginException; |
|
|
|
import moe.nekojimi.chords.commands.*; |
|
|
|
import moe.nekojimi.chords.commands.*; |
|
|
|
import moe.nekojimi.musicsearcher.Result; |
|
|
|
|
|
|
|
import moe.nekojimi.musicsearcher.providers.MetaSearcher; |
|
|
|
import moe.nekojimi.musicsearcher.providers.MetaSearcher; |
|
|
|
import moe.nekojimi.musicsearcher.providers.Searcher; |
|
|
|
import moe.nekojimi.musicsearcher.providers.Searcher; |
|
|
|
import net.dv8tion.jda.api.JDA; |
|
|
|
import net.dv8tion.jda.api.JDA; |
|
|
|
import net.dv8tion.jda.api.JDABuilder; |
|
|
|
import net.dv8tion.jda.api.JDABuilder; |
|
|
|
import net.dv8tion.jda.api.MessageBuilder; |
|
|
|
|
|
|
|
import net.dv8tion.jda.api.entities.*; |
|
|
|
import net.dv8tion.jda.api.entities.*; |
|
|
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; |
|
|
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; |
|
|
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; |
|
|
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; |
|
|
@ -34,9 +39,12 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author jimj316 |
|
|
|
* @author jimj316 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Main extends ListenerAdapter |
|
|
|
public final class Main extends ListenerAdapter |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final File dataDirectory; |
|
|
|
|
|
|
|
private final File playlistsDirectory; |
|
|
|
|
|
|
|
|
|
|
|
private MusicHandler musicHandler; |
|
|
|
private MusicHandler musicHandler; |
|
|
|
private final Downloader downloader; |
|
|
|
private final Downloader downloader; |
|
|
|
private final Searcher searcher; |
|
|
|
private final Searcher searcher; |
|
|
@ -51,10 +59,12 @@ public class Main extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
|
|
private int trackNumber = 1; |
|
|
|
private int trackNumber = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Playlist> playlists = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param args the command line arguments |
|
|
|
* @param args the command line arguments |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void main(String[] args) throws LoginException |
|
|
|
public static void main(String[] args) throws LoginException, IOException |
|
|
|
{ |
|
|
|
{ |
|
|
|
// We only need 2 gateway intents enabled for this example:
|
|
|
|
// We only need 2 gateway intents enabled for this example:
|
|
|
|
EnumSet<GatewayIntent> intents = EnumSet.of( |
|
|
|
EnumSet<GatewayIntent> intents = EnumSet.of( |
|
|
@ -125,11 +135,19 @@ public class Main extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public Main() |
|
|
|
public Main() throws IOException |
|
|
|
{ |
|
|
|
{ |
|
|
|
log("INFO", "Starting up..."); |
|
|
|
log("INFO", "Starting up..."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init dirs
|
|
|
|
|
|
|
|
dataDirectory = new File(System.getProperty("user.dir")); |
|
|
|
|
|
|
|
playlistsDirectory = initDirectory(dataDirectory, "playlists"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init downloader
|
|
|
|
downloader = new Downloader(); |
|
|
|
downloader = new Downloader(); |
|
|
|
downloader.setMessageHandler(downloaderMessageHandler); |
|
|
|
downloader.setMessageHandler(downloaderMessageHandler); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init searcher
|
|
|
|
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml")); |
|
|
|
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml")); |
|
|
|
|
|
|
|
|
|
|
|
// init queue manager
|
|
|
|
// init queue manager
|
|
|
@ -147,6 +165,9 @@ public class Main extends ListenerAdapter |
|
|
|
helpCommand = new HelpCommand(this); |
|
|
|
helpCommand = new HelpCommand(this); |
|
|
|
addCommand(helpCommand); |
|
|
|
addCommand(helpCommand); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// load playlists
|
|
|
|
|
|
|
|
loadPlaylists(); |
|
|
|
|
|
|
|
|
|
|
|
log("INFO", "Started OK!"); |
|
|
|
log("INFO", "Started OK!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -329,6 +350,35 @@ public class Main extends ListenerAdapter |
|
|
|
System.out.println(type + " " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + "\t" + message); |
|
|
|
System.out.println(type + " " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + "\t" + message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public File initDirectory(File parent, String name) throws IOException |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
File ret = new File(parent, name); |
|
|
|
|
|
|
|
if (!ret.exists()) |
|
|
|
|
|
|
|
Files.createDirectories(ret.toPath()); |
|
|
|
|
|
|
|
if (!ret.canRead()) |
|
|
|
|
|
|
|
throw new RuntimeException("Cannot read directory " + ret.getAbsolutePath() + "!"); |
|
|
|
|
|
|
|
if (!ret.canWrite()) |
|
|
|
|
|
|
|
throw new RuntimeException("Cannot write to directory " + ret.getAbsolutePath() + "!"); |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadPlaylists() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
File[] files = playlistsDirectory.listFiles((File file, String name) -> name.endsWith(".yaml")); |
|
|
|
|
|
|
|
for (File file : files) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
YamlMapping map = Yaml.createYamlInput(file).readYamlMapping(); |
|
|
|
|
|
|
|
Playlist playlist = Playlist.fromYaml(map); |
|
|
|
|
|
|
|
playlists.put(playlist.getName(), playlist); |
|
|
|
|
|
|
|
} catch (IOException ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public MusicHandler getMusicHandler() |
|
|
|
public MusicHandler getMusicHandler() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return musicHandler; |
|
|
|
return musicHandler; |
|
|
@ -363,4 +413,5 @@ public class Main extends ListenerAdapter |
|
|
|
return trackNumber; |
|
|
|
return trackNumber; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|