mirror of
https://github.com/chrisb09/MusicBot.git
synced 2026-11-06 01:12:40 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c49a559e34 | ||
|
|
af98eb5e01 | ||
|
|
e47c3efc58 | ||
|
|
058c3e18d2 | ||
|
|
38ae19cbec |
No files matched your search
@@ -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.
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.jagrosh</groupId>
|
||||
<artifactId>JMusicBot</artifactId>
|
||||
<version>0.1.2</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.5.0_335</version>
|
||||
<version>3.5.1_348</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sedmelluq</groupId>
|
||||
<artifactId>lavaplayer</artifactId>
|
||||
<version>1.2.47</version>
|
||||
<version>1.2.56</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jagrosh</groupId>
|
||||
<artifactId>JDA-Utilities</artifactId>
|
||||
<version>2.0</version>
|
||||
<artifactId>jda-utilities</artifactId>
|
||||
<version>2.1</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
||||
@@ -33,9 +33,9 @@ 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());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,18 @@ 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 configLocation = null;
|
||||
private String prefix, altprefix, token, owner, success, warning, error, game,
|
||||
help, loadingEmoji, searchingEmoji;
|
||||
private boolean stay, dbots, songingame, useEval, npimages;
|
||||
@@ -42,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);
|
||||
@@ -110,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;
|
||||
@@ -154,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;
|
||||
|
||||
@@ -29,21 +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 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)
|
||||
@@ -58,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.2)",
|
||||
"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);
|
||||
@@ -75,6 +78,7 @@ public class JMusicBot {
|
||||
.setOwnerId(config.getOwnerId())
|
||||
.setEmojis(config.getSuccess(), config.getWarning(), config.getError())
|
||||
.setHelpWord(config.getHelp())
|
||||
.setLinkedCacheSize(200)
|
||||
.addCommands(
|
||||
ab,
|
||||
new PingCommand(),
|
||||
@@ -128,19 +132,25 @@ 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)
|
||||
@@ -150,15 +160,16 @@ public class JMusicBot {
|
||||
.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 ex)
|
||||
{
|
||||
LoggerFactory.getLogger("Startup").error(""+ex);
|
||||
LOG.error("Some aspect of the configuration is invalid: "+ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ 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())
|
||||
@@ -85,7 +85,7 @@ public class PlayCmd extends MusicCommand
|
||||
}
|
||||
String args = event.getArgs().startsWith("<") && event.getArgs().endsWith(">")
|
||||
? event.getArgs().substring(1,event.getArgs().length()-1)
|
||||
: event.getArgs();
|
||||
: 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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user