Compare commits

...
53 Commits
Author SHA1 Message Date
John Grosh be4f235071 Merge origin/master 2020-11-04 08:07:20 -04:00
John Grosh e8df9e9523 fix aboutcommand error 2020-11-04 08:07:00 -04:00
John Grosh 9a79308065 Update and rename feature_request.md to feature-request.md 2020-11-02 15:52:57 -05:00
John Grosh 7a55e76a35 Update bug-report.md 2020-11-02 15:51:15 -05:00
John Grosh c92c55ca52 Create config.yml 2020-11-02 15:46:36 -05:00
John Grosh 2bb43b57ba return to main lavaplayer 2020-10-28 07:10:56 -04:00
John Grosh 403a43530f deps 2020-10-27 16:44:58 -04:00
John Grosh 51f9024498 first iteration of handling new gateway 2020-10-27 05:57:05 -04:00
John Grosh 9f7ad33707 Merge pull request #512 from jagrosh/dependabot/maven/junit-junit-4.13.1
Bump junit from 4.12 to 4.13.1
2020-10-21 23:09:23 -04:00
dependabot[bot] fa5241490f Bump junit from 4.12 to 4.13.1
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 10:57:44 +00:00
John Grosh 27fd75aa67 deps update and small code cleanup 2020-07-04 17:02:19 -04:00
John Grosh c5a583b96f update deps and deal with discords new ratelimits 2020-05-30 13:26:06 -04:00
John Grosh f1e301b48e fix windows path loading bug
fix empty game bug
2020-04-09 16:13:48 -04:00
John Grosh 61d4c51276 update deps 2020-03-23 17:05:02 -04:00
John Grosh cbdbe7bf4b update lavaplayer 2020-02-02 20:42:00 -05:00
John Grosh baa3a60b05 Merge origin/master
Conflicts:
	pom.xml
2020-01-28 21:02:36 -05:00
John Grosh 338dafca0c deps update 2020-01-28 21:00:57 -05:00
John Grosh b1dddb649b Merge pull request #342 from SplitPixl/patch-1
Add the letter "s"
2020-01-17 10:13:39 -05:00
SplitPixl 3eb284da55 Add the letter "s"
As of January 2020, JCenter rejects all non-https connections with a 403 Forbidden. 

https://jfrog.com/blog/secure-jcenter-with-https/
2020-01-16 20:02:26 -08:00
John Grosh 5fb969283d Update bug-report.md 2019-11-10 00:54:29 -05:00
John Grosh ae8b5cfe90 first pass of per-server prefixes 2019-11-09 20:22:53 -05:00
John Grosh b6fa7de7e2 Merge origin/master 2019-11-09 18:16:13 -05:00
John Grosh a4f13ca2de Merge pull request #308 from MichailiK/pr/feature/config/aliases
Add configurable aliases for all commands
2019-11-09 18:15:38 -05:00
John Grosh 5172deb12d dep update and fix playlist shuffling 2019-11-07 22:07:31 -05:00
MichailiK 179f447a70 Catch ConfigException.Missing in BotConfig#getAliases(string) 2019-10-26 09:39:56 +02:00
MichailiK f4a937cc6b Remove unused import from SCSearchCmd 2019-10-25 20:03:45 +02:00
MichailiK 0b4c6c9af1 Use Bot#getConfig() instead of using a public static config & Add missing newline 2019-10-25 19:48:41 +02:00
MichailiK f17058a344 Put aliases inside an "aliases"-block 2019-10-25 19:25:05 +02:00
MichailiK 4fcf86a5d6 Fix alias of volume 2019-10-25 18:14:23 +02:00
MichailiK 94362d640b Change Example 2 2019-10-25 17:56:55 +02:00
MichailiK 7192d55732 Add configurable aliases for all commands 2019-10-25 17:51:56 +02:00
John Grosh 11c9b00510 fix DJ permissions in PlayCmd
general cleanup
2019-10-21 01:02:48 -04:00
John Grosh 4579d6ca09 update deps and bump version 2019-10-21 00:27:19 -04:00
John Grosh c3a9937c90 first pass of debug command 2019-10-21 00:25:45 -04:00
MichailiandM R S E 8650f82210 Fix bot joining in AFK voice channels (#292)
* Fix bot joining in AFK voice channels

Since Discord automatically mutes users in AFK channels, bots shouldn't
play music inside AFK channels. This commit also fixes #147.

* Apply requested changes

* Fix potential NPE

Co-Authored-By: M R S E <Maurice.Craft@t-online.de>

* Fix indention
2019-10-19 23:02:28 -04:00
John Grosh 3ba13d2daa Merge pull request #296 from MichailiK/rp/fix/nowplayinghandler/refreshes-even-with-npimages-enabled
Fix nowplaying being updated even when NPImages is true.
2019-10-16 18:34:29 -04:00
MichailiK dace101c30 Fix nowplaying being updated even when NPImages is true. 2019-10-17 00:27:07 +02:00
John Grosh 05e8ec6814 Merge pull request #290 from MichailiK/pr/fix/pausebug
Fix player being paused when it is paused, then the queue being cleared
2019-10-15 13:19:26 -04:00
John Grosh 646ed6e9b1 Merge pull request #294 from MichailiK/pr/feature/command/queue/wrap-page-ends
Add wrapping of page ends in queue command
2019-10-15 13:15:41 -04:00
MichailiK a501b00ab7 Add wrapping of page ends in queue command
This feature wraps both page ends, meaning that users can jump from the
first page to the last page, using the previous page reaction,
while using the next page button on the last page brings you to the
first page.

Resolves #233.
2019-10-15 18:33:32 +02:00
MichailiK 6ae683b749 Fix player being paused when it is paused, then the queue being cleared
This commit fixes #75, where the player doesn't start playing when
it's been previously paused.
This may happen when a user pauses the player, clears the queue or skips
all songs and another user tries to use the player later.
2019-10-15 10:48:04 +02:00
John Grosh 235af8c8c6 Merge pull request #287 from MichailiK/pr-forceremovecmd-copyright
Add copyright and author to ForceRemoveCmd.java
2019-10-12 16:44:02 -04:00
MichailiK 33e4e8e5ce Add copyright and author to ForceRemoveCmd.java 2019-10-12 22:33:53 +02:00
John Grosh 20b23a3b0d Merge pull request #243 from MichailiK/pr-forceremovecmd
Added ForceRemoveCmd
2019-10-07 09:52:23 -04:00
MichailiK d616c1e386 Apply requested changes (Pass 3) 2019-10-05 19:37:19 +02:00
MichailiK e6f2b23ca9 Fix minor oversight 2019-10-05 10:30:59 +02:00
MichailiK fbfea7ab1f Apply requested changes (Pass 2) 2019-10-04 17:19:11 +02:00
MichailiK bc85fb9597 Apply requested changes 2019-09-12 14:44:13 +02:00
John Grosh a34f06669d removed build files 2019-09-11 19:31:15 -04:00
John Grosh 6508c2b62c dependency and version bump 2019-09-11 19:04:13 -04:00
John Grosh fb53b9e8ea deps updates 2019-07-31 23:35:50 -04:00
Michaili K 75abab2832 Removed redundant code. 2019-06-30 19:09:43 +02:00
Michaili K 13d9fa87d8 Added ForceRemoveCmd 2019-06-30 14:54:42 +02:00
59 changed files with 809 additions and 403 deletions

No files matched your search

-21
View File
@@ -1,21 +0,0 @@
version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile(
'http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET M2_HOME=C:\maven\apache-maven-3.2.5
- cmd: SET PATH=%SystemRoot%\system32;C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;%PATH
build_script:
- mvn clean package --batch-mode -DskipTest
test_script:
- mvn clean install --batch-mode
cache:
- C:\maven\
- C:\Users\appveyor\.m2
+9 -10
View File
@@ -8,23 +8,22 @@ assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
Replace this text with a clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Run with '...'
2. Do a command '....'
3. Some other step '....'
1.
2.
3.
**Expected behavior**
A clear and concise description of what you expected to happen.
Replace this text with a clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
If applicable, add screenshots to help explain your problem here.
**Version Info (please complete the following information):**
- Operating System: [e.g. Windows 64bit]
- JMusicBot Version: [e.g. 0.2.1]
**Debug Info**
Please run the `debug` command and paste it here or upload it as an attachment. If you cannot run the command, please provide information about your system such as operating system version, JMusicBot version, etc.
**Additional context**
Add any other context about the problem here.
Replace this text with any other context about the problem.
+5
View File
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Community Support Server
url: https://discord.gg/0p9LSGoRLu6Pet0k
about: For general questions, please ask in the support server
@@ -1,5 +1,5 @@
---
name: Feature request
name: Feature Request
about: Suggest an idea for this project
title: "[Feature Request] Title Here"
labels: ''
@@ -8,17 +8,16 @@ assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Replace this text with a clear and concise description of what the problem is.
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
Replace this text with a clear and concise description of what you want to happen.
**Describe the basic flow/steps of using this feature**
How this feature would be used:
1. Set something '...'
2. Run some command '...'
3. Other steps or related info '...'
4. ...
1.
2.
3.
**Additional context**
Add any other context or screenshots about the feature request here.
+1
View File
@@ -1,6 +1,7 @@
/nbproject/
/target/
/Playlists/
/test/
*.json
*.txt
nb*.xml
-22
View File
@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<id>bintray</id>
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
-2
View File
@@ -1,2 +0,0 @@
language: java
install: mvn install -Dmaven.javadoc.skip=true --batch-mode --show-version --settings .travis.settings.xml
-1
View File
@@ -8,7 +8,6 @@
[![License](https://img.shields.io/github/license/jagrosh/MusicBot.svg)](https://github.com/jagrosh/MusicBot/blob/master/LICENSE)
[![Discord](https://discordapp.com/api/guilds/147698382092238848/widget.png)](https://discord.gg/0p9LSGoRLu6Pet0k)<br>
[![CircleCI](https://img.shields.io/circleci/project/github/jagrosh/MusicBot/master.svg)](https://circleci.com/gh/jagrosh/MusicBot)
[![Travis-CI](https://travis-ci.com/jagrosh/MusicBot.svg?branch=master)](https://travis-ci.com/jagrosh/MusicBot)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/gdu6nyte5psj6xfk/branch/master?svg=true)](https://ci.appveyor.com/project/jagrosh/musicbot/branch/master)
[![CodeFactor](https://www.codefactor.io/repository/github/jagrosh/musicbot/badge)](https://www.codefactor.io/repository/github/jagrosh/musicbot)
+14 -9
View File
@@ -3,19 +3,19 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<version>0.2.3</version>
<version>Snapshot</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>bintray-jagrosh-maven</id>
<id>bintray-sedmelluq-com.sedmelluq</id>
<name>bintray</name>
<url>https://dl.bintray.com/jagrosh/maven</url>
<url>https://dl.bintray.com/sedmelluq/com.sedmelluq</url>
</repository>
</repositories>
@@ -23,23 +23,28 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.8.3_463</version>
<version>4.2.0_214</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.17</version>
<version>1.3.55</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer-natives-extra</artifactId>
<version>1.3.13</version>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<version>2.1.5</version>
<version>3.0.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>JLyrics</artifactId>
<version>0.2</version>
<version>0.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -54,7 +59,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
+6 -6
View File
@@ -25,9 +25,9 @@ import com.jagrosh.jmusicbot.gui.GUI;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader;
import com.jagrosh.jmusicbot.settings.SettingsManager;
import java.util.Objects;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
/**
*
@@ -109,9 +109,9 @@ public class Bot
public void resetGame()
{
Game game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame();
if(!Objects.equals(jda.getPresence().getGame(), game))
jda.getPresence().setGame(game);
Activity game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame();
if(!Objects.equals(jda.getPresence().getActivity(), game))
jda.getPresence().setActivity(game);
}
public void shutdown()
@@ -23,9 +23,8 @@ import com.typesafe.config.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
/**
*
@@ -45,8 +44,10 @@ public class BotConfig
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds;
private OnlineStatus status;
private Game game;
private Activity game;
private Config aliases;
private boolean valid = false;
public BotConfig(Prompt prompt)
@@ -62,7 +63,7 @@ public class BotConfig
try
{
// get the path to the config, default config.txt
path = Paths.get(System.getProperty("config.file", System.getProperty("config", "config.txt")));
path = OtherUtil.getPath(System.getProperty("config.file", System.getProperty("config", "config.txt")));
if(path.toFile().exists())
{
if(System.getProperty("config.file") == null)
@@ -94,6 +95,7 @@ public class BotConfig
useEval = config.getBoolean("eval");
maxSeconds = config.getLong("maxtime");
playlistsFolder = config.getString("playlistsfolder");
aliases = config.getConfig("aliases");
dbots = owner == 113156185389092864L;
// we may need to write a new config file
@@ -135,7 +137,7 @@ public class BotConfig
if(owner<=0)
{
prompt.alert(Prompt.Level.ERROR, CONTEXT, "Invalid User ID! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
System.exit(0);
return;
}
else
{
@@ -144,31 +146,7 @@ public class BotConfig
}
if(write)
{
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, bytes);
}
catch(IOException ex)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "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.\n\nConfig Location: "
+ path.toAbsolutePath().toString());
}
}
writeToFile();
// if we get through the whole config, it's good to go
valid = true;
@@ -179,6 +157,33 @@ public class BotConfig
}
}
private void writeToFile()
{
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, bytes);
}
catch(IOException ex)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "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.\n\nConfig Location: "
+ path.toAbsolutePath().toString());
}
}
public boolean isValid()
{
return valid;
@@ -234,7 +239,7 @@ public class BotConfig
return searchingEmoji;
}
public Game getGame()
public Activity getGame()
{
return game;
}
@@ -300,4 +305,16 @@ public class BotConfig
return false;
return Math.round(track.getDuration()/1000.0) > maxSeconds;
}
public String[] getAliases(String command)
{
try
{
return aliases.getStringList(command).toArray(new String[0]);
}
catch(NullPointerException | ConfigException.Missing e)
{
return new String[0];
}
}
}
@@ -15,7 +15,6 @@
*/
package com.jagrosh.jmusicbot;
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.*;
@@ -29,9 +28,12 @@ import com.jagrosh.jmusicbot.gui.GUI;
import com.jagrosh.jmusicbot.settings.SettingsManager;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.awt.Color;
import java.util.Arrays;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.core.*;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,9 +46,10 @@ public class JMusicBot
public final static String PLAY_EMOJI = "\u25B6"; // ▶
public final static String PAUSE_EMOJI = "\u23F8"; // ⏸
public final static String STOP_EMOJI = "\u23F9"; // ⏹
public final static Permission[] RECOMMENDED_PERMS = new Permission[]{Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
public final static Permission[] RECOMMENDED_PERMS = {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 GatewayIntent[] INTENTS = {GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES};
/**
* @param args the command line arguments
*/
@@ -59,18 +62,13 @@ public class JMusicBot
Prompt prompt = new Prompt("JMusicBot", "Switching to nogui mode. You can manually start in nogui mode by including the -Dnogui=true flag.",
"true".equalsIgnoreCase(System.getProperty("nogui", "false")));
// check deprecated nogui mode (new way of setting it is -Dnogui=true)
for(String arg: args)
if("-nogui".equalsIgnoreCase(arg))
{
prompt.alert(Prompt.Level.WARNING, "GUI", "The -nogui flag has been deprecated. "
+ "Please use the -Dnogui=true flag before the name of the jar. Example: java -jar -Dnogui=true JMusicBot.jar");
break;
}
// get and check latest version
String version = OtherUtil.checkVersion(prompt);
// check for valid java version
if(!System.getProperty("java.vm.name").contains("64"))
prompt.alert(Prompt.Level.WARNING, "Java Version", "It appears that you may not be using a supported Java version. Please use 64-bit java.");
// load config
BotConfig config = new BotConfig(prompt);
config.load();
@@ -100,38 +98,41 @@ public class JMusicBot
.setGuildSettingsManager(settings)
.addCommands(aboutCommand,
new PingCommand(),
new SettingsCmd(),
new SettingsCmd(bot),
new LyricsCmd(bot),
new NowplayingCmd(bot),
new PlayCmd(bot, config.getLoading()),
new PlayCmd(bot),
new PlaylistsCmd(bot),
new QueueCmd(bot),
new RemoveCmd(bot),
new SearchCmd(bot, config.getSearching()),
new SCSearchCmd(bot, config.getSearching()),
new SearchCmd(bot),
new SCSearchCmd(bot),
new ShuffleCmd(bot),
new SkipCmd(bot),
new ForceRemoveCmd(bot),
new ForceskipCmd(bot),
new MoveTrackCmd(bot),
new PauseCmd(bot),
new PlaynextCmd(bot, config.getLoading()),
new PlaynextCmd(bot),
new RepeatCmd(bot),
new SkiptoCmd(bot),
new StopCmd(bot),
new VolumeCmd(bot),
new SetdjCmd(),
new SettcCmd(),
new SetvcCmd(),
new PrefixCmd(bot),
new SetdjCmd(bot),
new SettcCmd(bot),
new SetvcCmd(bot),
new AutoplaylistCmd(bot),
new DebugCmd(bot),
new PlaylistCmd(bot),
new SetavatarCmd(),
new SetgameCmd(),
new SetnameCmd(),
new SetstatusCmd(),
new SetavatarCmd(bot),
new SetgameCmd(bot),
new SetnameCmd(bot),
new SetstatusCmd(bot),
new ShutdownCmd(bot)
);
if(config.useEval())
@@ -143,12 +144,11 @@ public class JMusicBot
cb.useDefaultGame();
else if(config.getGame().getName().equalsIgnoreCase("none"))
{
cb.setGame(null);
cb.setActivity(null);
nogame = true;
}
else
cb.setGame(config.getGame());
CommandClient client = cb.build();
cb.setActivity(config.getGame());
if(!prompt.isNoGUI())
{
@@ -166,17 +166,18 @@ public class JMusicBot
}
}
log.info("Loaded config from "+config.getConfigLocation());
log.info("Loaded config from " + config.getConfigLocation());
// attempt to log in and start
try
{
JDA jda = new JDABuilder(AccountType.BOT)
.setToken(config.getToken())
.setAudioEnabled(true)
.setGame(nogame ? null : Game.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE||config.getStatus()==OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListener(client, waiter, new Listener(bot))
JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS))
.enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE)
.setActivity(nogame ? null : Activity.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListeners(cb.build(), waiter, new Listener(bot))
.setBulkDeleteSplittingEnabled(true)
.build();
bot.setJDA(jda);
@@ -17,15 +17,15 @@ package com.jagrosh.jmusicbot;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.User;
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.guild.GuildMessageDeleteEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.ShutdownEvent;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,11 +45,11 @@ public class Listener extends ListenerAdapter
@Override
public void onReady(ReadyEvent event)
{
if(event.getJDA().getGuilds().isEmpty())
if(event.getJDA().getGuildCache().isEmpty())
{
Logger log = LoggerFactory.getLogger("MusicBot");
log.warn("This bot is not on any guilds! Use the following link to add the bot to your guilds!");
log.warn(event.getJDA().asBot().getInviteUrl(JMusicBot.RECOMMENDED_PERMS));
log.warn(event.getJDA().getInviteUrl(JMusicBot.RECOMMENDED_PERMS));
}
credit(event.getJDA());
event.getJDA().getGuilds().forEach((guild) ->
@@ -30,13 +30,14 @@ import com.jagrosh.jmusicbot.queue.FairQueue;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.audio.AudioSendHandler;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.User;
import java.nio.ByteBuffer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.audio.AudioSendHandler;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
/**
*
@@ -166,6 +167,9 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
manager.getBot().getNowplayingHandler().onTrackUpdate(guildId, null, this);
if(!manager.getBot().getConfig().getStay())
manager.getBot().closeAudioConnection(guildId);
// unpause, in the case when the player was paused and the track has been skipped.
// this is to prevent the player being paused next time it's being used.
player.setPaused(false);
}
}
else
@@ -261,7 +265,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
}
// Audio Send Handler methods
@Override
/*@Override
public boolean canProvide()
{
if (lastFrame == null)
@@ -280,6 +284,19 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
lastFrame = null;
return data;
}*/
@Override
public boolean canProvide()
{
lastFrame = audioPlayer.provide();
return lastFrame != null;
}
@Override
public ByteBuffer provide20MsAudio()
{
return ByteBuffer.wrap(lastFrame.getData());
}
@Override
@@ -23,12 +23,13 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.exceptions.PermissionException;
import net.dv8tion.jda.api.exceptions.RateLimitedException;
/**
*
@@ -47,7 +48,8 @@ public class NowplayingHandler
public void init()
{
bot.getThreadpool().scheduleWithFixedDelay(() -> updateAll(), 0, 5, TimeUnit.SECONDS);
if(!bot.getConfig().useNPImages())
bot.getThreadpool().scheduleWithFixedDelay(() -> updateAll(), 0, 5, TimeUnit.SECONDS);
}
public void setLastNPMessage(Message m)
@@ -107,23 +109,25 @@ public class NowplayingHandler
if(tchan!=null && guild.getSelfMember().hasPermission(tchan, Permission.MANAGE_CHANNEL))
{
String otherText;
if(tchan.getTopic()==null || tchan.getTopic().isEmpty())
String topic = tchan.getTopic();
if(topic==null || topic.isEmpty())
otherText = "\u200B";
else if(tchan.getTopic().contains("\u200B"))
otherText = tchan.getTopic().substring(tchan.getTopic().lastIndexOf("\u200B"));
else if(topic.contains("\u200B"))
otherText = topic.substring(topic.lastIndexOf("\u200B"));
else
otherText = "\u200B\n "+tchan.getTopic();
otherText = "\u200B\n "+topic;
String text = handler.getTopicFormat(bot.getJDA()) + otherText;
if(!text.equals(tchan.getTopic()))
{
try
{
if(wait)
tchan.getManager().setTopic(text).complete();
else
tchan.getManager().setTopic(text).queue();
// normally here if 'wait' was false, we'd want to queue, however,
// new discord ratelimits specifically limiting changing channel topics
// mean we don't want a backlog of changes piling up, so if we hit a
// ratelimit, we just won't change the topic this time
tchan.getManager().setTopic(text).complete(wait);
}
catch(PermissionException ignore) {}
catch(PermissionException | RateLimitedException ignore) {}
}
}
}
@@ -135,7 +139,7 @@ public class NowplayingHandler
if(bot.getConfig().getSongInStatus())
{
if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()<=1)
bot.getJDA().getPresence().setGame(Game.listening(track.getInfo().title));
bot.getJDA().getPresence().setActivity(Activity.listening(track.getInfo().title));
else
bot.resetGame();
}
@@ -20,7 +20,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.api.entities.Guild;
/**
*
@@ -18,7 +18,7 @@ package com.jagrosh.jmusicbot.audio;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.jagrosh.jmusicbot.queue.Queueable;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.api.entities.User;
/**
*
@@ -16,7 +16,7 @@
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.command.Command;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.api.Permission;
/**
*
@@ -15,10 +15,11 @@
*/
package com.jagrosh.jmusicbot.commands;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Role;
/**
*
@@ -29,17 +30,19 @@ public abstract class DJCommand extends MusicCommand
public DJCommand(Bot bot)
{
super(bot);
this.category = new Category("DJ", event ->
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.getGuild()==null)
return true;
if(event.getMember().hasPermission(Permission.MANAGE_SERVER))
return true;
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Role dj = settings.getRole(event.getGuild());
return dj!=null && (event.getMember().getRoles().contains(dj) || dj.getIdLong()==event.getGuild().getIdLong());
});
this.category = new Category("DJ", event -> checkDJPermission(event));
}
public static boolean checkDJPermission(CommandEvent event)
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.getGuild()==null)
return true;
if(event.getMember().hasPermission(Permission.MANAGE_SERVER))
return true;
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Role dj = settings.getRole(event.getGuild());
return dj!=null && (event.getMember().getRoles().contains(dj) || dj.getIdLong()==event.getGuild().getIdLong());
}
}
@@ -20,10 +20,10 @@ import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.core.entities.GuildVoiceState;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.exceptions.PermissionException;
/**
*
@@ -73,6 +73,14 @@ public abstract class MusicCommand extends Command
event.replyError("You must be listening in "+(current==null ? "a voice channel" : "**"+current.getName()+"**")+" to use that!");
return;
}
VoiceChannel afkChannel = userState.getGuild().getAfkChannel();
if(afkChannel != null && afkChannel.equals(userState.getChannel()))
{
event.replyError("You cannot use that command in an AFK channel!");
return;
}
if(!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel())
{
try
@@ -0,0 +1,58 @@
/*
* 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.commands.admin;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
/**
*
* @author John Grosh (john.a.grosh@gmail.com)
*/
public class PrefixCmd extends AdminCommand
{
public PrefixCmd(Bot bot)
{
this.name = "prefix";
this.help = "sets a server-specific prefix";
this.arguments = "<prefix|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}
@Override
protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.replyError("Please include a prefix or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setPrefix(null);
event.replySuccess("Prefix cleared.");
}
else
{
s.setPrefix(event.getArgs());
event.replySuccess("Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*");
}
}
}
@@ -18,10 +18,11 @@ package com.jagrosh.jmusicbot.commands.admin;
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.api.entities.Role;
/**
*
@@ -29,11 +30,12 @@ import net.dv8tion.jda.core.entities.Role;
*/
public class SetdjCmd extends AdminCommand
{
public SetdjCmd()
public SetdjCmd(Bot bot)
{
this.name = "setdj";
this.help = "sets the DJ role for certain music commands";
this.arguments = "<rolename|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}
@Override
@@ -18,10 +18,11 @@ package com.jagrosh.jmusicbot.commands.admin;
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.TextChannel;
/**
*
@@ -29,11 +30,12 @@ import net.dv8tion.jda.core.entities.TextChannel;
*/
public class SettcCmd extends AdminCommand
{
public SettcCmd()
public SettcCmd(Bot bot)
{
this.name = "settc";
this.help = "sets the text channel for music commands";
this.arguments = "<channel|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}
@Override
@@ -18,10 +18,11 @@ package com.jagrosh.jmusicbot.commands.admin;
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
/**
*
@@ -29,11 +30,12 @@ import net.dv8tion.jda.core.entities.VoiceChannel;
*/
public class SetvcCmd extends AdminCommand
{
public SetvcCmd()
public SetvcCmd(Bot bot)
{
this.name = "setvc";
this.help = "sets the voice channel for playing music";
this.arguments = "<channel|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}
@Override
@@ -0,0 +1,119 @@
/*
* Copyright 2019 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.commands.dj;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jdautilities.menu.OrderedMenu;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
*
* @author Michaili K.
*/
public class ForceRemoveCmd extends DJCommand
{
public ForceRemoveCmd(Bot bot)
{
super(bot);
this.name = "forceremove";
this.help = "removes all entries by a user from the queue";
this.arguments = "<user>";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = false;
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
}
@Override
public void doCommand(CommandEvent event)
{
if (event.getArgs().isEmpty())
{
event.replyError("You need to mention a user!");
return;
}
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
if (handler.getQueue().isEmpty())
{
event.replyError("There is nothing in the queue!");
return;
}
User target;
List<Member> found = FinderUtil.findMembers(event.getArgs(), event.getGuild());
if(found.isEmpty())
{
event.replyError("Unable to find the user!");
return;
}
else if(found.size()>1)
{
OrderedMenu.Builder builder = new OrderedMenu.Builder();
for(int i=0; i<found.size() && i<4; i++)
{
Member member = found.get(i);
builder.addChoice("**"+member.getUser().getName()+"**#"+member.getUser().getDiscriminator());
}
builder
.setSelection((msg, i) -> removeAllEntries(found.get(i-1).getUser(), event))
.setText("Found multiple users:")
.setColor(event.getSelfMember().getColor())
.useNumbers()
.setUsers(event.getAuthor())
.useCancelButton(true)
.setCancel((msg) -> {})
.setEventWaiter(bot.getWaiter())
.setTimeout(1, TimeUnit.MINUTES)
.build().display(event.getChannel());
return;
}
else
{
target = found.get(0).getUser();
}
removeAllEntries(target, event);
}
private void removeAllEntries(User target, CommandEvent event)
{
int count = ((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong());
if (count == 0)
{
event.replyWarning("**"+target.getName()+"** doesn't have any songs in the queue!");
}
else
{
event.replySuccess("Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+".");
}
}
}
@@ -19,7 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.api.entities.User;
/**
*
@@ -32,7 +32,7 @@ public class ForceskipCmd extends DJCommand
super(bot);
this.name = "forceskip";
this.help = "skips the current song";
this.aliases = new String[]{"modskip"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}
@@ -20,7 +20,7 @@ public class MoveTrackCmd extends DJCommand
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.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}
@@ -31,6 +31,7 @@ public class PauseCmd extends DJCommand
super(bot);
this.name = "pause";
this.help = "pauses the current song";
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}
@@ -25,7 +25,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.api.entities.Message;
/**
*
@@ -35,13 +35,14 @@ public class PlaynextCmd extends DJCommand
{
private final String loadingEmoji;
public PlaynextCmd(Bot bot, String loadingEmoji)
public PlaynextCmd(Bot bot)
{
super(bot);
this.loadingEmoji = loadingEmoji;
this.loadingEmoji = bot.getConfig().getLoading();
this.name = "playnext";
this.arguments = "<title|URL>";
this.help = "plays a single song next";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = false;
}
@@ -32,6 +32,7 @@ public class RepeatCmd extends DJCommand
this.name = "repeat";
this.help = "re-adds music to the queue when finished";
this.arguments = "[on|off]";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
}
@@ -32,7 +32,7 @@ public class SkiptoCmd extends DJCommand
this.name = "skipto";
this.help = "skips to the specified song";
this.arguments = "<position>";
this.aliases = new String[]{"jumpto"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}
@@ -31,6 +31,7 @@ public class StopCmd extends DJCommand
super(bot);
this.name = "stop";
this.help = "stops the current song and clears the queue";
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = false;
}
@@ -32,7 +32,7 @@ public class VolumeCmd extends DJCommand
{
super(bot);
this.name = "volume";
this.aliases = new String[]{"vol"};
this.aliases = bot.getConfig().getAliases(this.name);
this.help = "sets or shows volume";
this.arguments = "[0-150]";
}
@@ -17,12 +17,14 @@ package com.jagrosh.jmusicbot.commands.general;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
/**
*
@@ -32,11 +34,11 @@ public class SettingsCmd extends Command
{
private final static String EMOJI = "\uD83C\uDFA7"; // 🎧
public SettingsCmd()
public SettingsCmd(Bot bot)
{
this.name = "settings";
this.help = "shows the bots settings";
this.aliases = new String[]{"status"};
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
}
@@ -46,22 +48,23 @@ public class SettingsCmd extends Command
Settings s = event.getClient().getSettingsFor(event.getGuild());
MessageBuilder builder = new MessageBuilder()
.append(EMOJI + " **")
.append(event.getSelfUser().getName())
.append(FormatUtil.filter(event.getSelfUser().getName()))
.append("** settings:");
TextChannel tchan = s.getTextChannel(event.getGuild());
VoiceChannel vchan = s.getVoiceChannel(event.getGuild());
Role role = s.getRole(event.getGuild());
EmbedBuilder ebuilder = new EmbedBuilder()
.setColor(event.getSelfMember().getColor())
.setDescription("Text Channel: "+(tchan==null ? "Any" : "**#"+tchan.getName()+"**")
+ "\nVoice Channel: "+(vchan==null ? "Any" : "**"+vchan.getName()+"**")
+ "\nDJ Role: "+(role==null ? "None" : "**"+role.getName()+"**")
+ "\nRepeat Mode: **"+(s.getRepeatMode() ? "On" : "Off")+"**"
+ "\nDefault Playlist: "+(s.getDefaultPlaylist()==null ? "None" : "**"+s.getDefaultPlaylist()+"**")
.setDescription("Text Channel: " + (tchan == null ? "Any" : "**#" + tchan.getName() + "**")
+ "\nVoice Channel: " + (vchan == null ? "Any" : "**" + vchan.getName() + "**")
+ "\nDJ Role: " + (role == null ? "None" : "**" + role.getName() + "**")
+ "\nCustom Prefix: " + (s.getPrefix() == null ? "None" : "`" + s.getPrefix() + "`")
+ "\nRepeat Mode: **" + (s.getRepeatMode() ? "On" : "Off") + "**"
+ "\nDefault Playlist: " + (s.getDefaultPlaylist() == null ? "None" : "**" + s.getDefaultPlaylist() + "**")
)
.setFooter(event.getJDA().getGuilds().size()+" servers | "
+event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()
+" audio connections", null);
.setFooter(event.getJDA().getGuilds().size() + " servers | "
+ event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()
+ " audio connections", null);
event.getChannel().sendMessage(builder.setEmbed(ebuilder.build()).build()).queue();
}
@@ -16,14 +16,12 @@
package com.jagrosh.jmusicbot.commands.music;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jlyrics.Lyrics;
import com.jagrosh.jlyrics.LyricsClient;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import java.util.concurrent.ExecutionException;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
/**
*
@@ -39,6 +37,7 @@ public class LyricsCmd extends MusicCommand
this.name = "lyrics";
this.arguments = "[song name]";
this.help = "shows the lyrics to the currently-playing song";
this.aliases = bot.getConfig().getAliases(this.name);
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
this.bePlaying = true;
}
@@ -56,7 +55,7 @@ public class LyricsCmd extends MusicCommand
{
if(lyrics == null)
{
event.replyError("Lyrics for `" + title + "` could not be found!");
event.replyError("Lyrics for `" + title + "` could not be found!" + (event.getArgs().isEmpty() ? " Try entering the song name manually (`lyrics [song name]`)" : ""));
return;
}
@@ -19,8 +19,8 @@ import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
/**
*
@@ -33,7 +33,7 @@ public class NowplayingCmd extends MusicCommand
super(bot);
this.name = "nowplaying";
this.help = "shows the song that is currently playing";
this.aliases = new String[]{"np","current"};
this.aliases = bot.getConfig().getAliases(this.name);
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
}
@@ -26,15 +26,14 @@ import com.jagrosh.jdautilities.menu.ButtonMenu;
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.commands.MusicCommand;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.exceptions.PermissionException;
/**
*
@@ -47,13 +46,14 @@ public class PlayCmd extends MusicCommand
private final String loadingEmoji;
public PlayCmd(Bot bot, String loadingEmoji)
public PlayCmd(Bot bot)
{
super(bot);
this.loadingEmoji = loadingEmoji;
this.loadingEmoji = bot.getConfig().getLoading();
this.name = "play";
this.arguments = "<title|URL|subcommand>";
this.help = "plays the provided song";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = false;
this.children = new Command[]{new PlaylistCmd(bot)};
@@ -67,20 +67,13 @@ public class PlayCmd extends MusicCommand
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
if(handler.getPlayer().getPlayingTrack()!=null && handler.getPlayer().isPaused())
{
boolean isDJ = event.getMember().hasPermission(Permission.MANAGE_SERVER);
if(!isDJ)
isDJ = event.isOwner();
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Role dj = settings.getRole(event.getGuild());
if(!isDJ && dj!=null)
isDJ = event.getMember().getRoles().contains(dj);
if(!isDJ)
event.replyError("Only DJs can unpause the player!");
else
if(DJCommand.checkDJPermission(event))
{
handler.getPlayer().setPaused(false);
event.replySuccess("Resumed **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**.");
}
else
event.replyError("Only DJs can unpause the player!");
return;
}
StringBuilder builder = new StringBuilder(event.getClient().getWarning()+" Play Commands:\n");
@@ -31,7 +31,7 @@ public class PlaylistsCmd extends MusicCommand
super(bot);
this.name = "playlists";
this.help = "shows the available playlists";
this.aliases = new String[]{"pls"};
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
this.beListening = false;
this.beListening = false;
@@ -26,10 +26,10 @@ import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.exceptions.PermissionException;
/**
*
@@ -47,7 +47,7 @@ public class QueueCmd extends MusicCommand
this.name = "queue";
this.help = "shows the current queue";
this.arguments = "[pagenum]";
this.aliases = new String[]{"list"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS};
builder = new Paginator.Builder()
@@ -57,6 +57,7 @@ public class QueueCmd extends MusicCommand
.waitOnSinglePage(false)
.useNumberedItems(true)
.showPageNumbers(true)
.wrapPageEnds(true)
.setEventWaiter(bot.getWaiter())
.setTimeout(1, TimeUnit.MINUTES);
}
@@ -21,8 +21,8 @@ import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.User;
/**
*
@@ -36,7 +36,7 @@ public class RemoveCmd extends MusicCommand
this.name = "remove";
this.help = "removes a song from the queue";
this.arguments = "<position|ALL>";
this.aliases = new String[]{"delete"};
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
@@ -23,12 +23,12 @@ import com.jagrosh.jmusicbot.Bot;
*/
public class SCSearchCmd extends SearchCmd
{
public SCSearchCmd(Bot bot, String searchingEmoji)
public SCSearchCmd(Bot bot)
{
super(bot, searchingEmoji);
super(bot);
this.searchPrefix = "scsearch:";
this.name = "scsearch";
this.help = "searches Soundcloud for a provided query";
this.aliases = new String[]{};
this.aliases = bot.getConfig().getAliases(this.name);
}
}
@@ -28,8 +28,8 @@ import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
/**
*
@@ -41,12 +41,12 @@ public class SearchCmd extends MusicCommand
private final OrderedMenu.Builder builder;
private final String searchingEmoji;
public SearchCmd(Bot bot, String searchingEmoji)
public SearchCmd(Bot bot)
{
super(bot);
this.searchingEmoji = searchingEmoji;
this.searchingEmoji = bot.getConfig().getSearching();
this.name = "search";
this.aliases = new String[]{"ytsearch"};
this.aliases = bot.getConfig().getAliases(this.name);
this.arguments = "<query>";
this.help = "searches Youtube for a provided query";
this.beListening = true;
@@ -115,8 +115,8 @@ public class SearchCmd extends MusicCommand
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1;
event.replySuccess("Added **"+track.getInfo().title
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0 ? "to begin playing"
event.replySuccess("Added **" + FormatUtil.filter(track.getInfo().title)
+ "** (`" + FormatUtil.formatTime(track.getDuration()) + "`) " + (pos==0 ? "to begin playing"
: " to the queue at position "+pos));
})
.setCancel((msg) -> {})
@@ -31,6 +31,7 @@ public class ShuffleCmd extends MusicCommand
super(bot);
this.name = "shuffle";
this.help = "shuffles songs you have added";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
@@ -19,7 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.api.entities.User;
/**
*
@@ -32,7 +32,7 @@ public class SkipCmd extends MusicCommand
super(bot);
this.name = "skip";
this.help = "votes to skip the current song";
this.aliases = new String[]{"voteskip"};
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
@@ -35,6 +35,7 @@ public class AutoplaylistCmd extends OwnerCommand
this.name = "autoplaylist";
this.arguments = "<name|NONE>";
this.help = "sets the default playlist for the server";
this.aliases = bot.getConfig().getAliases(this.name);
}
@Override
@@ -0,0 +1,87 @@
/*
* 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 com.jagrosh.jmusicbot.commands.owner;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
import net.dv8tion.jda.api.JDAInfo;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ChannelType;
/**
*
* @author John Grosh (john.a.grosh@gmail.com)
*/
public class DebugCmd extends OwnerCommand
{
private final static String[] PROPERTIES = {"java.version", "java.vm.name", "java.vm.specification.version",
"java.runtime.name", "java.runtime.version", "java.specification.version", "os.arch", "os.name"};
private final Bot bot;
public DebugCmd(Bot bot)
{
this.bot = bot;
this.name = "debug";
this.help = "shows debug info";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@Override
protected void execute(CommandEvent event)
{
StringBuilder sb = new StringBuilder();
sb.append("```\nSystem Properties:");
for(String key: PROPERTIES)
sb.append("\n ").append(key).append(" = ").append(System.getProperty(key));
sb.append("\n\nJMusicBot Information:")
.append("\n Version = ").append(OtherUtil.getCurrentVersion())
.append("\n Owner = ").append(bot.getConfig().getOwnerId())
.append("\n Prefix = ").append(bot.getConfig().getPrefix())
.append("\n AltPrefix = ").append(bot.getConfig().getAltPrefix())
.append("\n MaxSeconds = ").append(bot.getConfig().getMaxSeconds())
.append("\n NPImages = ").append(bot.getConfig().useNPImages())
.append("\n SongInStatus = ").append(bot.getConfig().getSongInStatus())
.append("\n StayInChannel = ").append(bot.getConfig().getStay())
.append("\n UseEval = ").append(bot.getConfig().useEval())
.append("\n UpdateAlerts = ").append(bot.getConfig().useUpdateAlerts());
sb.append("\n\nDependency Information:")
.append("\n JDA Version = ").append(JDAInfo.VERSION)
.append("\n JDA-Utilities Version = ").append(JDAUtilitiesInfo.VERSION)
.append("\n Lavaplayer Version = ").append(PlayerLibrary.VERSION);
long total = Runtime.getRuntime().totalMemory() / 1024 / 1024;
long used = total - (Runtime.getRuntime().freeMemory() / 1024 / 1024);
sb.append("\n\nRuntime Information:")
.append("\n Total Memory = ").append(total)
.append("\n Used Memory = ").append(used);
sb.append("\n\nDiscord Information:")
.append("\n ID = ").append(event.getJDA().getSelfUser().getId())
.append("\n Guilds = ").append(event.getJDA().getGuildCache().size())
.append("\n Users = ").append(event.getJDA().getUserCache().size());
sb.append("\n```");
if(event.isFromType(ChannelType.PRIVATE)
|| event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES))
event.getChannel().sendFile(sb.toString().getBytes(), "debug_information.txt").queue();
else
event.reply("Debug Information: " + sb.toString());
}
}
@@ -34,6 +34,7 @@ public class EvalCmd extends OwnerCommand
this.bot = bot;
this.name = "eval";
this.help = "evaluates nashorn code";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@@ -21,7 +21,6 @@ import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import com.jagrosh.jmusicbot.commands.owner.AutoplaylistCmd;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
/**
@@ -38,6 +37,7 @@ public class PlaylistCmd extends OwnerCommand
this.name = "playlist";
this.arguments = "<append|delete|make|setdefault>";
this.help = "playlist management";
this.aliases = bot.getConfig().getAliases(this.name);
this.children = new OwnerCommand[]{
new ListCmd(),
new AppendlistCmd(),
@@ -18,9 +18,10 @@ package com.jagrosh.jmusicbot.commands.owner;
import java.io.IOException;
import java.io.InputStream;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import net.dv8tion.jda.core.entities.Icon;
import net.dv8tion.jda.api.entities.Icon;
/**
*
@@ -28,11 +29,12 @@ import net.dv8tion.jda.core.entities.Icon;
*/
public class SetavatarCmd extends OwnerCommand
{
public SetavatarCmd()
public SetavatarCmd(Bot bot)
{
this.name = "setavatar";
this.help = "sets the avatar of the bot";
this.arguments = "<url>";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@@ -16,8 +16,9 @@
package com.jagrosh.jmusicbot.commands.owner;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.api.entities.Activity;
/**
*
@@ -25,11 +26,12 @@ import net.dv8tion.jda.core.entities.Game;
*/
public class SetgameCmd extends OwnerCommand
{
public SetgameCmd()
public SetgameCmd(Bot bot)
{
this.name = "setgame";
this.help = "sets the game the bot is playing";
this.arguments = "[action] [game]";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
this.children = new OwnerCommand[]{
new SetlistenCmd(),
@@ -44,7 +46,7 @@ public class SetgameCmd extends OwnerCommand
String title = event.getArgs().toLowerCase().startsWith("playing") ? event.getArgs().substring(7).trim() : event.getArgs();
try
{
event.getJDA().getPresence().setGame(title.isEmpty() ? null : Game.playing(title));
event.getJDA().getPresence().setActivity(title.isEmpty() ? null : Activity.playing(title));
event.reply(event.getClient().getSuccess()+" **"+event.getSelfUser().getName()
+"** is "+(title.isEmpty() ? "no longer playing anything." : "now playing `"+title+"`"));
}
@@ -76,7 +78,7 @@ public class SetgameCmd extends OwnerCommand
}
try
{
event.getJDA().getPresence().setGame(Game.streaming(parts[1], "https://twitch.tv/"+parts[0]));
event.getJDA().getPresence().setActivity(Activity.streaming(parts[1], "https://twitch.tv/"+parts[0]));
event.replySuccess("**"+event.getSelfUser().getName()
+"** is now streaming `"+parts[1]+"`");
}
@@ -109,7 +111,7 @@ public class SetgameCmd extends OwnerCommand
String title = event.getArgs().toLowerCase().startsWith("to") ? event.getArgs().substring(2).trim() : event.getArgs();
try
{
event.getJDA().getPresence().setGame(Game.listening(title));
event.getJDA().getPresence().setActivity(Activity.listening(title));
event.replySuccess("**"+event.getSelfUser().getName()+"** is now listening to `"+title+"`");
} catch(Exception e) {
event.reply(event.getClient().getError()+" The game could not be set!");
@@ -139,7 +141,7 @@ public class SetgameCmd extends OwnerCommand
String title = event.getArgs();
try
{
event.getJDA().getPresence().setGame(Game.watching(title));
event.getJDA().getPresence().setActivity(Activity.watching(title));
event.replySuccess("**"+event.getSelfUser().getName()+"** is now watching `"+title+"`");
} catch(Exception e) {
event.reply(event.getClient().getError()+" The game could not be set!");
@@ -18,7 +18,7 @@ package com.jagrosh.jmusicbot.commands.owner;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import net.dv8tion.jda.api.exceptions.RateLimitedException;
/**
*
@@ -26,11 +26,12 @@ import net.dv8tion.jda.core.exceptions.RateLimitedException;
*/
public class SetnameCmd extends OwnerCommand
{
public SetnameCmd()
public SetnameCmd(Bot bot)
{
this.name = "setname";
this.help = "sets the name of the bot";
this.arguments = "<name>";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@@ -16,8 +16,9 @@
package com.jagrosh.jmusicbot.commands.owner;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.api.OnlineStatus;
/**
*
@@ -25,11 +26,12 @@ import net.dv8tion.jda.core.OnlineStatus;
*/
public class SetstatusCmd extends OwnerCommand
{
public SetstatusCmd()
public SetstatusCmd(Bot bot)
{
this.name = "setstatus";
this.help = "sets the status the bot displays";
this.arguments = "<status>";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@@ -32,6 +32,7 @@ public class ShutdownCmd extends OwnerCommand
this.bot = bot;
this.name = "shutdown";
this.help = "safely shuts down";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}
@@ -16,6 +16,7 @@
package com.jagrosh.jmusicbot.playlist;
import com.jagrosh.jmusicbot.BotConfig;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
@@ -24,7 +25,6 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -61,29 +61,29 @@ public class PlaylistLoader
{
try
{
Files.createDirectory(Paths.get(config.getPlaylistsFolder()));
Files.createDirectory(OtherUtil.getPath(config.getPlaylistsFolder()));
}
catch (IOException ignore) {}
}
public boolean folderExists()
{
return Files.exists(Paths.get(config.getPlaylistsFolder()));
return Files.exists(OtherUtil.getPath(config.getPlaylistsFolder()));
}
public void createPlaylist(String name) throws IOException
{
Files.createFile(Paths.get(config.getPlaylistsFolder()+File.separator+name+".txt"));
Files.createFile(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt"));
}
public void deletePlaylist(String name) throws IOException
{
Files.delete(Paths.get(config.getPlaylistsFolder()+File.separator+name+".txt"));
Files.delete(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt"));
}
public void writePlaylist(String name, String text) throws IOException
{
Files.write(Paths.get(config.getPlaylistsFolder()+File.separator+name+".txt"), text.trim().getBytes());
Files.write(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt"), text.trim().getBytes());
}
public Playlist getPlaylist(String name)
@@ -96,7 +96,7 @@ public class PlaylistLoader
{
boolean[] shuffle = {false};
List<String> list = new ArrayList<>();
Files.readAllLines(Paths.get(config.getPlaylistsFolder()+File.separator+name+".txt")).forEach(str ->
Files.readAllLines(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt")).forEach(str ->
{
String s = str.trim();
if(s.isEmpty())
@@ -157,101 +157,90 @@ public class PlaylistLoader
public void loadTracks(AudioPlayerManager manager, Consumer<AudioTrack> consumer, Runnable callback)
{
if(!loaded)
if(loaded)
return;
loaded = true;
for(int i=0; i<items.size(); i++)
{
loaded = true;
for(int i=0; i<items.size(); i++)
boolean last = i+1 == items.size();
int index = i;
manager.loadItemOrdered(name, items.get(i), new AudioLoadResultHandler()
{
boolean last = i+1==items.size();
int index = i;
manager.loadItemOrdered(name, items.get(i), new AudioLoadResultHandler()
private void done()
{
@Override
public void trackLoaded(AudioTrack at)
if(last)
{
if(config.isTooLong(at))
errors.add(new PlaylistLoadError(index, items.get(index), "This track is longer than the allowed maximum"));
else
{
at.setUserData(0L);
tracks.add(at);
consumer.accept(at);
}
if(last && callback!=null)
callback.run();
}
@Override
public void playlistLoaded(AudioPlaylist ap)
{
if(ap.isSearchResult())
{
if(config.isTooLong(ap.getTracks().get(0)))
errors.add(new PlaylistLoadError(index, items.get(index), "This track is longer than the allowed maximum"));
else
{
ap.getTracks().get(0).setUserData(0L);
tracks.add(ap.getTracks().get(0));
consumer.accept(ap.getTracks().get(0));
}
}
else if(ap.getSelectedTrack()!=null)
{
if(config.isTooLong(ap.getSelectedTrack()))
errors.add(new PlaylistLoadError(index, items.get(index), "This track is longer than the allowed maximum"));
else
{
ap.getSelectedTrack().setUserData(0L);
tracks.add(ap.getSelectedTrack());
consumer.accept(ap.getSelectedTrack());
}
}
else
{
List<AudioTrack> loaded = new ArrayList<>(ap.getTracks());
if(shuffle)
for(int first =0; first<loaded.size(); first++)
{
int second = (int)(Math.random()*loaded.size());
AudioTrack tmp = loaded.get(first);
loaded.set(first, loaded.get(second));
loaded.set(second, tmp);
}
loaded.removeIf(track -> config.isTooLong(track));
loaded.forEach(at -> at.setUserData(0L));
tracks.addAll(loaded);
loaded.forEach(at -> consumer.accept(at));
}
if(last && callback!=null)
if(shuffle)
shuffleTracks();
if(callback != null)
callback.run();
}
}
@Override
public void noMatches()
@Override
public void trackLoaded(AudioTrack at)
{
if(config.isTooLong(at))
errors.add(new PlaylistLoadError(index, items.get(index), "This track is longer than the allowed maximum"));
else
{
errors.add(new PlaylistLoadError(index, items.get(index), "No matches found."));
if(last && callback!=null)
callback.run();
at.setUserData(0L);
tracks.add(at);
consumer.accept(at);
}
done();
}
@Override
public void loadFailed(FriendlyException fe)
@Override
public void playlistLoaded(AudioPlaylist ap)
{
if(ap.isSearchResult())
{
errors.add(new PlaylistLoadError(index, items.get(index), "Failed to load track: "+fe.getLocalizedMessage()));
if(last && callback!=null)
callback.run();
trackLoaded(ap.getTracks().get(0));
}
});
}
else if(ap.getSelectedTrack()!=null)
{
trackLoaded(ap.getSelectedTrack());
}
else
{
List<AudioTrack> loaded = new ArrayList<>(ap.getTracks());
if(shuffle)
for(int first =0; first<loaded.size(); first++)
{
int second = (int)(Math.random()*loaded.size());
AudioTrack tmp = loaded.get(first);
loaded.set(first, loaded.get(second));
loaded.set(second, tmp);
}
loaded.removeIf(track -> config.isTooLong(track));
loaded.forEach(at -> at.setUserData(0L));
tracks.addAll(loaded);
loaded.forEach(at -> consumer.accept(at));
}
done();
}
@Override
public void noMatches()
{
errors.add(new PlaylistLoadError(index, items.get(index), "No matches found."));
done();
}
@Override
public void loadFailed(FriendlyException fe)
{
errors.add(new PlaylistLoadError(index, items.get(index), "Failed to load track: "+fe.getLocalizedMessage()));
done();
}
});
}
if(shuffle)
shuffleTracks();
}
public void shuffleTracks()
{
if(tracks!=null)
shuffle(tracks);
shuffle(tracks);
}
public String getName()
@@ -16,10 +16,12 @@
package com.jagrosh.jmusicbot.settings;
import com.jagrosh.jdautilities.command.GuildSettingsProvider;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import java.util.Collection;
import java.util.Collections;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
/**
*
@@ -34,8 +36,9 @@ public class Settings implements GuildSettingsProvider
private int volume;
private String defaultPlaylist;
private boolean repeatMode;
private String prefix;
public Settings(SettingsManager manager, String textId, String voiceId, String roleId, int volume, String defaultPlaylist, boolean repeatMode)
public Settings(SettingsManager manager, String textId, String voiceId, String roleId, int volume, String defaultPlaylist, boolean repeatMode, String prefix)
{
this.manager = manager;
try
@@ -65,9 +68,10 @@ public class Settings implements GuildSettingsProvider
this.volume = volume;
this.defaultPlaylist = defaultPlaylist;
this.repeatMode = repeatMode;
this.prefix = prefix;
}
public Settings(SettingsManager manager, long textId, long voiceId, long roleId, int volume, String defaultPlaylist, boolean repeatMode)
public Settings(SettingsManager manager, long textId, long voiceId, long roleId, int volume, String defaultPlaylist, boolean repeatMode, String prefix)
{
this.manager = manager;
this.textId = textId;
@@ -76,6 +80,7 @@ public class Settings implements GuildSettingsProvider
this.volume = volume;
this.defaultPlaylist = defaultPlaylist;
this.repeatMode = repeatMode;
this.prefix = prefix;
}
// Getters
@@ -109,6 +114,17 @@ public class Settings implements GuildSettingsProvider
return repeatMode;
}
public String getPrefix()
{
return prefix;
}
@Override
public Collection<String> getPrefixes()
{
return prefix == null ? Collections.EMPTY_SET : Collections.singleton(prefix);
}
// Setters
public void setTextChannel(TextChannel tc)
{
@@ -145,4 +161,10 @@ public class Settings implements GuildSettingsProvider
this.repeatMode = mode;
this.manager.writeSettings();
}
public void setPrefix(String prefix)
{
this.prefix = prefix;
this.manager.writeSettings();
}
}
@@ -16,11 +16,12 @@
package com.jagrosh.jmusicbot.settings;
import com.jagrosh.jdautilities.command.GuildSettingsManager;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.api.entities.Guild;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
@@ -37,7 +38,7 @@ public class SettingsManager implements GuildSettingsManager
{
this.settings = new HashMap<>();
try {
JSONObject loadedSettings = new JSONObject(new String(Files.readAllBytes(Paths.get("serversettings.json"))));
JSONObject loadedSettings = new JSONObject(new String(Files.readAllBytes(OtherUtil.getPath("serversettings.json"))));
loadedSettings.keySet().forEach((id) -> {
JSONObject o = loadedSettings.getJSONObject(id);
settings.put(Long.parseLong(id), new Settings(this,
@@ -46,7 +47,8 @@ public class SettingsManager implements GuildSettingsManager
o.has("dj_role_id") ? o.getString("dj_role_id") : null,
o.has("volume") ? o.getInt("volume") : 100,
o.has("default_playlist")? o.getString("default_playlist"): null,
o.has("repeat") ? o.getBoolean("repeat") : false));
o.has("repeat") ? o.getBoolean("repeat") : false,
o.has("prefix") ? o.getString("prefix") : null));
});
} catch(IOException | JSONException e) {
LoggerFactory.getLogger("Settings").warn("Failed to load server settings (this is normal if no settings have been set yet): "+e);
@@ -72,7 +74,7 @@ public class SettingsManager implements GuildSettingsManager
private Settings createDefaultSettings()
{
return new Settings(this, 0, 0, 0, 100, null, false);
return new Settings(this, 0, 0, 0, 100, null, false, null);
}
protected void writeSettings()
@@ -89,14 +91,16 @@ public class SettingsManager implements GuildSettingsManager
o.put("dj_role_id", Long.toString(s.roleId));
if(s.getVolume()!=100)
o.put("volume",s.getVolume());
if(s.getDefaultPlaylist()!=null)
if(s.getDefaultPlaylist() != null)
o.put("default_playlist", s.getDefaultPlaylist());
if(s.getRepeatMode())
o.put("repeat", true);
if(s.getPrefix() != null)
o.put("prefix", s.getPrefix());
obj.put(Long.toString(key), o);
});
try {
Files.write(Paths.get("serversettings.json"), obj.toString(4).getBytes());
Files.write(OtherUtil.getPath("serversettings.json"), obj.toString(4).getBytes());
} catch(IOException ex){
LoggerFactory.getLogger("Settings").warn("Failed to write to file: "+ex);
}
@@ -16,9 +16,9 @@
package com.jagrosh.jmusicbot.utils;
import java.util.List;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
/**
*
@@ -92,6 +92,9 @@ public class FormatUtil {
public static String filter(String input)
{
return input.replace("@everyone", "@\u0435veryone").replace("@here", "@h\u0435re").trim(); // cyrillic letter e
return input.replace("\u202E","")
.replace("@everyone", "@\u0435veryone") // cyrillic letter e
.replace("@here", "@h\u0435re") // cyrillic letter e
.trim();
}
}
@@ -18,10 +18,13 @@ package com.jagrosh.jmusicbot.utils;
import com.jagrosh.jmusicbot.JMusicBot;
import com.jagrosh.jmusicbot.entities.Prompt;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.entities.Game;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import okhttp3.*;
import org.json.JSONException;
import org.json.JSONObject;
@@ -37,7 +40,38 @@ public class OtherUtil
+ "Current version: %s\n"
+ "New Version: %s\n\n"
+ "Please visit https://github.com/jagrosh/MusicBot/releases/latest to get the latest release.";
private final static String WINDOWS_INVALID_PATH = "c:\\windows\\system32\\";
/**
* gets a Path from a String
* also fixes the windows tendency to try to start in system32
* any time the bot tries to access this path, it will instead start in the location of the jar file
*
* @param path the string path
* @return the Path object
*/
public static Path getPath(String path)
{
// special logic to prevent trying to access system32
if(path.toLowerCase().startsWith(WINDOWS_INVALID_PATH))
{
String filename = path.substring(WINDOWS_INVALID_PATH.length());
try
{
path = new File(JMusicBot.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile().getPath() + File.separator + filename;
}
catch(URISyntaxException ex) {}
}
return Paths.get(path);
}
/**
* Loads a resource from the jar as a string
*
* @param clazz class base object
* @param name name of resource
* @return string containing the contents of the resource
*/
public static String loadResource(Object clazz, String name)
{
try(BufferedReader reader = new BufferedReader(new InputStreamReader(clazz.getClass().getResourceAsStream(name))))
@@ -52,6 +86,12 @@ public class OtherUtil
}
}
/**
* Loads image data from a URL
*
* @param url url of image
* @return inputstream of url
*/
public static InputStream imageFromUrl(String url)
{
if(url==null)
@@ -67,28 +107,39 @@ public class OtherUtil
return null;
}
public static Game parseGame(String game)
/**
* Parses an activity from a string
*
* @param game the game, including the action such as 'playing' or 'watching'
* @return the parsed activity
*/
public static Activity parseGame(String game)
{
if(game==null || game.trim().isEmpty() || game.trim().equalsIgnoreCase("default"))
return null;
String lower = game.toLowerCase();
if(lower.startsWith("playing"))
return Game.playing(game.substring(7).trim());
return Activity.playing(makeNonEmpty(game.substring(7).trim()));
if(lower.startsWith("listening to"))
return Game.listening(game.substring(12).trim());
return Activity.listening(makeNonEmpty(game.substring(12).trim()));
if(lower.startsWith("listening"))
return Game.listening(game.substring(9).trim());
return Activity.listening(makeNonEmpty(game.substring(9).trim()));
if(lower.startsWith("watching"))
return Game.watching(game.substring(8).trim());
return Activity.watching(makeNonEmpty(game.substring(8).trim()));
if(lower.startsWith("streaming"))
{
String[] parts = game.substring(9).trim().split("\\s+", 2);
if(parts.length == 2)
{
return Game.streaming(parts[1], "https://twitch.tv/"+parts[0]);
return Activity.streaming(makeNonEmpty(parts[1]), "https://twitch.tv/"+parts[0]);
}
}
return Game.playing(game);
return Activity.playing(game);
}
public static String makeNonEmpty(String str)
{
return str == null || str.isEmpty() ? "\u200B" : str;
}
public static OnlineStatus parseStatus(String status)
+43
View File
@@ -123,6 +123,49 @@ updatealerts=true
lyrics.default = "A-Z Lyrics"
// These settings allow you to configure custom aliases for all commands.
// Multiple aliases may be given, separated by commas.
//
// Example 1: Giving command "play" the alias "p":
// play = [ p ]
//
// Example 2: Giving command "search" the aliases "yts" and "find":
// search = [ yts, find ]
aliases {
// General commands
settings = [ status ]
// Music commands
lyrics = []
nowplaying = [ np, current ]
play = []
playlists = [ pls ]
queue = [ list ]
remove = [ delete ]
scsearch = []
search = [ ytsearch ]
shuffle = []
skip = [ voteskip ]
// Admin commands
prefix = [ setprefix ]
setdj = []
settc = []
setvc = []
// DJ Commands
forceremove = [ forcedelete, modremove, moddelete, modelete ]
forceskip = [ modskip ]
movetrack = [ move ]
pause = []
playnext = []
repeat = []
skipto = [ jumpto ]
stop = []
volume = [ vol ]
}
// If you set this to true, it will enable the eval command for the bot owner. This command
// allows the bot owner to run arbitrary code from the bot's account.
//