Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #442 from Frederikam/dev
Browse files Browse the repository at this point in the history
v2.1 - Command modules
  • Loading branch information
freyacodes committed Jan 27, 2018
2 parents 0b3c9bc + 9cfd297 commit aa798bf
Show file tree
Hide file tree
Showing 160 changed files with 4,541 additions and 2,369 deletions.
6 changes: 4 additions & 2 deletions FredBoat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'org.junit.platform.gradle.plugin'

description = 'FredBoat Discord Music Bot'
mainClassName = "fredboat.FredBoat"
version '2.0'
version '2.1'
ext {
moduleName = 'FredBoat'
}
Expand Down Expand Up @@ -53,14 +53,16 @@ dependencies {
compile group: 'org.yaml', name: 'snakeyaml', version: '1.19'
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.1.1'
compile group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: '3.1.1'

compile group: 'io.prometheus', name: 'simpleclient', version: '0.1.0'
compile group: 'io.prometheus', name: 'simpleclient_hotspot', version: '0.1.0'
compile group: 'io.prometheus', name: 'simpleclient_logback', version: '0.1.0'
compile group: 'io.prometheus', name: 'simpleclient_hibernate', version: '0.1.0'
compile group: 'io.prometheus', name: 'simpleclient_guava', version: '0.1.0'
compile group: 'io.prometheus', name: 'simpleclient_servlet', version: '0.1.0'

compile group: 'space.npstr.SqlSauce', name: 'sqlsauce-core', version: 'a5c9afd96d1928d9a51e799249a6eb5b08b4f473'
compile group: 'space.npstr.SqlSauce', name: 'sqlsauce-core', version: '8a939c06651fd06877d705874834463373cfb596'
compile group: 'space.npstr.SqlSauce', name: 'discord-entities', version: '8a939c06651fd06877d705874834463373cfb596'
compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.12.Final'
compile group: 'org.flywaydb', name: 'flyway-core', version: '5.0.3'

Expand Down
5 changes: 3 additions & 2 deletions FredBoat/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ patron: false # Set this to true for self hosting the music bot
development: true # Set this to true for self hosting the full bot (including non music commands)
prefix: '<<' # Default prefix used by the bot
restServerEnabled: true # Set this to false if you are running multiple FredBoat bots on the same machine
admins: [] # Add comma separated userIds and roleIds that should have access to bot admin commands
admins: [] # Add comma separated userIds and roleIds that should have access to bot admin commands. Find role ids with the ;;roleinfo command
useAutoBlacklist: true # Set to true to automatically blacklist users who frequently hit the rate limits
game: "" # Set the displayed game/status. Leave empty quote marks for the default status
continuePlayback: false # Set to true to force the player to continue playback even if left alone
Expand All @@ -15,7 +15,8 @@ enableTwitch: true # Set to true to enable playing Twitch links
enableVimeo: true # Set to true to enable playing Vimeo links
enableMixer: true # Set to true to enable playing Mixer links
enableSpotify: true # Set to true to enable playing Spotify links
enableHttp: true # Set to true to enable playing direct links
enableLocal: false # Set to true to enable playing local files
enableHttp: false # Set to true to enable playing direct links

# THIS IS TEMPORARY UNTIL COMMANDS ARE MODULARIZED
tempUseVoiceChannelCleanup: true # This acts as an override if set to false no vcCleanupAgent will be run
9 changes: 8 additions & 1 deletion FredBoat/src/main/java/fredboat/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.base.CharMatcher;
import fredboat.audio.player.PlayerLimitManager;
import fredboat.command.admin.SentryDsnCommand;
import fredboat.commandmeta.CommandInitializer;
import fredboat.commandmeta.MessagingException;
import fredboat.shared.constant.DistributionEnum;
import fredboat.util.DiscordUtil;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class Config {
private boolean vimeoAudio;
private boolean mixerAudio;
private boolean spotifyAudio;
private boolean localAudio;
private boolean httpAudio;

// temporary config values todo remove after merging main + music
Expand Down Expand Up @@ -200,6 +202,7 @@ public Config(File credentialsFile, File configFile) {
vimeoAudio = (Boolean) config.getOrDefault("enableVimeo", true);
mixerAudio = (Boolean) config.getOrDefault("enableMixer", true);
spotifyAudio = (Boolean) config.getOrDefault("enableSpotify", true);
localAudio = (Boolean) config.getOrDefault("enableLocal", false);
httpAudio = (Boolean) config.getOrDefault("enableHttp", false);

//temp configs
Expand Down Expand Up @@ -462,7 +465,7 @@ public boolean useAutoBlacklist() {

public String getGame() {
if (game == null || game.isEmpty()) {
return "Say " + getPrefix() + "help";
return "Say " + getPrefix() + CommandInitializer.HELP_COMM_NAME;
} else {
return game;
}
Expand Down Expand Up @@ -500,6 +503,10 @@ public boolean isSpotifyEnabled() {
return spotifyAudio;
}

public boolean isLocalEnabled() {
return localAudio;
}

public boolean isHttpEnabled() {
return httpAudio;
}
Expand Down
11 changes: 3 additions & 8 deletions FredBoat/src/main/java/fredboat/FredBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
import fredboat.api.API;
import fredboat.audio.player.LavalinkManager;
import fredboat.audio.queue.MusicPersistenceHandler;
import fredboat.commandmeta.CommandInitializer;
import fredboat.commandmeta.CommandRegistry;
import fredboat.commandmeta.init.MainCommandInitializer;
import fredboat.commandmeta.init.MusicCommandInitializer;
import fredboat.db.DatabaseManager;
import fredboat.event.EventListenerBoat;
import fredboat.feature.I18n;
Expand Down Expand Up @@ -173,10 +172,8 @@ public static void main(String[] args) throws LoginException, IllegalArgumentExc
LavalinkManager.ins.start();

//Commands
if (Config.CONFIG.getDistribution() == DistributionEnum.DEVELOPMENT)
MainCommandInitializer.initCommands();

MusicCommandInitializer.initCommands();
CommandInitializer.initCommands();
log.info("Loaded commands, registry size is " + CommandRegistry.getTotalSize());

if (!Config.CONFIG.isPatronDistribution() && Config.CONFIG.useVoiceChannelCleanup()) {
log.info("Starting VoiceChannelCleanupAgent.");
Expand All @@ -186,8 +183,6 @@ public static void main(String[] args) throws LoginException, IllegalArgumentExc
"either running Patron distro or overridden by temp config");
}

log.info("Loaded commands, registry size is " + CommandRegistry.getSize());

//Check MAL creds
executor.submit(FredBoat::hasValidMALLogin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.local.LocalAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager;
Expand All @@ -51,6 +52,7 @@
import fredboat.audio.source.SpotifyPlaylistSourceManager;
import fredboat.commandmeta.MessagingException;
import fredboat.shared.constant.DistributionEnum;
import fredboat.util.TextUtils;
import lavalink.client.player.IPlayer;
import lavalink.client.player.LavalinkPlayer;
import lavalink.client.player.LavaplayerPlayerWrapper;
Expand Down Expand Up @@ -113,7 +115,7 @@ private static void initAudioPlayerManager() {
public static AudioPlayerManager registerSourceManagers(AudioPlayerManager mng) {
mng.registerSourceManager(new PlaylistImportSourceManager());
//Determine which Source managers are enabled
//By default, all are enabled except HttpAudioSources
//By default, all are enabled except LocalAudioSources and HttpAudioSources, see config.yaml and Config class
if (Config.CONFIG.isYouTubeEnabled()) {
YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager();
youtubeAudioSourceManager.configureRequests(config -> RequestConfig.copy(config)
Expand All @@ -139,6 +141,9 @@ public static AudioPlayerManager registerSourceManagers(AudioPlayerManager mng)
if (Config.CONFIG.isSpotifyEnabled()) {
mng.registerSourceManager(new SpotifyPlaylistSourceManager());
}
if (Config.CONFIG.isLocalEnabled()) {
mng.registerSourceManager(new LocalAudioSourceManager());
}
if (Config.CONFIG.isHttpEnabled()) {
//add new source managers above the HttpAudio one, because it will either eat your request or throw an exception
//so you will never reach a source manager below it
Expand Down Expand Up @@ -285,7 +290,7 @@ public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason
log.info("Track " + track.getIdentifier() + " was cleaned up");
} else if (endReason == AudioTrackEndReason.LOAD_FAILED) {
if (onErrorHook != null)
onErrorHook.accept(new MessagingException("Track `" + track.getInfo().title + "` failed to load. Skipping..."));
onErrorHook.accept(new MessagingException("Track `" + TextUtils.escapeAndDefuse(track.getInfo().title) + "` failed to load. Skipping..."));
audioTrackProvider.skipped();
loadAndPlay();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import fredboat.messaging.CentralMessaging;
import fredboat.perms.PermissionLevel;
import fredboat.perms.PermsUtil;
import fredboat.util.TextUtils;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
Expand Down Expand Up @@ -98,7 +99,7 @@ private void announceTrack(AudioTrackContext atc) {
TextChannel activeTextChannel = getActiveTextChannel();
if (activeTextChannel != null) {
CentralMessaging.sendMessage(activeTextChannel,
atc.i18nFormat("trackAnnounce", atc.getEffectiveTitle()));
atc.i18nFormat("trackAnnounce", TextUtils.escapeAndDefuse(atc.getEffectiveTitle())));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public void trackLoaded(AudioTrack at) {

if (!context.isQuiet()) {
context.reply(gplayer.isPlaying() ?
context.i18nFormat("loadSingleTrack", at.getInfo().title)
context.i18nFormat("loadSingleTrack", TextUtils.escapeAndDefuse(at.getInfo().title))
:
context.i18nFormat("loadSingleTrackAndPlay", at.getInfo().title)
context.i18nFormat("loadSingleTrackAndPlay", TextUtils.escapeAndDefuse(at.getInfo().title))
);
} else {
log.info("Quietly loaded " + at.getIdentifier());
Expand Down Expand Up @@ -311,7 +311,7 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){
mb.append("`[")
.append(TextUtils.formatTime(atc.getEffectiveDuration()))
.append("]` ")
.append(atc.getEffectiveTitle())
.append(TextUtils.escapeAndDefuse(atc.getEffectiveTitle()))
.append("\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import fredboat.audio.player.GuildPlayer;
import fredboat.audio.player.PlayerRegistry;
import fredboat.command.util.HelpCommand;
import fredboat.command.info.HelpCommand;
import fredboat.commandmeta.abs.Command;
import fredboat.commandmeta.abs.CommandContext;
import fredboat.commandmeta.abs.ICommandRestricted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,46 @@
import fredboat.messaging.internal.Context;
import fredboat.perms.PermissionLevel;
import fredboat.shared.constant.ExitCodes;
import org.slf4j.LoggerFactory;
import fredboat.util.TextUtils;

import javax.annotation.Nonnull;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

public class BotRestartCommand extends Command implements ICommandRestricted {

private static final org.slf4j.Logger log = LoggerFactory.getLogger(BotRestartCommand.class);

public BotRestartCommand(String name, String... aliases) {
super(name, aliases);
}

@Nonnull
private String code = TextUtils.randomAlphaNumericString(4);

@Override
public void onInvoke(@Nonnull CommandContext context) {
try {
context.replyWithName(" Restarting...").getWithDefaultTimeout();
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
if (context.hasArguments()) {
if (context.rawArgs.equals(code)) {
try {
context.replyWithName("Restarting...").getWithDefaultTimeout();
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
FredBoat.shutdown(ExitCodes.EXIT_CODE_RESTART);
return;
} else {
context.reply(String.format("Your input `%s` did not fit the required code `%s`. A new code will be issued.",
TextUtils.escapeMarkdown(context.rawArgs), code));
}
}

FredBoat.shutdown(ExitCodes.EXIT_CODE_RESTART);
code = TextUtils.randomAlphaNumericString(4);
context.reply(String.format("This will **restart the whole bot**. "
+ "Please confirm by issuing this command again, with the following confirmation code appended: `%s`", code));
}

@Nonnull
@Override
public String help(@Nonnull Context context) {
return "{0}{1}\n#Restarts the bot.";
return "{0}{1} [code]\n#Restart the bot.";
}

@Nonnull
Expand Down
Loading

0 comments on commit aa798bf

Please sign in to comment.