Compare commits

..
7 Commits
Author SHA1 Message Date
John Grosh c49a559e34 play command accepts file uploads 2018-03-15 18:09:29 -05:00
John Grosh af98eb5e01 more minor updates 2018-03-13 05:46:31 -05:00
John Grosh e47c3efc58 dependency updates 2018-02-16 21:14:58 -05:00
John Grosh 058c3e18d2 added issue template 2018-02-07 17:00:36 -05:00
John Grosh 38ae19cbec little bugfixes 2018-02-07 16:33:26 -05:00
John Grosh 2eeffb374f dependency updates
more emojis
2018-02-07 11:07:37 -05:00
John Grosh e478fa43c8 perm and id fix 2017-12-18 11:48:30 -05:00
36 changed files with 276 additions and 162 deletions

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
[download]: https://github.com/jagrosh/MusicBot/releases/latest
[release]: https://img.shields.io/github/release/jagrosh/MusicBot.svg
[setup]: https://github.com/jagrosh/MusicBot/wiki/Setup
[rpi]: https://github.com/jagrosh/MusicBot/wiki/JMusicBot-on-Raspberry-Pi
[features]: https://github.com/jagrosh/MusicBot/projects/1
## General Troubleshooting
Please check off these steps before suggesting a feature or reporting a bug:
- [ ] I am running the [latest version][download]: [![Release][release]][download]
- [ ] I have followed all instructions on the [setup page][setup] (and if applicable, [Raspberry Pi][rpi])
- [ ] I have read through the [planned and suggested features][features]
## Issue
### Issue Type
- [ ] Bug Report
- [ ] Feature Request
### Description
Replace this with a description of your bug or feature request. Please provide screenshots and logs as applicable.
+6 -10
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<version>0.1.1</version>
<version>0.1.3</version>
<packaging>jar</packaging>
<repositories>
@@ -15,25 +15,21 @@
</repositories>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.3.1_316</version>
<version>3.5.1_348</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.2.45</version>
<version>1.2.56</version>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>JDA-Utilities</artifactId>
<version>1.9</version>
<artifactId>jda-utilities</artifactId>
<version>2.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
+18 -12
View File
@@ -27,15 +27,15 @@ import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.jagrosh.jdautilities.commandclient.Command.Category;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.waiter.EventWaiter;
import com.jagrosh.jdautilities.command.Command.Category;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.gui.GUI;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.jagrosh.jmusicbot.utils.Pair;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import java.util.Objects;
import javafx.util.Pair;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Game;
@@ -47,7 +47,7 @@ import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.ReadyEvent;
import net.dv8tion.jda.core.events.ShutdownEvent;
import net.dv8tion.jda.core.events.guild.GuildJoinEvent;
import net.dv8tion.jda.core.events.message.MessageDeleteEvent;
import net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import org.json.JSONException;
@@ -185,7 +185,7 @@ public class Bot extends ListenerAdapter {
}
@Override
public void onMessageDelete(MessageDeleteEvent event) {
public void onGuildMessageDelete(GuildMessageDeleteEvent event) {
if(lastNP.containsKey(event.getGuild().getIdLong()))
{
Pair<Long,Long> pair = lastNP.get(event.getGuild().getIdLong());
@@ -240,10 +240,12 @@ public class Bot extends ListenerAdapter {
}
}
public void shutdown(){
public void shutdown()
{
manager.shutdown();
threadpool.shutdownNow();
jda.getGuilds().stream().forEach(g -> {
jda.getGuilds().stream().forEach(g ->
{
g.getAudioManager().closeAudioConnection();
AudioHandler ah = (AudioHandler)g.getAudioManager().getSendingHandler();
if(ah!=null)
@@ -262,13 +264,15 @@ public class Bot extends ListenerAdapter {
}
@Override
public void onShutdown(ShutdownEvent event) {
public void onShutdown(ShutdownEvent event)
{
if(gui!=null)
gui.dispose();
}
@Override
public void onReady(ReadyEvent event) {
public void onReady(ReadyEvent event)
{
this.jda = event.getJDA();
if(jda.getGuilds().isEmpty())
{
@@ -277,7 +281,8 @@ public class Bot extends ListenerAdapter {
log.warn(event.getJDA().asBot().getInviteUrl(JMusicBot.RECOMMENDED_PERMS));
}
credit(event.getJDA());
jda.getGuilds().forEach((guild) -> {
jda.getGuilds().forEach((guild) ->
{
try
{
String defpl = getSettings(guild).getDefaultPlaylist();
@@ -293,7 +298,8 @@ public class Bot extends ListenerAdapter {
}
@Override
public void onGuildJoin(GuildJoinEvent event) {
public void onGuildJoin(GuildJoinEvent event)
{
credit(event.getJDA());
}
+43 -21
View File
@@ -25,27 +25,21 @@ import java.util.Scanner;
import javax.swing.JOptionPane;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author John Grosh (jagrosh)
*/
public class Config {
public class Config
{
private final static Logger LOG = LoggerFactory.getLogger(Config.class);
private boolean nogui;
private String prefix;
private String altprefix;
private String token;
private String owner;
private String success;
private String warning;
private String error;
private String game;
private String help;
private boolean stay;
private boolean dbots;
private boolean songingame;
private boolean useEval;
private boolean npimages;
private String configLocation = null;
private String prefix, altprefix, token, owner, success, warning, error, game,
help, loadingEmoji, searchingEmoji;
private boolean stay, dbots, songingame, useEval, npimages;
private long maxSeconds;
private OnlineStatus status = OnlineStatus.UNKNOWN;
@@ -53,9 +47,11 @@ public class Config {
{
this.nogui = nogui;
List<String> lines;
try {
try
{
configLocation = Paths.get("config.txt").toFile().getAbsolutePath();
lines = Files.readAllLines(Paths.get("config.txt"), StandardCharsets.UTF_8);
System.out.println("[INFO] Loading config: "+Paths.get("config.txt").toFile().getAbsolutePath());
//System.out.println("[INFO] Loading config: "+location);
for(String line: lines)
{
String[] parts = line.split("=",2);
@@ -84,6 +80,12 @@ public class Config {
case "error":
error = value;
break;
case "loading":
loadingEmoji = value;
break;
case "searching":
searchingEmoji = value;
break;
case "game":
game = value;
break;
@@ -115,8 +117,10 @@ public class Config {
break;
}
}
} catch (IOException ex) {
alert("'config.txt' was not found!");
}
catch (IOException ex)
{
alert("'config.txt' was not found at "+configLocation+"!");
lines = new LinkedList<>();
}
boolean write = false;
@@ -159,15 +163,23 @@ public class Config {
{
StringBuilder builder = new StringBuilder();
lines.stream().forEach(s -> builder.append(s).append("\r\n"));
try {
try
{
Files.write(Paths.get("config.txt"), builder.toString().trim().getBytes());
} catch(IOException ex) {
}
catch(IOException ex)
{
alert("Failed to write new config options to config.txt: "+ex
+ "\nPlease make sure that the files are not on your desktop or some other restricted area.");
}
}
}
public String getConfigLocation()
{
return configLocation;
}
public String getPrefix()
{
return prefix;
@@ -203,6 +215,16 @@ public class Config {
return error==null ? "\uD83D\uDEAB" : error;
}
public String getLoading()
{
return loadingEmoji==null ? "\u231A" : loadingEmoji;
}
public String getSearching()
{
return searchingEmoji==null ? "\uD83D\uDD0E" : searchingEmoji;
}
public Game getGame()
{
if(game==null || game.isEmpty())
@@ -17,10 +17,10 @@ package com.jagrosh.jmusicbot;
import java.awt.Color;
import javax.security.auth.login.LoginException;
import com.jagrosh.jdautilities.commandclient.CommandClient;
import com.jagrosh.jdautilities.commandclient.CommandClientBuilder;
import com.jagrosh.jdautilities.commandclient.examples.*;
import com.jagrosh.jdautilities.waiter.EventWaiter;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jdautilities.examples.command.*;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.*;
import com.jagrosh.jmusicbot.gui.GUI;
@@ -29,22 +29,24 @@ import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author John Grosh (jagrosh)
*/
public class JMusicBot {
public static Permission[] RECOMMENDED_PERMS = new Permission[]{Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
public class JMusicBot
{
public final static Permission[] RECOMMENDED_PERMS = new Permission[]{Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE, Permission.MESSAGE_EXT_EMOJI,
Permission.MANAGE_CHANNEL, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.NICKNAME_CHANGE};
public final static Logger LOG = LoggerFactory.getLogger("Startup");
/**
* @param args the command line arguments
*/
public static void main(String[] args){
public static void main(String[] args)
{
// check run mode(s)
boolean nogui = false;
for(String arg: args)
@@ -59,7 +61,7 @@ public class JMusicBot {
Bot bot = new Bot(waiter, config);
AboutCommand ab = new AboutCommand(Color.BLUE.brighter(),
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v0.1.1)",
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v0.1.3)",
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"},
RECOMMENDED_PERMS);
ab.setIsAuthor(false);
@@ -76,18 +78,19 @@ public class JMusicBot {
.setOwnerId(config.getOwnerId())
.setEmojis(config.getSuccess(), config.getWarning(), config.getError())
.setHelpWord(config.getHelp())
.setLinkedCacheSize(200)
.addCommands(
ab,
new PingCommand(),
new SettingsCmd(bot),
new NowplayingCmd(bot),
new PlayCmd(bot),
new PlayCmd(bot, config.getLoading()),
new PlaylistsCmd(bot),
new QueueCmd(bot),
new RemoveCmd(bot),
new SearchCmd(bot),
new SCSearchCmd(bot),
new SearchCmd(bot, config.getSearching()),
new SCSearchCmd(bot, config.getSearching()),
new ShuffleCmd(bot),
new SkipCmd(bot),
@@ -129,37 +132,44 @@ public class JMusicBot {
if(!config.getNoGui())
{
try {
try
{
GUI gui = new GUI(bot);
bot.setGUI(gui);
gui.init();
} catch(Exception e) {
LoggerFactory.getLogger("Startup").error("Could not start GUI. If you are "
}
catch(Exception e)
{
LOG.error("Could not start GUI. If you are "
+ "running on a server or in a location where you cannot display a "
+ "window, please run in nogui mode using the -nogui flag.");
}
}
LOG.info("Loaded config from "+config.getConfigLocation());
// attempt to log in and start
try {
try
{
new JDABuilder(AccountType.BOT)
.setToken(config.getToken())
.setAudioEnabled(true)
.setGame(nogame ? null : Game.of("loading..."))
.setGame(nogame ? null : Game.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE||config.getStatus()==OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListener(client)
.addEventListener(waiter)
.addEventListener(bot)
.buildAsync();
} catch (LoginException ex)
}
catch (LoginException ex)
{
LoggerFactory.getLogger("Startup").error(ex+"\nPlease make sure you are "
LOG.error(ex+"\nPlease make sure you are "
+ "editing the correct config.txt file, and that you have used the "
+ "correct token (not the 'secret'!)");
}
catch(IllegalArgumentException | RateLimitedException ex)
catch(IllegalArgumentException ex)
{
LoggerFactory.getLogger("Startup").error(""+ex);
LOG.error("Some aspect of the configuration is invalid: "+ex);
}
}
}
@@ -15,13 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.playlist.Playlist;
@@ -17,8 +17,8 @@ package com.jagrosh.jmusicbot.commands;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
/**
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.core.entities.User;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.Settings;
import com.jagrosh.jmusicbot.audio.AudioHandler;
@@ -51,7 +51,7 @@ public abstract class MusicCommand extends Command {
try {
event.getMessage().delete().queue();
} catch(PermissionException e){}
event.replyInDM(event.getClient().getError()+" You can only use that command in <#"+settings.getTextId()+">!");
event.replyInDm(event.getClient().getError()+" You can only use that command in <#"+settings.getTextId()+">!");
return;
}
if(bePlaying
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.Permission;
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.core.entities.User;
@@ -20,18 +20,16 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.waiter.EventWaiter;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.menu.ButtonMenu;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.playlist.Playlist;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Emote;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.core.exceptions.PermissionException;
/**
@@ -40,9 +38,14 @@ import net.dv8tion.jda.core.exceptions.PermissionException;
*/
public class PlayCmd extends MusicCommand
{
public PlayCmd(Bot bot)
public final static String LOAD = "\uD83D\uDCE5";
public final static String CANCEL = "\uD83D\uDEAB";
private final String loadingEmoji;
public PlayCmd(Bot bot, String loadingEmoji)
{
super(bot);
this.loadingEmoji = loadingEmoji;
this.name = "play";
this.arguments = "<title|URL|subcommand>";
this.help = "plays the provided song";
@@ -53,14 +56,14 @@ public class PlayCmd extends MusicCommand
@Override
public void doCommand(CommandEvent event) {
if(event.getArgs().isEmpty())
if(event.getArgs().isEmpty() && event.getMessage().getAttachments().isEmpty())
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
if(handler!=null && handler.getPlayer().getPlayingTrack()!=null && handler.getPlayer().isPaused())
{
boolean isDJ = event.getMember().hasPermission(Permission.MANAGE_SERVER);
if(!isDJ)
isDJ = event.isOwner() || event.isCoOwner();
isDJ = event.isOwner();
if(!isDJ)
isDJ = event.getMember().getRoles().contains(event.getGuild().getRoleById(bot.getSettings(event.getGuild()).getRoleId()));
if(!isDJ)
@@ -82,8 +85,8 @@ public class PlayCmd extends MusicCommand
}
String args = event.getArgs().startsWith("<") && event.getArgs().endsWith(">")
? event.getArgs().substring(1,event.getArgs().length()-1)
: event.getArgs();
event.reply("\u231A Loading... `["+args+"]`", m -> bot.getAudioManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false)));
: event.getArgs().isEmpty() ? event.getMessage().getAttachments().get(0).getUrl() : event.getArgs();
event.reply(loadingEmoji+" Loading... `["+args+"]`", m -> bot.getAudioManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false)));
}
private class ResultHandler implements AudioLoadResultHandler
@@ -110,27 +113,25 @@ public class PlayCmd extends MusicCommand
int pos = bot.queueTrack(event, track)+1;
String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos));
if(playlist==null)
if(playlist==null || !event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ADD_REACTION))
m.editMessage(addMsg).queue();
else
{
m.editMessage(addMsg+"\n"+event.getClient().getWarning()+" This track has a playlist of **"+playlist.getTracks().size()+"** tracks attached. Load playlist?")
.queue(m ->
new ButtonMenu.Builder()
.setText(addMsg+"\n"+event.getClient().getWarning()+" This track has a playlist of **"+playlist.getTracks().size()+"** tracks attached. Select "+LOAD+" to load playlist.")
.setChoices(LOAD, CANCEL)
.setEventWaiter(bot.getWaiter())
.setTimeout(30, TimeUnit.SECONDS)
.setAction(re ->
{
Emote emote = event.getJDA().getEmoteById(event.getClient().getSuccess().replaceAll("<:.+:(\\d+)>", "$1"));
if(emote == null)
m.addReaction(event.getClient().getSuccess()).queue();
if(re.getName().equals(LOAD))
m.editMessage(addMsg+"\n"+event.getClient().getSuccess()+" Loaded **"+loadPlaylist(playlist, track)+"** additional tracks!").queue();
else
m.addReaction(emote).queue();
bot.getWaiter().waitForEvent(MessageReactionAddEvent.class,
e -> e.getMessageIdLong()==m.getIdLong() && e.getUser().getIdLong()==event.getAuthor().getIdLong(),
e ->
{
m.editMessage(addMsg+"\n"+event.getClient().getSuccess()+" Loaded **"+loadPlaylist(playlist, track)+"** additional tracks!").queue();
try{m.clearReactions().queue();}catch(PermissionException ex){}
},
2, TimeUnit.MINUTES, () -> {try{m.clearReactions().queue();}catch(PermissionException e){}});
});
m.editMessage(addMsg).queue();
}).setFinalAction(m ->
{
try{m.clearReactions().queue();}catch(PermissionException ex){}
}).build().display(m);
}
}
@@ -230,7 +231,7 @@ public class PlayCmd extends MusicCommand
event.reply(event.getClient().getError()+" I could not find `"+event.getArgs()+".txt` in the Playlists folder.");
return;
}
event.getChannel().sendMessage("\u231A Loading playlist **"+event.getArgs()+"**... ("+playlist.getItems().size()+" items)").queue(m -> {
event.getChannel().sendMessage(loadingEmoji+" Loading playlist **"+event.getArgs()+"**... ("+playlist.getItems().size()+" items)").queue(m -> {
playlist.loadTracks(bot.getAudioManager(), (at)->bot.queueTrack(event, at), () -> {
StringBuilder builder = new StringBuilder(playlist.getTracks().isEmpty()
? event.getClient().getWarning()+" No tracks were loaded!"
@@ -20,8 +20,8 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.playlist.Playlist;
@@ -16,7 +16,7 @@
package com.jagrosh.jmusicbot.commands;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.playlist.Playlist;
@@ -17,8 +17,8 @@ package com.jagrosh.jmusicbot.commands;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.menu.pagination.PaginatorBuilder;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.menu.Paginator;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
@@ -32,7 +32,7 @@ import net.dv8tion.jda.core.exceptions.PermissionException;
*/
public class QueueCmd extends MusicCommand {
private final PaginatorBuilder builder;
private final Paginator.Builder builder;
public QueueCmd(Bot bot)
{
super(bot);
@@ -42,7 +42,7 @@ public class QueueCmd extends MusicCommand {
this.aliases = new String[]{"list"};
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS};
builder = new PaginatorBuilder()
builder = new Paginator.Builder()
.setColumns(1)
.setFinalAction(m -> {try{m.clearReactions().queue();}catch(PermissionException e){}})
.setItemsPerPage(10)
@@ -76,7 +76,7 @@ public class QueueCmd extends MusicCommand {
songs[i] = list.get(i).toString();
}
long fintotal = total;
builder.setText((i1,i2) -> getQueueTitle(ah, event.getClient().getSuccess(), songs.length, fintotal, bot.getSettings(event.getGuild()).getRepeatMode()))
builder.setText((i1,i2) -> event.getClient().getSuccess()+" "+getQueueTitle(ah, event.getClient().getSuccess(), songs.length, fintotal, bot.getSettings(event.getGuild()).getRepeatMode()))
.setItems(songs)
.setUsers(event.getAuthor())
.setColor(event.getSelfMember().getColor())
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
/**
@@ -21,8 +21,8 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import java.util.concurrent.TimeUnit;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.menu.orderedmenu.OrderedMenuBuilder;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.menu.OrderedMenu;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -35,17 +35,19 @@ import net.dv8tion.jda.core.entities.Message;
*/
public class SCSearchCmd extends MusicCommand {
private final OrderedMenuBuilder builder;
public SCSearchCmd(Bot bot)
private final OrderedMenu.Builder builder;
private final String searchingEmoji;
public SCSearchCmd(Bot bot, String searchingEmoji)
{
super(bot);
this.searchingEmoji = searchingEmoji;
this.name = "scsearch";
this.arguments = "<query>";
this.help = "searches Soundcloud for a provided query";
this.beListening = true;
this.bePlaying = false;
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
builder = new OrderedMenuBuilder()
builder = new OrderedMenu.Builder()
.allowTextInput(true)
.useNumbers()
.useCancelButton(true)
@@ -60,7 +62,7 @@ public class SCSearchCmd extends MusicCommand {
event.reply(event.getClient().getError()+" Please include a query.");
return;
}
event.reply("\uD83D\uDD0E Searching... `["+event.getArgs()+"]`",m -> bot.getAudioManager().loadItemOrdered(event.getGuild(), "scsearch:"+event.getArgs(), new ResultHandler(m,event)));
event.reply(searchingEmoji+" Searching... `["+event.getArgs()+"]`",m -> bot.getAudioManager().loadItemOrdered(event.getGuild(), "scsearch:"+event.getArgs(), new ResultHandler(m,event)));
}
private class ResultHandler implements AudioLoadResultHandler {
@@ -91,7 +93,7 @@ public class SCSearchCmd extends MusicCommand {
builder.setColor(event.getSelfMember().getColor())
.setText(FormatUtil.filter(event.getClient().getSuccess()+" Search results for `"+event.getArgs()+"`:"))
.setChoices(new String[0])
.setAction(i -> {
.setSelection((msg, i) -> {
AudioTrack track = playlist.getTracks().get(i-1);
if(AudioHandler.isTooLong(track))
{
@@ -104,7 +106,7 @@ public class SCSearchCmd extends MusicCommand {
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0 ? "to begin playing"
: " to the queue at position "+pos));
})
.setCancel(() -> {})
.setCancel((msg) -> {})
.setUsers(event.getAuthor())
;
for(int i=0; i<4&&i<playlist.getTracks().size(); i++)
@@ -21,8 +21,8 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import java.util.concurrent.TimeUnit;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.menu.orderedmenu.OrderedMenuBuilder;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.menu.OrderedMenu;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -35,10 +35,12 @@ import net.dv8tion.jda.core.entities.Message;
*/
public class SearchCmd extends MusicCommand {
private final OrderedMenuBuilder builder;
public SearchCmd(Bot bot)
private final OrderedMenu.Builder builder;
private final String searchingEmoji;
public SearchCmd(Bot bot, String searchingEmoji)
{
super(bot);
this.searchingEmoji = searchingEmoji;
this.name = "search";
this.aliases = new String[]{"ytsearch"};
this.arguments = "<query>";
@@ -46,7 +48,7 @@ public class SearchCmd extends MusicCommand {
this.beListening = true;
this.bePlaying = false;
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
builder = new OrderedMenuBuilder()
builder = new OrderedMenu.Builder()
.allowTextInput(true)
.useNumbers()
.useCancelButton(true)
@@ -61,7 +63,7 @@ public class SearchCmd extends MusicCommand {
event.reply(event.getClient().getError()+" Please include a query.");
return;
}
event.reply("\uD83D\uDD0E Searching... `["+event.getArgs()+"]`",m ->bot.getAudioManager().loadItemOrdered(event.getGuild(), "ytsearch:"+event.getArgs(), new ResultHandler(m,event)));
event.reply(searchingEmoji+" Searching... `["+event.getArgs()+"]`",m ->bot.getAudioManager().loadItemOrdered(event.getGuild(), "ytsearch:"+event.getArgs(), new ResultHandler(m,event)));
}
private class ResultHandler implements AudioLoadResultHandler {
@@ -88,11 +90,12 @@ public class SearchCmd extends MusicCommand {
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
public void playlistLoaded(AudioPlaylist playlist)
{
builder.setColor(event.getSelfMember().getColor())
.setText(FormatUtil.filter(event.getClient().getSuccess()+" Search results for `"+event.getArgs()+"`:"))
.setChoices(new String[0])
.setAction(i -> {
.setSelection((msg,i) -> {
AudioTrack track = playlist.getTracks().get(i-1);
if(AudioHandler.isTooLong(track))
{
@@ -105,7 +108,7 @@ public class SearchCmd extends MusicCommand {
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0 ? "to begin playing"
: " to the queue at position "+pos));
})
.setCancel(() -> {})
.setCancel((msg) -> {})
.setUsers(event.getAuthor())
;
for(int i=0; i<4&&i<playlist.getTracks().size(); i++)
@@ -18,8 +18,8 @@ package com.jagrosh.jmusicbot.commands;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import net.dv8tion.jda.core.entities.Icon;
@@ -16,8 +16,8 @@
package com.jagrosh.jmusicbot.commands;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.utils.FinderUtil;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import net.dv8tion.jda.core.entities.Game;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import net.dv8tion.jda.core.OnlineStatus;
@@ -16,8 +16,8 @@
package com.jagrosh.jmusicbot.commands;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.utils.FinderUtil;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.Settings;
import net.dv8tion.jda.core.EmbedBuilder;
@@ -16,8 +16,8 @@
package com.jagrosh.jmusicbot.commands;
import java.util.List;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.utils.FinderUtil;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
/**
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.core.entities.User;
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.core.entities.User;
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
@@ -15,7 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.utils.FormatUtil;
@@ -1,11 +1,20 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* Copyright 2018 John Grosh (jagrosh).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jagrosh.jmusicbot.playlist;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
@@ -95,6 +95,8 @@ public class FormatUtil {
long userid = handler.getRequester();
AudioTrack track = handler.getPlayer().getPlayingTrack();
String title = track.getInfo().title;
if(title==null || title.equals("Unknown Title"))
title = track.getInfo().uri;
return "**"+title+"** ["+(userid==0 ? "autoplay" : "<@"+userid+">")+"]"
+ "\n"+(handler.getPlayer().isPaused()?"\u23F8":"\u25B6")+" "
+"["+formatTime(track.getDuration())+"] "
@@ -0,0 +1,44 @@
/*
* Copyright 2018 John Grosh <john.a.grosh@gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jagrosh.jmusicbot.utils;
/**
*
* @author John Grosh (john.a.grosh@gmail.com)
* @param <K>
* @param <V>
*/
public class Pair<K,V>
{
private final K key;
private final V value;
public Pair(K key, V value)
{
this.key = key;
this.value = value;
}
public K getKey()
{
return key;
}
public V getValue()
{
return value;
}
}