Compare commits
No commits in common. "3f5ed0af08409710304441e773a3efa0dfb6dde9" and "e9ee8a575d890528940304997e9326e71c0edc53" have entirely different histories.
3f5ed0af08
...
e9ee8a575d
|
@ -7,8 +7,6 @@ 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.*;
|
||||||
|
@ -18,7 +16,6 @@ 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;
|
||||||
|
@ -80,7 +77,6 @@ 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) ->
|
||||||
{
|
{
|
||||||
|
@ -89,10 +85,8 @@ 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();
|
||||||
log("DOWN", "Downloaded " + song);
|
else
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
Format format = song.getBestFormat();
|
Format format = song.getBestFormat();
|
||||||
String formatDetails = "";
|
String formatDetails = "";
|
||||||
|
@ -101,13 +95,9 @@ 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"));
|
||||||
|
@ -121,8 +111,6 @@ 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)
|
||||||
|
@ -135,19 +123,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -164,8 +139,6 @@ 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);
|
||||||
|
@ -189,7 +162,6 @@ 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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,11 +223,6 @@ 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;
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2022 jimj316
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package moe.nekojimi.chords;
|
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jimj316
|
|
||||||
*/
|
|
||||||
public class Playlist
|
|
||||||
{
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final List<Song> songs = new ArrayList<>();
|
|
||||||
|
|
||||||
public Playlist(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlMapping toYaml()
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Playlist fromYaml(YamlMapping yaml)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSong(Song song)
|
|
||||||
{
|
|
||||||
song.setKept(true);
|
|
||||||
songs.add(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Song> getSongs()
|
|
||||||
{
|
|
||||||
return songs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -75,11 +75,6 @@ public class Song
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDownloaded()
|
|
||||||
{
|
|
||||||
return (location != null && location.exists() && location.canRead());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return title;
|
return title;
|
||||||
|
@ -196,4 +191,5 @@ public class Song
|
||||||
return formats.get(0);
|
return formats.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class JoinCommand extends Command
|
public class JoinCommand extends Command
|
||||||
|
@ -21,26 +23,11 @@ public class JoinCommand extends Command
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> args)
|
public void call(GuildMessageReceivedEvent event, List<String> args)
|
||||||
{
|
|
||||||
TextChannel textChannel = event.getChannel();
|
|
||||||
VoiceChannel channel = null;
|
|
||||||
if (args.isEmpty() || args.get(0).isBlank())
|
|
||||||
{
|
|
||||||
GuildVoiceState voiceState = event.getMember().getVoiceState();
|
|
||||||
if (voiceState != null && voiceState.inVoiceChannel())
|
|
||||||
channel = voiceState.getChannel();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Guild guild = event.getMessage().getGuild();
|
|
||||||
List<VoiceChannel> voiceChannels = guild.getVoiceChannels();
|
|
||||||
Optional<VoiceChannel> findFirst = voiceChannels.stream().filter((t) -> !t.getMembers().isEmpty()).findFirst();
|
|
||||||
channel = findFirst.orElseThrow(() -> new RuntimeException("Cannot find any voice channels with people in!"));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
String arg0 = args.get(0);
|
String arg0 = args.get(0);
|
||||||
Guild guild = event.getGuild();
|
Guild guild = event.getGuild();
|
||||||
boolean isNumber = arg0.matches("\\d+"); // This is a regular expression that ensures the input consists of digits
|
boolean isNumber = arg0.matches("\\d+"); // This is a regular expression that ensures the input consists of digits
|
||||||
|
VoiceChannel channel = null;
|
||||||
if (isNumber) // The input is an id?
|
if (isNumber) // The input is an id?
|
||||||
channel = guild.getVoiceChannelById(arg0);
|
channel = guild.getVoiceChannelById(arg0);
|
||||||
if (channel == null) // Then the input must be a name?
|
if (channel == null) // Then the input must be a name?
|
||||||
|
@ -50,13 +37,12 @@ public class JoinCommand extends Command
|
||||||
channel = channels.get(0); // We found a channel! This cannot be null.
|
channel = channels.get(0); // We found a channel! This cannot be null.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextChannel textChannel = event.getChannel();
|
||||||
if (channel == null) // I have no idea what you want mr user
|
if (channel == null) // I have no idea what you want mr user
|
||||||
{
|
{
|
||||||
onUnknownChannel(textChannel, arg0); // Let the user know about our failure
|
onUnknownChannel(textChannel, arg0); // Let the user know about our failure
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
bot.connectTo(channel); // We found a channel to connect to!
|
bot.connectTo(channel); // We found a channel to connect to!
|
||||||
onConnecting(channel, textChannel); // Let the user know, we were successful!
|
onConnecting(channel, textChannel); // Let the user know, we were successful!
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue