Main: Log various events to stdout.
This commit is contained in:
parent
76921f6855
commit
2345ddf17f
|
@ -7,6 +7,8 @@ package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import moe.nekojimi.chords.commands.*;
|
import moe.nekojimi.chords.commands.*;
|
||||||
|
@ -16,6 +18,7 @@ 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.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
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;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.api.managers.AudioManager;
|
import net.dv8tion.jda.api.managers.AudioManager;
|
||||||
|
@ -77,6 +80,7 @@ public class Main extends ListenerAdapter
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
|
log("INFO", "Starting up...");
|
||||||
downloader = new Downloader();
|
downloader = new Downloader();
|
||||||
downloader.setMessageHandler((Song song, Exception ex) ->
|
downloader.setMessageHandler((Song song, Exception ex) ->
|
||||||
{
|
{
|
||||||
|
@ -85,8 +89,10 @@ public class Main extends ListenerAdapter
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
if (ex == null)
|
if (ex == null)
|
||||||
if (song.getLocation() != null)
|
if (song.getLocation() != null)
|
||||||
|
{
|
||||||
channel.sendMessage(/*bracketNo + */"Finished downloading " + song + " for " + song.getRequestedBy() + ", added to queue!").queue();
|
channel.sendMessage(/*bracketNo + */"Finished downloading " + song + " for " + song.getRequestedBy() + ", added to queue!").queue();
|
||||||
else
|
log("DOWN", "Downloaded " + song);
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
Format format = song.getBestFormat();
|
Format format = song.getBestFormat();
|
||||||
String formatDetails = "";
|
String formatDetails = "";
|
||||||
|
@ -95,9 +101,13 @@ public class Main extends ListenerAdapter
|
||||||
formatDetails = " (" + format.getBitrate() / 1000 + "k, " + String.format("%.2f", format.getSize() / (1024.0 * 1024.0)) + "MiB)";
|
formatDetails = " (" + format.getBitrate() / 1000 + "k, " + String.format("%.2f", format.getSize() / (1024.0 * 1024.0)) + "MiB)";
|
||||||
}
|
}
|
||||||
channel.sendMessage(/*bracketNo + */"Now downloading " + song + formatDetails + " for " + song.getRequestedBy() + " ...").queue();
|
channel.sendMessage(/*bracketNo + */"Now downloading " + song + formatDetails + " for " + song.getRequestedBy() + " ...").queue();
|
||||||
|
log("DOWN", "Downloading " + song + "...");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
channel.sendMessage(/*bracketNo + */"Failed to download " + song + " for " + song.getRequestedBy() + "! Reason: " + ex.getMessage()).queue();
|
channel.sendMessage(/*bracketNo + */"Failed to download " + song + " for " + song.getRequestedBy() + "! Reason: " + ex.getMessage()).queue();
|
||||||
|
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml"));
|
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml"));
|
||||||
|
@ -111,6 +121,8 @@ public class Main extends ListenerAdapter
|
||||||
addCommand(new SkipCommand(this));
|
addCommand(new SkipCommand(this));
|
||||||
helpCommand = new HelpCommand(this);
|
helpCommand = new HelpCommand(this);
|
||||||
addCommand(helpCommand);
|
addCommand(helpCommand);
|
||||||
|
|
||||||
|
log("INFO", "Started OK!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCommand(Command command)
|
private void addCommand(Command command)
|
||||||
|
@ -123,6 +135,19 @@ public class Main extends ListenerAdapter
|
||||||
this.jda = jda;
|
this.jda = jda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event)
|
||||||
|
{
|
||||||
|
if (this.currentVoiceChannel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final VoiceChannel channelLeft = event.getChannelLeft();
|
||||||
|
|
||||||
|
if (channelLeft.getMembers().isEmpty())
|
||||||
|
if (channelLeft == currentVoiceChannel)
|
||||||
|
disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||||
{
|
{
|
||||||
|
@ -139,6 +164,8 @@ public class Main extends ListenerAdapter
|
||||||
if (author.isBot())
|
if (author.isBot())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String[] split = content.split("\\s+", 2);
|
String[] split = content.split("\\s+", 2);
|
||||||
|
@ -162,6 +189,7 @@ public class Main extends ListenerAdapter
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage("Error in command! " + ex.getMessage()).queue();
|
event.getChannel().sendMessage("Error in command! " + ex.getMessage()).queue();
|
||||||
|
log("UERR", "Command error:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +251,11 @@ public class Main extends ListenerAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void log(String type, String message)
|
||||||
|
{
|
||||||
|
System.out.println(type + " " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + "\t" + message);
|
||||||
|
}
|
||||||
|
|
||||||
public MusicHandler getMusicHandler()
|
public MusicHandler getMusicHandler()
|
||||||
{
|
{
|
||||||
return musicHandler;
|
return musicHandler;
|
||||||
|
|
Loading…
Reference in New Issue