mirror of
https://github.com/chrisb09/MusicBot.git
synced 2026-11-05 17:02:35 -05:00
Compare commits
8
Commits
0.0.1
...
0.0.2-patch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d87b6aa505 | ||
|
|
269dd7e0a7 | ||
|
|
f9c55ee567 | ||
|
|
8192f7a0bb | ||
|
|
5b5afe7aa8 | ||
|
|
c0dfabf0f8 | ||
|
|
2491fba863 | ||
|
|
f3d16556ff |
No files matched your search
@@ -1,5 +1,22 @@
|
||||
# Spectra-Music
|
||||
# JMusicBot
|
||||
A Discord music bot with a clean interface, and that is easy to set up and run yourself
|
||||
|
||||
## Note:
|
||||
This project is currently in early stages of development. If you are having trouble setting it up, or feel that it isn't complete, that's because it is not fully supported yet.
|
||||
# Features
|
||||
* Easy to run (just make sure Java is installed, and run!)
|
||||
* Fast loading of songs
|
||||
* No external keys needed (besides a Discord Bot token)
|
||||
* Smooth playback
|
||||
* Server-specific setup for the "DJ" role that can moderate the music
|
||||
* Clean and beautiful menus
|
||||
* Channel-topic playback bar
|
||||
* Supports many sites, including Youtube, Soundcloud, and more
|
||||
* Playlist support
|
||||
|
||||
# Setup
|
||||
Please see the [Setup Page](https://github.com/jagrosh/MusicBot/wiki/Setup) in the wiki to run this bot yourself!
|
||||
|
||||
# Questions/Suggestions/Bug Reports
|
||||
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). 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)
|
||||
|
||||
# Example
|
||||

|
||||
@@ -63,6 +63,8 @@ public class Bot extends ListenerAdapter {
|
||||
public final Category MUSIC = new Category("Music");
|
||||
public final Category DJ = new Category("DJ", event ->
|
||||
{
|
||||
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
|
||||
return true;
|
||||
if(event.getGuild()==null)
|
||||
return true;
|
||||
if(PermissionUtil.checkPermission(event.getGuild(), event.getMember(), Permission.MANAGE_SERVER))
|
||||
@@ -72,6 +74,8 @@ public class Bot extends ListenerAdapter {
|
||||
});
|
||||
public final Category ADMIN = new Category("Admin", event ->
|
||||
{
|
||||
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
|
||||
return true;
|
||||
if(event.getGuild()==null)
|
||||
return true;
|
||||
return PermissionUtil.checkPermission(event.getGuild(), event.getMember(), Permission.MANAGE_SERVER);
|
||||
@@ -141,9 +145,9 @@ public class Bot extends ListenerAdapter {
|
||||
if(tchan.getTopic()==null || tchan.getTopic().isEmpty())
|
||||
otherText = "";
|
||||
else if(tchan.getTopic().contains("\u200B"))
|
||||
otherText = tchan.getTopic().substring(tchan.getTopic().indexOf("\u200B")).trim();
|
||||
otherText = tchan.getTopic().substring(tchan.getTopic().indexOf("\u200B"));
|
||||
else
|
||||
otherText = "\n\u200B "+tchan.getTopic();
|
||||
otherText = "\u200B\n "+tchan.getTopic();
|
||||
String text = FormatUtil.formattedAudio(handler, guild.getJDA(), true)+otherText;
|
||||
if(!text.equals(tchan.getTopic()))
|
||||
tchan.getManager().setTopic(text).queue();
|
||||
|
||||
@@ -26,6 +26,7 @@ import me.jagrosh.jmusicbot.gui.GUI;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
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 net.dv8tion.jda.core.utils.SimpleLog;
|
||||
@@ -53,6 +54,8 @@ public class JMusicBot {
|
||||
EventWaiter waiter = new EventWaiter();
|
||||
Bot bot = new Bot(waiter);
|
||||
|
||||
AboutCommand.IS_AUTHOR = false;
|
||||
|
||||
// set up the command client
|
||||
CommandClient client = new CommandClientBuilder()
|
||||
.setPrefix(config.getPrefix())
|
||||
@@ -61,8 +64,10 @@ public class JMusicBot {
|
||||
.addCommands(
|
||||
new AboutCommand(Color.BLUE.brighter(),
|
||||
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot)",
|
||||
"https://github.com/jagrosh/MusicBot",
|
||||
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"}),
|
||||
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"},
|
||||
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),
|
||||
new PingCommand(),
|
||||
new SettingsCmd(bot),
|
||||
|
||||
@@ -71,9 +76,11 @@ public class JMusicBot {
|
||||
new QueueCmd(bot),
|
||||
new RemoveCmd(bot),
|
||||
new SearchCmd(bot),
|
||||
new ShuffleCmd(bot),
|
||||
new SkipCmd(bot),
|
||||
|
||||
new ForceskipCmd(bot),
|
||||
new SkiptoCmd(bot),
|
||||
new StopCmd(bot),
|
||||
new VolumeCmd(bot),
|
||||
|
||||
@@ -81,7 +88,9 @@ public class JMusicBot {
|
||||
new SettcCmd(bot),
|
||||
new SetvcCmd(bot),
|
||||
|
||||
new GuildlistCommand(waiter),
|
||||
new SetavatarCmd(bot),
|
||||
new SetgameCmd(bot),
|
||||
new SetnameCmd(bot),
|
||||
new ShutdownCmd(bot)
|
||||
).build();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
||||
{
|
||||
current = qt;
|
||||
audioPlayer.playTrack(track);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class MusicCommand extends Command {
|
||||
+" to use that!");
|
||||
return;
|
||||
}
|
||||
if(current==null)
|
||||
if(!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel())
|
||||
event.getGuild().getAudioManager().openAudioConnection(userState.getChannel());
|
||||
}
|
||||
doCommand(event);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2017 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 me.jagrosh.jmusicbot.commands;
|
||||
|
||||
import me.jagrosh.jdautilities.commandclient.Command;
|
||||
import me.jagrosh.jdautilities.commandclient.CommandEvent;
|
||||
import me.jagrosh.jmusicbot.Bot;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh <john.a.grosh@gmail.com>
|
||||
*/
|
||||
public class SetgameCmd extends Command {
|
||||
|
||||
public SetgameCmd(Bot bot)
|
||||
{
|
||||
this.name = "setgame";
|
||||
this.help = "sets the game the bot is playing";
|
||||
this.arguments = "[game]";
|
||||
this.ownerCommand = true;
|
||||
this.category = bot.OWNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(CommandEvent event) {
|
||||
try {
|
||||
event.getJDA().getPresence().setGame(event.getArgs().isEmpty() ? null : Game.of(event.getArgs()));
|
||||
event.reply(event.getClient().getSuccess()+" **"+event.getSelfUser().getName()
|
||||
+"** is "+(event.getArgs().isEmpty() ? "no longer playing anything." : "now playing `"+event.getArgs()+"`"));
|
||||
} catch(Exception e) {
|
||||
event.reply(event.getClient().getError()+" The game could not be set!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2016 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 me.jagrosh.jmusicbot.commands;
|
||||
|
||||
import me.jagrosh.jdautilities.commandclient.CommandEvent;
|
||||
import me.jagrosh.jmusicbot.Bot;
|
||||
import me.jagrosh.jmusicbot.audio.AudioHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh <john.a.grosh@gmail.com>
|
||||
*/
|
||||
public class ShuffleCmd extends MusicCommand {
|
||||
|
||||
public ShuffleCmd(Bot bot)
|
||||
{
|
||||
super(bot);
|
||||
this.name = "shuffle";
|
||||
this.help = "shuffles songs you have added";
|
||||
this.beListening = true;
|
||||
this.bePlaying = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand(CommandEvent event) {
|
||||
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
|
||||
int s = handler.getQueue().shuffle(event.getAuthor().getId());
|
||||
switch (s) {
|
||||
case 0:
|
||||
event.reply(event.getClient().getError()+" You don't have any music in the queue to shuffle!");
|
||||
break;
|
||||
case 1:
|
||||
event.reply(event.getClient().getWarning()+" You only have one song in the queue!");
|
||||
break;
|
||||
default:
|
||||
event.reply(event.getClient().getSuccess()+" You successfully shuffled your "+s+" entries.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class SkipCmd extends MusicCommand {
|
||||
if(event.getAuthor().getId().equals(handler.getCurrentTrack().getIdentifier()))
|
||||
{
|
||||
event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getCurrentTrack().getTrack().getInfo().title
|
||||
+"** (requested by **"+event.getAuthor().getName()+"**)");
|
||||
+"**");
|
||||
handler.getPlayer().stopTrack();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2016 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 me.jagrosh.jmusicbot.commands;
|
||||
|
||||
import me.jagrosh.jdautilities.commandclient.CommandEvent;
|
||||
import me.jagrosh.jmusicbot.Bot;
|
||||
import me.jagrosh.jmusicbot.audio.AudioHandler;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh <john.a.grosh@gmail.com>
|
||||
*/
|
||||
public class SkiptoCmd extends MusicCommand {
|
||||
|
||||
public SkiptoCmd(Bot bot)
|
||||
{
|
||||
super(bot);
|
||||
this.name = "skipto";
|
||||
this.help = "skips to the current song";
|
||||
this.arguments = "<position>";
|
||||
this.aliases = new String[]{"jumpto"};
|
||||
this.bePlaying = true;
|
||||
this.category = bot.DJ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand(CommandEvent event) {
|
||||
int index = 0;
|
||||
try
|
||||
{
|
||||
index = Integer.parseInt(event.getArgs());
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
event.reply(event.getClient().getError()+" `"+event.getArgs()+"` is not a valid integer!");
|
||||
return;
|
||||
}
|
||||
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
|
||||
if(index<1 || index>handler.getQueue().size())
|
||||
{
|
||||
event.reply(event.getClient().getError()+" Position must be a valid integer between 1 and "+handler.getQueue().size()+"!");
|
||||
return;
|
||||
}
|
||||
handler.getQueue().skip(index-1);
|
||||
event.reply(event.getClient().getSuccess()+" Skipped to **"+handler.getQueue().get(0).getTrack().getInfo().title+"**");
|
||||
handler.getPlayer().stopTrack();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,4 +80,29 @@ public class FairQueue<T extends Queueable> {
|
||||
{
|
||||
list.clear();
|
||||
}
|
||||
|
||||
public int shuffle(String identifier)
|
||||
{
|
||||
List<Integer> iset = new ArrayList<>();
|
||||
for(int i=0; i<list.size(); i++)
|
||||
{
|
||||
if(list.get(i).getIdentifier().equals(identifier))
|
||||
iset.add(i);
|
||||
}
|
||||
for(int j=0; j<iset.size(); j++)
|
||||
{
|
||||
int first = iset.get(j);
|
||||
int second = iset.get((int)(Math.random()*iset.size()));
|
||||
T temp = list.get(first);
|
||||
list.set(first, list.get(second));
|
||||
list.set(second, temp);
|
||||
}
|
||||
return iset.size();
|
||||
}
|
||||
|
||||
public void skip(int number)
|
||||
{
|
||||
for(int i=0; i<number; i++)
|
||||
list.remove(0);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public class FormatUtil {
|
||||
|
||||
public static String formatTime(long duration)
|
||||
{
|
||||
if(duration == Long.MAX_VALUE)
|
||||
return "LIVE";
|
||||
long seconds = Math.round(duration/1000.0);
|
||||
long hours = seconds/(60*60);
|
||||
seconds %= 60*60;
|
||||
@@ -42,10 +44,10 @@ public class FormatUtil {
|
||||
|
||||
public static String formattedAudio(AudioHandler handler, JDA jda, boolean inTopic)
|
||||
{
|
||||
if(handler==null || handler.getCurrentTrack()==null)
|
||||
{
|
||||
if(handler==null)
|
||||
return "No music playing\n\u23F9 "+progressBar(-1)+" "+volumeIcon(100);
|
||||
else if (handler.getCurrentTrack()==null)
|
||||
return "No music playing\n\u23F9 "+progressBar(-1)+" "+volumeIcon(handler.getPlayer().getVolume());
|
||||
}
|
||||
else
|
||||
{
|
||||
String userid = handler.getCurrentTrack().getIdentifier();
|
||||
|
||||
Reference in new issue
Block a user