Skip to content

Commit c4e11d6

Browse files
committed
update deps, minor code cleanup
1 parent 85aebe8 commit c4e11d6

File tree

12 files changed

+116
-68
lines changed

12 files changed

+116
-68
lines changed

.github/workflows/make-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
artifacts: "*.jar"
6363
body: |
6464
${{ github.event.inputs.info }}
65+
6566
---
6667
### Setup
6768
https://jmusicbot.com/setup

pom.xml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,28 @@
2020
<repository>
2121
<id>jitpack.io</id>
2222
<url>https://jitpack.io</url>
23+
<snapshots>
24+
<enabled>true</enabled>
25+
<updatePolicy>always</updatePolicy>
26+
</snapshots>
2327
</repository>
2428
</repositories>
2529

2630
<dependencies>
31+
<!-- Discord Dependencies -->
2732
<dependency>
2833
<groupId>net.dv8tion</groupId>
2934
<artifactId>JDA</artifactId>
30-
<version>4.3.0_324</version>
35+
<version>4.4.0_352</version>
3136
</dependency>
37+
<dependency>
38+
<groupId>com.jagrosh</groupId>
39+
<artifactId>jda-utilities</artifactId>
40+
<version>3.0.5</version>
41+
<type>pom</type>
42+
</dependency>
43+
44+
<!-- Music Dependencies -->
3245
<!-- using a fork of this to fix some issues faster -->
3346
<!-- dependency>
3447
<groupId>com.sedmelluq</groupId>
@@ -46,23 +59,13 @@
4659
<artifactId>lavaplayer-natives-extra</artifactId>
4760
<version>1.3.13</version>
4861
</dependency-->
49-
<dependency>
50-
<groupId>com.jagrosh</groupId>
51-
<artifactId>jda-utilities</artifactId>
52-
<version>3.0.5</version>
53-
<type>pom</type>
54-
</dependency>
55-
<!-- jitpack for now, we need to version this correctly later -->
5662
<dependency>
5763
<groupId>com.github.jagrosh</groupId>
5864
<artifactId>JLyrics</artifactId>
59-
<version>-SNAPSHOT</version>
65+
<version>master-SNAPSHOT</version>
6066
</dependency>
61-
<!--dependency>
62-
<groupId>com.jagrosh</groupId>
63-
<artifactId>JLyrics</artifactId>
64-
<version>0.6</version>
65-
</dependency-->
67+
68+
<!-- Misc Internal Dependencies -->
6669
<dependency>
6770
<groupId>ch.qos.logback</groupId>
6871
<artifactId>logback-classic</artifactId>
@@ -78,6 +81,8 @@
7881
<artifactId>jsoup</artifactId>
7982
<version>1.14.2</version>
8083
</dependency>
84+
85+
<!-- Testing Dependencies -->
8186
<dependency>
8287
<groupId>junit</groupId>
8388
<artifactId>junit</artifactId>

src/main/java/com/jagrosh/jmusicbot/BotConfig.java

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.IOException;
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26-
import java.util.Collections;
2726
import net.dv8tion.jda.api.OnlineStatus;
2827
import net.dv8tion.jda.api.entities.Activity;
2928

@@ -63,13 +62,7 @@ public void load()
6362
try
6463
{
6564
// get the path to the config, default config.txt
66-
path = OtherUtil.getPath(System.getProperty("config.file", System.getProperty("config", "config.txt")));
67-
if(path.toFile().exists())
68-
{
69-
if(System.getProperty("config.file") == null)
70-
System.setProperty("config.file", System.getProperty("config", path.toAbsolutePath().toString()));
71-
ConfigFactory.invalidateCaches();
72-
}
65+
path = getConfigPath();
7366

7467
// load in the config file, plus the default values
7568
//Config config = ConfigFactory.parseFile(path.toFile()).withFallback(ConfigFactory.load());
@@ -161,19 +154,9 @@ public void load()
161154

162155
private void writeToFile()
163156
{
164-
String original = OtherUtil.loadResource(this, "/reference.conf");
165-
byte[] bytes;
166-
if(original==null)
167-
{
168-
bytes = ("token = "+token+"\r\nowner = "+owner).getBytes();
169-
}
170-
else
171-
{
172-
bytes = original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN))
173-
.replace("BOT_TOKEN_HERE", token)
157+
byte[] bytes = loadDefaultConfig().replace("BOT_TOKEN_HERE", token)
174158
.replace("0 // OWNER ID", Long.toString(owner))
175159
.trim().getBytes();
176-
}
177160
try
178161
{
179162
Files.write(path, bytes);
@@ -186,6 +169,43 @@ private void writeToFile()
186169
}
187170
}
188171

172+
private static String loadDefaultConfig()
173+
{
174+
String original = OtherUtil.loadResource(new JMusicBot(), "/reference.conf");
175+
return original==null
176+
? "token = BOT_TOKEN_HERE\r\nowner = 0 // OWNER ID"
177+
: original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN)).trim();
178+
}
179+
180+
private static Path getConfigPath()
181+
{
182+
Path path = OtherUtil.getPath(System.getProperty("config.file", System.getProperty("config", "config.txt")));
183+
if(path.toFile().exists())
184+
{
185+
if(System.getProperty("config.file") == null)
186+
System.setProperty("config.file", System.getProperty("config", path.toAbsolutePath().toString()));
187+
ConfigFactory.invalidateCaches();
188+
}
189+
return path;
190+
}
191+
192+
public static void writeDefaultConfig()
193+
{
194+
Prompt prompt = new Prompt(null, null, true, true);
195+
prompt.alert(Prompt.Level.INFO, "JMusicBot Config", "Generating default config file");
196+
Path path = BotConfig.getConfigPath();
197+
byte[] bytes = BotConfig.loadDefaultConfig().getBytes();
198+
try
199+
{
200+
prompt.alert(Prompt.Level.INFO, "JMusicBot Config", "Writing default config file to " + path.toAbsolutePath().toString());
201+
Files.write(path, bytes);
202+
}
203+
catch(Exception ex)
204+
{
205+
prompt.alert(Prompt.Level.ERROR, "JMusicBot Config", "An error occurred writing the default config file: " + ex.getMessage());
206+
}
207+
}
208+
189209
public boolean isValid()
190210
{
191211
return valid;

src/main/java/com/jagrosh/jmusicbot/JMusicBot.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,51 @@
4343
*/
4444
public class JMusicBot
4545
{
46-
public final static String PLAY_EMOJI = "\u25B6"; // ▶
47-
public final static String PAUSE_EMOJI = "\u23F8"; // ⏸
48-
public final static String STOP_EMOJI = "\u23F9"; // ⏹
46+
public final static Logger LOG = LoggerFactory.getLogger(JMusicBot.class);
4947
public final static Permission[] RECOMMENDED_PERMS = {Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
5048
Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE, Permission.MESSAGE_EXT_EMOJI,
5149
Permission.MANAGE_CHANNEL, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.NICKNAME_CHANGE};
5250
public final static GatewayIntent[] INTENTS = {GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES};
51+
5352
/**
5453
* @param args the command line arguments
5554
*/
5655
public static void main(String[] args)
5756
{
58-
// startup log
59-
Logger log = LoggerFactory.getLogger("Startup");
60-
57+
if(args.length > 0)
58+
switch(args[0].toLowerCase())
59+
{
60+
case "generate-config":
61+
BotConfig.writeDefaultConfig();
62+
return;
63+
default:
64+
}
65+
startBot();
66+
}
67+
68+
private static void startBot()
69+
{
6170
// create prompt to handle startup
62-
Prompt prompt = new Prompt("JMusicBot", "Switching to nogui mode. You can manually start in nogui mode by including the -Dnogui=true flag.");
63-
64-
// get and check latest version
65-
String version = OtherUtil.checkVersion(prompt);
71+
Prompt prompt = new Prompt("JMusicBot");
6672

67-
// check for valid java version
68-
if(!System.getProperty("java.vm.name").contains("64"))
69-
prompt.alert(Prompt.Level.WARNING, "Java Version", "It appears that you may not be using a supported Java version. Please use 64-bit java.");
73+
// startup checks
74+
OtherUtil.checkVersion(prompt);
75+
OtherUtil.checkJavaVersion(prompt);
7076

7177
// load config
7278
BotConfig config = new BotConfig(prompt);
7379
config.load();
7480
if(!config.isValid())
7581
return;
82+
LOG.info("Loaded config from " + config.getConfigLocation());
7683

7784
// set up the listener
7885
EventWaiter waiter = new EventWaiter();
7986
SettingsManager settings = new SettingsManager();
8087
Bot bot = new Bot(waiter, config, settings);
8188

8289
AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(),
83-
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v"+version+")",
90+
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")",
8491
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"},
8592
RECOMMENDED_PERMS);
8693
aboutCommand.setIsAuthor(false);
@@ -160,14 +167,12 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
160167
}
161168
catch(Exception e)
162169
{
163-
log.error("Could not start GUI. If you are "
170+
LOG.error("Could not start GUI. If you are "
164171
+ "running on a server or in a location where you cannot display a "
165172
+ "window, please run in nogui mode using the -Dnogui=true flag.");
166173
}
167174
}
168175

169-
log.info("Loaded config from " + config.getConfigLocation());
170-
171176
// attempt to log in and start
172177
try
173178
{

src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
*/
4747
public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
4848
{
49+
public final static String PLAY_EMOJI = "\u25B6"; // ▶
50+
public final static String PAUSE_EMOJI = "\u23F8"; // ⏸
51+
public final static String STOP_EMOJI = "\u23F9"; // ⏹
52+
4953
private final FairQueue<QueuedTrack> queue = new FairQueue<>();
5054
private final List<AudioTrack> defaultQueue = new LinkedList<>();
5155
private final Set<String> votes = new HashSet<>();
@@ -233,12 +237,12 @@ public Message getNowPlaying(JDA jda)
233237
eb.setFooter("Source: " + track.getInfo().author, null);
234238

235239
double progress = (double)audioPlayer.getPlayingTrack().getPosition()/track.getDuration();
236-
eb.setDescription((audioPlayer.isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI)
240+
eb.setDescription(getStatusEmoji()
237241
+ " "+FormatUtil.progressBar(progress)
238242
+ " `[" + FormatUtil.formatTime(track.getPosition()) + "/" + FormatUtil.formatTime(track.getDuration()) + "]` "
239243
+ FormatUtil.volumeIcon(audioPlayer.getVolume()));
240244

241-
return mb.setEmbed(eb.build()).build();
245+
return mb.setEmbeds(eb.build()).build();
242246
}
243247
else return null;
244248
}
@@ -248,9 +252,9 @@ public Message getNoMusicPlaying(JDA jda)
248252
Guild guild = guild(jda);
249253
return new MessageBuilder()
250254
.setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing...**"))
251-
.setEmbed(new EmbedBuilder()
255+
.setEmbeds(new EmbedBuilder()
252256
.setTitle("No music playing")
253-
.setDescription(JMusicBot.STOP_EMOJI+" "+FormatUtil.progressBar(-1)+" "+FormatUtil.volumeIcon(audioPlayer.getVolume()))
257+
.setDescription(STOP_EMOJI+" "+FormatUtil.progressBar(-1)+" "+FormatUtil.volumeIcon(audioPlayer.getVolume()))
254258
.setColor(guild.getSelfMember().getColor())
255259
.build()).build();
256260
}
@@ -265,11 +269,16 @@ public String getTopicFormat(JDA jda)
265269
if(title==null || title.equals("Unknown Title"))
266270
title = track.getInfo().uri;
267271
return "**"+title+"** ["+(userid==0 ? "autoplay" : "<@"+userid+">")+"]"
268-
+ "\n" + (audioPlayer.isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI) + " "
272+
+ "\n" + getStatusEmoji() + " "
269273
+ "[" + FormatUtil.formatTime(track.getDuration()) + "] "
270274
+ FormatUtil.volumeIcon(audioPlayer.getVolume());
271275
}
272-
else return "No music playing " + JMusicBot.STOP_EMOJI + " " + FormatUtil.volumeIcon(audioPlayer.getVolume());
276+
else return "No music playing " + STOP_EMOJI + " " + FormatUtil.volumeIcon(audioPlayer.getVolume());
277+
}
278+
279+
public String getStatusEmoji()
280+
{
281+
return audioPlayer.isPaused() ? PAUSE_EMOJI : PLAY_EMOJI;
273282
}
274283

275284
// Audio Send Handler methods

src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
2121
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
2222
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
23-
import com.typesafe.config.Config;
2423
import net.dv8tion.jda.api.entities.Guild;
2524

2625
/**

src/main/java/com/jagrosh/jmusicbot/commands/general/SettingsCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void execute(CommandEvent event)
6868
.setFooter(event.getJDA().getGuilds().size() + " servers | "
6969
+ event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()
7070
+ " audio connections", null);
71-
event.getChannel().sendMessage(builder.setEmbed(ebuilder.build()).build()).queue();
71+
event.getChannel().sendMessage(builder.setEmbeds(ebuilder.build()).build()).queue();
7272
}
7373

7474
}

src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ else if (playlist.getSelectedTrack()!=null)
173173
else
174174
{
175175
int count = loadPlaylist(playlist, null);
176-
if(count==0)
176+
if(playlist.getTracks().size() == 0)
177+
{
178+
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" The playlist "+(playlist.getName()==null ? "" : "(**"+playlist.getName()
179+
+"**) ")+" could not be loaded or contained 0 entries")).queue();
180+
}
181+
else if(count==0)
177182
{
178183
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" All entries in this playlist "+(playlist.getName()==null ? "" : "(**"+playlist.getName()
179184
+"**) ")+"were longer than the allowed maximum (`"+bot.getConfig().getMaxTime()+"`)")).queue();

src/main/java/com/jagrosh/jmusicbot/commands/music/QueueCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void doCommand(CommandEvent event)
7878
Message nonowp = ah.getNoMusicPlaying(event.getJDA());
7979
Message built = new MessageBuilder()
8080
.setContent(event.getClient().getWarning() + " There is no music in the queue!")
81-
.setEmbed((nowp==null ? nonowp : nowp).getEmbeds().get(0)).build();
81+
.setEmbeds((nowp==null ? nonowp : nowp).getEmbeds().get(0)).build();
8282
event.reply(built, m ->
8383
{
8484
if(nowp!=null)
@@ -108,7 +108,7 @@ private String getQueueTitle(AudioHandler ah, String success, int songslength, l
108108
StringBuilder sb = new StringBuilder();
109109
if(ah.getPlayer().getPlayingTrack()!=null)
110110
{
111-
sb.append(ah.getPlayer().isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI).append(" **")
111+
sb.append(ah.getStatusEmoji()).append(" **")
112112
.append(ah.getPlayer().getPlayingTrack().getInfo().title).append("**\n");
113113
}
114114
return FormatUtil.filter(sb.append(success).append(" Current Queue | ").append(songslength)

src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public List<String> getPlaylistNames()
5353
else
5454
{
5555
createFolder();
56-
return Collections.EMPTY_LIST;
56+
return Collections.emptyList();
5757
}
5858
}
5959

src/main/java/com/jagrosh/jmusicbot/settings/Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public double getSkipRatio()
130130
@Override
131131
public Collection<String> getPrefixes()
132132
{
133-
return prefix == null ? Collections.EMPTY_SET : Collections.singleton(prefix);
133+
return prefix == null ? Collections.emptySet() : Collections.singleton(prefix);
134134
}
135135

136136
// Setters

src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ public static OnlineStatus parseStatus(String status)
150150
return st == null ? OnlineStatus.ONLINE : st;
151151
}
152152

153-
public static String checkVersion(Prompt prompt)
153+
public static void checkJavaVersion(Prompt prompt)
154+
{
155+
if(!System.getProperty("java.vm.name").contains("64"))
156+
prompt.alert(Prompt.Level.WARNING, "Java Version",
157+
"It appears that you may not be using a supported Java version. Please use 64-bit java.");
158+
}
159+
160+
public static void checkVersion(Prompt prompt)
154161
{
155162
// Get current version number
156163
String version = getCurrentVersion();
@@ -160,11 +167,8 @@ public static String checkVersion(Prompt prompt)
160167

161168
if(latestVersion!=null && !latestVersion.equals(version))
162169
{
163-
prompt.alert(Prompt.Level.WARNING, "Version", String.format(NEW_VERSION_AVAILABLE, version, latestVersion));
170+
prompt.alert(Prompt.Level.WARNING, "JMusicBot Version", String.format(NEW_VERSION_AVAILABLE, version, latestVersion));
164171
}
165-
166-
// Return the current version
167-
return version;
168172
}
169173

170174
public static String getCurrentVersion()

0 commit comments

Comments
 (0)