Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jagrosh committed Dec 5, 2018
1 parent c88979a commit c0f0d45
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 325 deletions.
26 changes: 14 additions & 12 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
[download]: https://github.com/jagrosh/MusicBot/releases/latest
[release]: https://img.shields.io/github/release/jagrosh/MusicBot.svg
[setup]: https://github.com/jagrosh/MusicBot/wiki/Setup
[rpi]: https://github.com/jagrosh/MusicBot/wiki/JMusicBot-on-Raspberry-Pi
[features]: https://github.com/jagrosh/MusicBot/projects/1

## General Troubleshooting

Please check off these steps before suggesting a feature or reporting a bug:

- [ ] I am running the [latest version][download]: [![Release][release]][download]
- [ ] I have followed all instructions on the [setup page][setup] (and if applicable, [Raspberry Pi][rpi])
- [ ] I have read through the [planned and suggested features][features]
- [ ] I am running the [latest version][download]: [![Release][release]][download]
- [ ] I have followed all instructions on the [setup page][setup] (and if applicable, [Raspberry Pi][rpi])
- [ ] I have read through the [planned and suggested features][features]

## Issue

### Issue Type

- [ ] Bug Report
- [ ] Feature Request
- [ ] Bug Report
- [ ] Feature Request

### Description

Replace this with a description of your bug or feature request. Please provide screenshots and logs as applicable.
Replace this with a description of your bug or feature request. Please provide screenshots and logs as applicable.



[download]: https://github.com/jagrosh/MusicBot/releases/latest
[release]: https://img.shields.io/github/release/jagrosh/MusicBot.svg
[setup]: https://github.com/jagrosh/MusicBot/wiki/Setup
[rpi]: https://github.com/jagrosh/MusicBot/wiki/JMusicBot-on-Raspberry-Pi
[features]: https://github.com/jagrosh/MusicBot/projects/1
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
[![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)

# JMusicBot
## JMusicBot
A Discord music bot with a clean interface, and that is easy to set up and run yourself

[![Setup](http://i.imgur.com/VvXYp5j.png)](https://github.com/jagrosh/MusicBot/wiki/Setup)

# Features
* Easy to run (just make sure Java is installed, and run!)
* Fast loading of songs
* No external keys needed (besides a Discord Bot token)
* Smooth playback
* Server-specific setup for the "DJ" role that can moderate the music
* Clean and beautiful menus
* Channel-topic playback bar
* Supports many sites, including Youtube, Soundcloud, and more
* Supports many online radio/streams
* Supports local files
* Playlist support (both web/youtube, and local)

# Setup
## Features
* Easy to run (just make sure Java is installed, and run!)
* Fast loading of songs
* No external keys needed (besides a Discord Bot token)
* Smooth playback
* Server-specific setup for the "DJ" role that can moderate the music
* Clean and beautiful menus
* Channel-topic playback bar
* Supports many sites, including Youtube, Soundcloud, and more
* Supports many online radio/streams
* Supports local files
* Playlist support (both web/youtube, and local)

## Setup
Please see the [Setup Page](https://github.com/jagrosh/MusicBot/wiki/Setup) in the wiki to run this bot yourself!

# Questions/Suggestions/Bug Reports
## Questions/Suggestions/Bug Reports
**Please read the [Suggested/Planned Features List](https://github.com/jagrosh/MusicBot/projects/1) before suggesting a feature**. If you'd like to suggest changes to how the bot functions, recommend more customization options, or report bugs, feel free to either open an [Issue](https://github.com/jagrosh/MusicBot/issues) on this repository, or join [my Discord server](https://discord.gg/0p9LSGoRLu6Pet0k). (Note: I will not accept any feature requests that will require additional API keys, nor any non-music features). If you like this bot, be sure to add a star to the libraries that make this possible: [**JDA**](https://github.com/DV8FromTheWorld/JDA) and [**lavaplayer**](https://github.com/sedmelluq/lavaplayer)

# Example
## Example
![Example](https://i.imgur.com/tevrtKt.png)

# Editing
## Editing
This bot (and the source code here) is not meant to be edited. The main purpose of having the source public is to show the capabilities of the libraries, and to allow others to understand how the bot works. There are many requirements and dependencies required to edit and compile it, and there will not be support provided for people looking to make changes on their own. Instead, consider making a feature request (see the above section). If you still choose to make edits, please do so in accordance with the Apache 2.0 License.
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static void main(String[] args)
new PlaylistCmd(bot),
new SetavatarCmd(),
new SetgameCmd(),
new SetnameCmd(bot),
new SetnameCmd(),
new SetstatusCmd(),
new ShutdownCmd(bot)
);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/jagrosh/jmusicbot/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public void onReady(ReadyEvent event)
{
String defpl = bot.getSettingsManager().getSettings(guild).getDefaultPlaylist();
VoiceChannel vc = bot.getSettingsManager().getSettings(guild).getVoiceChannel(guild);
if(defpl!=null && vc!=null)
if(defpl!=null && vc!=null && bot.getPlayerManager().setUpHandler(guild).playFromDefault())
{
if(bot.getPlayerManager().setUpHandler(guild).playFromDefault())
guild.getAudioManager().openAudioConnection(vc);
guild.getAudioManager().openAudioConnection(vc);
}
}
catch(Exception ex) {}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import com.jagrosh.jmusicbot.queue.FairQueue;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import static com.jagrosh.jmusicbot.utils.FormatUtil.formatTime;
import static com.jagrosh.jmusicbot.utils.FormatUtil.volumeIcon;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
Expand Down Expand Up @@ -256,10 +254,10 @@ public String getTopicFormat(JDA jda)
title = track.getInfo().uri;
return "**"+title+"** ["+(userid==0 ? "autoplay" : "<@"+userid+">")+"]"
+ "\n"+(audioPlayer.isPaused()?"\u23F8":"\u25B6")+" "
+"["+formatTime(track.getDuration())+"] "
+volumeIcon(audioPlayer.getVolume());
+"["+FormatUtil.formatTime(track.getDuration())+"] "
+FormatUtil.volumeIcon(audioPlayer.getVolume());
}
else return "No music playing \u23F9 " + volumeIcon(audioPlayer.getVolume());
else return "No music playing \u23F9 " + FormatUtil.volumeIcon(audioPlayer.getVolume());
}

// Audio Send Handler methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.entities.Pair;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@
package com.jagrosh.jmusicbot.commands.dj;

import com.jagrosh.jdautilities.command.CommandEvent;
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.music.PlayCmd;
import static com.jagrosh.jmusicbot.commands.music.PlayCmd.CANCEL;
import static com.jagrosh.jmusicbot.commands.music.PlayCmd.LOAD;
import com.jagrosh.jmusicbot.utils.FormatUtil;
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 java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.exceptions.PermissionException;

/**
*
Expand Down Expand Up @@ -69,9 +62,9 @@ public void doCommand(CommandEvent event)

private class ResultHandler implements AudioLoadResultHandler
{
final Message m;
final CommandEvent event;
final boolean ytsearch;
private final Message m;
private final CommandEvent event;
private final boolean ytsearch;

private ResultHandler(Message m, CommandEvent event, boolean ytsearch)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ else if(event.getArgs().equalsIgnoreCase("false") || event.getArgs().equalsIgnor
}

@Override
public void doCommand(CommandEvent event) {}
public void doCommand(CommandEvent event) { /* Intentionally Empty */ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public void doCommand(CommandEvent event)

private class ResultHandler implements AudioLoadResultHandler
{
final Message m;
final CommandEvent event;
final boolean ytsearch;
private final Message m;
private final CommandEvent event;
private final boolean ytsearch;

private ResultHandler(Message m, CommandEvent event, boolean ytsearch)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public void doCommand(CommandEvent event)

private class ResultHandler implements AudioLoadResultHandler
{
final Message m;
final CommandEvent event;
private final Message m;
private final CommandEvent event;

private ResultHandler(Message m, CommandEvent event)
{
this.m = m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
*/
public class EvalCmd extends OwnerCommand
{
private final Bot bot;

public EvalCmd(Bot bot)
{
this.bot = bot;
this.name = "eval";
this.help = "evaluates nashorn code";
this.guildOnly = false;
Expand All @@ -38,6 +41,7 @@ public EvalCmd(Bot bot)
protected void execute(CommandEvent event)
{
ScriptEngine se = new ScriptEngineManager().getEngineByName("Nashorn");
se.put("bot", bot);
se.put("event", event);
se.put("jda", event.getJDA());
se.put("guild", event.getGuild());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class SetnameCmd extends OwnerCommand
{
public SetnameCmd(Bot bot)
public SetnameCmd()
{
this.name = "setname";
this.help = "sets the name of the bot";
Expand All @@ -37,13 +37,18 @@ public SetnameCmd(Bot bot)
@Override
protected void execute(CommandEvent event)
{
try {
try
{
String oldname = event.getSelfUser().getName();
event.getSelfUser().getManager().setName(event.getArgs()).complete(false);
event.reply(event.getClient().getSuccess()+" Name changed from `"+oldname+"` to `"+event.getArgs()+"`");
} catch(RateLimitedException e) {
}
catch(RateLimitedException e)
{
event.reply(event.getClient().getError()+" Name can only be changed twice per hour!");
} catch(Exception e) {
}
catch(Exception e)
{
event.reply(event.getClient().getError()+" That name is not valid!");
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jagrosh/jmusicbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void init()
setVisible(true);
addWindowListener(new WindowListener()
{
@Override public void windowOpened(WindowEvent e) {}
@Override public void windowOpened(WindowEvent e) { /* unused */ }
@Override public void windowClosing(WindowEvent e)
{
try
Expand All @@ -63,11 +63,11 @@ public void init()
System.exit(0);
}
}
@Override public void windowClosed(WindowEvent e) {}
@Override public void windowIconified(WindowEvent e) {}
@Override public void windowDeiconified(WindowEvent e) {}
@Override public void windowActivated(WindowEvent e) {}
@Override public void windowDeactivated(WindowEvent e) {}
@Override public void windowClosed(WindowEvent e) { /* unused */ }
@Override public void windowIconified(WindowEvent e) { /* unused */ }
@Override public void windowDeiconified(WindowEvent e) { /* unused */ }
@Override public void windowActivated(WindowEvent e) { /* unused */ }
@Override public void windowDeactivated(WindowEvent e) { /* unused */ }
});
}
}
Loading

0 comments on commit c0f0d45

Please sign in to comment.