Compare commits

...
11 Commits
Author SHA1 Message Date
John Grosh c0d40b2594 Merge origin/master 2019-06-10 18:35:49 -04:00
John Grosh 327cfe7d21 Update README.md 2019-06-07 14:48:26 -04:00
John Grosh b4e83fd3f0 Merge origin/master
also minor edits
Conflicts:
	pom.xml
2019-05-29 22:26:51 -04:00
John Grosh c902c1eace Merge pull request #225 from Sanduhr32/patch-1
Fixing news/store channels issue
2019-05-22 14:05:55 -04:00
M R S E 39a787c3c9 Dont go to insane on JDAs version
Also bump version
2019-05-05 16:55:18 +02:00
M R S E cdc20ce500 Fixing news/store channels issue 2019-05-05 16:52:51 +02:00
John Grosh 7dcd7badb3 Merge pull request #218 from SlapGaming/pullreqs
Move track command
2019-04-09 15:34:59 -04:00
Rick Fontein 1a0a73ac7c PR feedback pass 2 2019-04-09 20:56:16 +02:00
Rick Fontein eb1fb776a5 PR feedback pass 2019-04-08 20:38:59 +02:00
Rick Fontein 82349d380b Move track command
Adds support for moving a track in queue.
2019-04-07 00:12:21 +02:00
John Grosh 3c5deca55e improved config flow and autowrite full config 2019-03-16 16:29:09 -05:00
8 changed files with 150 additions and 28 deletions

No files matched your search

+1 -3
View File
@@ -38,7 +38,5 @@ Please see the [Setup Page](https://github.com/jagrosh/MusicBot/wiki/Setup) in t
## Questions/Suggestions/Bug Reports
**Please read the [Suggested/Planned Features List](https://github.com/jagrosh/MusicBot/projects/1) before suggesting a feature**. If you'd like to suggest changes to how the bot functions, recommend more customization options, or report bugs, feel free to either open an [Issue](https://github.com/jagrosh/MusicBot/issues) on this repository, or join [my Discord server](https://discord.gg/0p9LSGoRLu6Pet0k). (Note: I will not accept any feature requests that will require additional API keys, nor any non-music features). If you like this bot, be sure to add a star to the libraries that make this possible: [**JDA**](https://github.com/DV8FromTheWorld/JDA) and [**lavaplayer**](https://github.com/sedmelluq/lavaplayer)
## Editing
This bot (and the source code here) is not meant to be edited. The main purpose of having the source public is to show the capabilities of the libraries, and to allow others to understand how the bot works. There are many requirements and dependencies required to edit and compile it, and there will not be support provided for people looking to make changes on their own. Instead, consider making a feature request (see the above section). If you still choose to make edits, please do so in accordance with the Apache 2.0 License.
This bot (and the source code here) might not be easy to edit for inexperienced programmers. The main purpose of having the source public is to show the capabilities of the libraries, to allow others to understand how the bot works, and to allow those knowledgeable about java, JDA, and Discord bot development to contribute. There are many requirements and dependencies required to edit and compile it, and there will not be support provided for people looking to make changes on their own. Instead, consider making a feature request (see the above section). If you choose to make edits, please do so in accordance with the Apache 2.0 License.
+4 -4
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<packaging>jar</packaging>
<repositories>
@@ -23,12 +23,12 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.8.1_454</version>
<version>3.8.3_463</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.10</version>
<version>1.3.17</version>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
@@ -112,4 +112,4 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
</project>
@@ -24,15 +24,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
/**
* @author Your Name
* Changes from original source:
* - Changed "searching" to "finding"
*
*
* @author John Grosh (jagrosh)
@@ -41,6 +36,8 @@ public class BotConfig
{
private final Prompt prompt;
private final static String CONTEXT = "Config";
private final static String START_TOKEN = "/// START OF JMUSICBOT CONFIG ///";
private final static String END_TOKEN = "/// END OF JMUSICBOT CONFIG ///";
private Path path = null;
private String token, prefix, altprefix, helpWord, playlistsFolder,
@@ -99,8 +96,8 @@ public class BotConfig
playlistsFolder = config.getString("playlistsfolder");
dbots = owner == 113156185389092864L;
// we may need to get some additional data and write a new config file
List<String> lines = new LinkedList<>();
// we may need to write a new config file
boolean write = false;
// validate bot token
if(token==null || token.isEmpty() || token.equalsIgnoreCase("BOT_TOKEN_HERE"))
@@ -116,7 +113,7 @@ public class BotConfig
}
else
{
lines.add("token = "+token);
write = true;
}
}
@@ -142,17 +139,28 @@ public class BotConfig
}
else
{
lines.add("owner = "+owner);
write = true;
}
}
if(!lines.isEmpty())
if(write)
{
StringBuilder builder = new StringBuilder();
lines.stream().forEach(s -> builder.append(s).append("\r\n"));
String original = OtherUtil.loadResource(this, "/reference.conf");
byte[] bytes;
if(original==null)
{
bytes = ("token = "+token+"\r\nowner = "+owner).getBytes();
}
else
{
bytes = original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN))
.replace("BOT_TOKEN_HERE", token)
.replace("0 // OWNER ID", Long.toString(owner))
.trim().getBytes();
}
try
{
Files.write(path, builder.toString().trim().getBytes());
Files.write(path, bytes);
}
catch(IOException ex)
{
@@ -114,6 +114,7 @@ public class JMusicBot
new SkipCmd(bot),
new ForceskipCmd(bot),
new MoveTrackCmd(bot),
new PauseCmd(bot),
new PlaynextCmd(bot, config.getLoading()),
new RepeatCmd(bot),
@@ -182,14 +183,15 @@ public class JMusicBot
}
catch (LoginException ex)
{
log.error(ex+"\nPlease make sure you are "
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are "
+ "editing the correct config.txt file, and that you have used the "
+ "correct token (not the 'secret'!)");
+ "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
System.exit(1);
}
catch(IllegalArgumentException ex)
{
log.error("Some aspect of the configuration is invalid: "+ex);
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is "
+ "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
System.exit(1);
}
}
@@ -0,0 +1,85 @@
package com.jagrosh.jmusicbot.commands.dj;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.commands.DJCommand;
import com.jagrosh.jmusicbot.queue.FairQueue;
/**
* Command that provides users the ability to move a track in the playlist.
*/
public class MoveTrackCmd extends DJCommand
{
public MoveTrackCmd(Bot bot)
{
super(bot);
this.name = "movetrack";
this.help = "move a track in the current queue to a different position";
this.arguments = "<from> <to>";
this.aliases = new String[]{"move"};
this.bePlaying = true;
}
@Override
public void doCommand(CommandEvent event)
{
int from;
int to;
String[] parts = event.getArgs().split("\\s+", 2);
if(parts.length < 2)
{
event.replyError("Please include two valid indexes.");
return;
}
try
{
// Validate the args
from = Integer.parseInt(parts[0]);
to = Integer.parseInt(parts[1]);
}
catch (NumberFormatException e)
{
event.replyError("Please provide two valid indexes.");
return;
}
if (from == to)
{
event.replyError("Can't move a track to the same position.");
return;
}
// Validate that from and to are available
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
FairQueue<QueuedTrack> queue = handler.getQueue();
if (isUnavailablePosition(queue, from))
{
String reply = String.format("`%d` is not a valid position in the queue!", from);
event.replyError(reply);
return;
}
if (isUnavailablePosition(queue, to))
{
String reply = String.format("`%d` is not a valid position in the queue!", to);
event.replyError(reply);
return;
}
// Move the track
QueuedTrack track = queue.moveItem(from - 1, to - 1);
String trackTitle = track.getTrack().getInfo().title;
String reply = String.format("Moved **%s** from position `%d` to `%d`.", trackTitle, from, to);
event.replySuccess(reply);
}
private static boolean isUnavailablePosition(FairQueue<QueuedTrack> queue, int position)
{
return (position < 1 || position > queue.size());
}
}
@@ -128,4 +128,17 @@ public class FairQueue<T extends Queueable> {
for(int i=0; i<number; i++)
list.remove(0);
}
/**
* Move an item to a different position in the list
* @param from The position of the item
* @param to The new position of the item
* @return the moved item
*/
public T moveItem(int from, int to)
{
T item = list.remove(from);
list.add(to, item);
return item;
}
}
@@ -17,9 +17,7 @@ package com.jagrosh.jmusicbot.utils;
import com.jagrosh.jmusicbot.JMusicBot;
import com.jagrosh.jmusicbot.entities.Prompt;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import net.dv8tion.jda.core.OnlineStatus;
@@ -40,6 +38,20 @@ public class OtherUtil
+ "New Version: %s\n\n"
+ "Please visit https://github.com/jagrosh/MusicBot/releases/latest to get the latest release.";
public static String loadResource(Object clazz, String name)
{
try(BufferedReader reader = new BufferedReader(new InputStreamReader(clazz.getClass().getResourceAsStream(name))))
{
StringBuilder sb = new StringBuilder();
reader.lines().forEach(line -> sb.append("\r\n").append(line));
return sb.toString().trim();
}
catch(IOException ex)
{
return null;
}
}
public static InputStream imageFromUrl(String url)
{
if(url==null)
+6 -2
View File
@@ -1,3 +1,4 @@
/// START OF JMUSICBOT CONFIG ///
/////////////////////////////////////////////////////////
// Config for the JMusicBot //
/////////////////////////////////////////////////////////
@@ -20,7 +21,7 @@ token = BOT_TOKEN_HERE
// This needs to be the owner's ID (a 17-18 digit number)
// https://github.com/jagrosh/MusicBot/wiki/Finding-Your-User-ID
owner = 0
owner = 0 // OWNER ID
// This sets the prefix for the bot
@@ -119,7 +120,7 @@ updatealerts=true
// If you are interested in contributing a provider, please see
// https://github.com/jagrosh/JLyrics
lyrics.default = "MusicMatch"
lyrics.default = "A-Z Lyrics"
// If you set this to true, it will enable the eval command for the bot owner. This command
@@ -134,3 +135,6 @@ lyrics.default = "MusicMatch"
// IF SOMEONE ASKS YOU TO ENABLE THIS, THERE IS AN 11/10 CHANCE THEY ARE TRYING TO SCAM YOU
eval=false
/// END OF JMUSICBOT CONFIG ///