Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/target/
/Playlists/
/test/
.idea
*.json
*.txt
nb*.xml
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use an OpenJDK 11 image as the base image
FROM openjdk:11-jre-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the JAR file and the config file into the container
COPY MusicBot.jar /app/MusicBot.jar
COPY config.txt /app/config.txt

# Expose any port needed by the bot (optional, replace 8080 if required)
# EXPOSE 8080

# Run the JAR file with the -Dnogui=true argument
CMD ["java", "-Dnogui=true", "-jar", "/app/MusicBot.jar", "config.txt"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unofficial JMusicBot update (Forked from: https://github.com/d-pacheco/MusicBot)
Compiled using Github Actions

### To enable Oauth
- In your bot folder, edit "config.txt" and add `youtubeoauth2=true` to enable Youtube oauth.
- USE A BURNER GOOGLE ACCOUNT AS YOU MAY GET BANNED IN THE WORSE CASE.

<img align="right" src="https://i.imgur.com/zrE80HY.png" height="200" width="200">

# JMusicBot
Expand Down
51 changes: 37 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>chewtils-snapshots</id>
<url>https://m2.chew.pro/snapshots/</url>
</repository>
<repository>
<id>m2.duncte123.dev</id>
<name>m2-duncte123</name>
Expand All @@ -42,25 +46,34 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.4.1_353</version>
<version>5.6.1</version>
</dependency>
<!-- Chewtils modules (drop-in for JDA-Utilities) -->
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<version>3.0.5</version>
<type>pom</type>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils-commons</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils-command</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils-menu</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>

<!-- Music Dependencies -->
<dependency>
<groupId>dev.arbjerg</groupId>
<artifactId>lavaplayer</artifactId>
<version>2.2.1</version>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>dev.lavalink.youtube</groupId>
<artifactId>common</artifactId>
<version>1.5.2</version>
<version>1.13.5</version>
</dependency>
<dependency>
<groupId>com.github.jagrosh</groupId>
Expand All @@ -71,36 +84,46 @@
<groupId>com.dunctebot</groupId>
<artifactId>sourcemanagers</artifactId>
<version>1.9.0</version>
<exclusions>
<exclusion>
<groupId>dev.lavalink.youtube</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer-ext-youtube</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Misc Internal Dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.2</version>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
<version>1.18.1</version>
</dependency>

<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jagrosh.jmusicbot.playlist.PlaylistLoader;
import com.jagrosh.jmusicbot.settings.SettingsManager;
import java.util.Objects;
import com.jagrosh.jmusicbot.utils.YoutubeOauth2TokenHandler;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
Expand All @@ -44,6 +45,7 @@ public class Bot
private final PlaylistLoader playlists;
private final NowplayingHandler nowplaying;
private final AloneInVoiceHandler aloneInVoiceHandler;
private final YoutubeOauth2TokenHandler youTubeOauth2TokenHandler;

private boolean shuttingDown = false;
private JDA jda;
Expand All @@ -56,6 +58,8 @@ public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings)
this.settings = settings;
this.playlists = new PlaylistLoader(config);
this.threadpool = Executors.newSingleThreadScheduledExecutor();
this.youTubeOauth2TokenHandler = new YoutubeOauth2TokenHandler();
this.youTubeOauth2TokenHandler.init();
this.players = new PlayerManager(this);
this.players.init();
this.nowplaying = new NowplayingHandler(this);
Expand Down Expand Up @@ -103,6 +107,11 @@ public AloneInVoiceHandler getAloneInVoiceHandler()
{
return aloneInVoiceHandler;
}

public YoutubeOauth2TokenHandler getYouTubeOauth2Handler()
{
return youTubeOauth2TokenHandler;
}

public JDA getJDA()
{
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BotConfig
private String token, prefix, altprefix, helpWord, playlistsFolder, logLevel,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji,
evalEngine;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private boolean youtubeOauth2, stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private int maxYTPlaylistPages;
private double skipratio;
Expand Down Expand Up @@ -84,6 +84,7 @@ public void load()
searchingEmoji = config.getString("searching");
game = OtherUtil.parseGame(config.getString("game"));
status = OtherUtil.parseStatus(config.getString("status"));
youtubeOauth2 = config.getBoolean("youtubeoauth2");
stayInChannel = config.getBoolean("stayinchannel");
songInGame = config.getBoolean("songinstatus");
npImages = config.getBoolean("npimages");
Expand Down Expand Up @@ -293,6 +294,11 @@ public String getHelp()
return helpWord;
}

public boolean useYoutubeOauth2()
{
return youtubeOauth2;
}

public boolean getStay()
{
return stayInChannel;
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jdautilities.examples.command.*;
import com.jagrosh.jmusicbot.commands.admin.*;
import com.jagrosh.jmusicbot.commands.dj.*;
import com.jagrosh.jmusicbot.commands.general.*;
Expand All @@ -30,7 +29,6 @@
import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.awt.Color;
import java.util.Arrays;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
Expand All @@ -47,7 +45,7 @@
public class JMusicBot
{
public final static Logger LOG = LoggerFactory.getLogger(JMusicBot.class);
public final static Permission[] RECOMMENDED_PERMS = {Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
public final static Permission[] RECOMMENDED_PERMS = {Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE, Permission.MESSAGE_EXT_EMOJI,
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};
Expand All @@ -74,7 +72,7 @@ private static void startBot()
Prompt prompt = new Prompt("JMusicBot");

// startup checks
OtherUtil.checkVersion(prompt);
// OtherUtil.checkVersion(prompt);
OtherUtil.checkJavaVersion(prompt);

// load config
Expand Down Expand Up @@ -117,13 +115,12 @@ private static void startBot()
try
{
JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS))
.enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS)
.enableCache(CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.EMOJI, CacheFlag.ONLINE_STATUS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JDA 5 requires intents to be explicitly enabled
Thus you are missing, otherwise you will not be able to read any content or members
.enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)

.setActivity(config.isGameNone() ? null : Activity.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListeners(client, waiter, new Listener(bot))
.setBulkDeleteSplittingEnabled(true)
.build();
bot.setJDA(jda);

Expand All @@ -147,13 +144,6 @@ private static void startBot()
+ "on https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot");
}
}
catch (LoginException ex)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are "
+ "editing the correct config.txt file, and that you have used the "
+ "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
System.exit(1);
}
catch(IllegalArgumentException ex)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is "
Expand All @@ -170,14 +160,6 @@ private static void startBot()

private static CommandClient createCommandClient(BotConfig config, SettingsManager settings, Bot bot)
{
// instantiate about command
AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(),
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")",
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"},
RECOMMENDED_PERMS);
aboutCommand.setIsAuthor(false);
aboutCommand.setReplacementCharacter("\uD83C\uDFB6"); // 🎶

// set up the command client
CommandClientBuilder cb = new CommandClientBuilder()
.setPrefix(config.getPrefix())
Expand All @@ -187,8 +169,7 @@ private static CommandClient createCommandClient(BotConfig config, SettingsManag
.setHelpWord(config.getHelp())
.setLinkedCacheSize(200)
.setGuildSettingsManager(settings)
.addCommands(aboutCommand,
new PingCommand(),
.addCommands(
new SettingsCmd(bot),

new LyricsCmd(bot),
Expand Down
Loading