Search in sources :

Example 1 with Settings

use of com.jagrosh.jmusicbot.settings.Settings in project MusicBot by jagrosh.

the class AutoplaylistCmd method execute.

@Override
public void execute(CommandEvent event) {
    if (event.getArgs().isEmpty()) {
        event.reply(event.getClient().getError() + " Please include a playlist name or NONE");
        return;
    }
    if (event.getArgs().equalsIgnoreCase("none")) {
        Settings settings = event.getClient().getSettingsFor(event.getGuild());
        settings.setDefaultPlaylist(null);
        event.reply(event.getClient().getSuccess() + " Cleared the default playlist for **" + event.getGuild().getName() + "**");
        return;
    }
    String pname = event.getArgs().replaceAll("\\s+", "_");
    if (bot.getPlaylistLoader().getPlaylist(pname) == null) {
        event.reply(event.getClient().getError() + " Could not find `" + pname + ".txt`!");
    } else {
        Settings settings = event.getClient().getSettingsFor(event.getGuild());
        settings.setDefaultPlaylist(pname);
        event.reply(event.getClient().getSuccess() + " The default playlist for **" + event.getGuild().getName() + "** is now `" + pname + "`");
    }
}
Also used : Settings(com.jagrosh.jmusicbot.settings.Settings)

Example 2 with Settings

use of com.jagrosh.jmusicbot.settings.Settings in project MusicBot by jagrosh.

the class VolumeCmd method doCommand.

@Override
public void doCommand(CommandEvent event) {
    AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
    Settings settings = event.getClient().getSettingsFor(event.getGuild());
    int volume = handler.getPlayer().getVolume();
    if (event.getArgs().isEmpty()) {
        event.reply(FormatUtil.volumeIcon(volume) + " Current volume is `" + volume + "`");
    } else {
        int nvolume;
        try {
            nvolume = Integer.parseInt(event.getArgs());
        } catch (NumberFormatException e) {
            nvolume = -1;
        }
        if (nvolume < 0 || nvolume > 150)
            event.reply(event.getClient().getError() + " Volume must be a valid integer between 0 and 150!");
        else {
            handler.getPlayer().setVolume(nvolume);
            settings.setVolume(nvolume);
            event.reply(FormatUtil.volumeIcon(nvolume) + " Volume changed from `" + volume + "` to `" + nvolume + "`");
        }
    }
}
Also used : AudioHandler(com.jagrosh.jmusicbot.audio.AudioHandler) Settings(com.jagrosh.jmusicbot.settings.Settings)

Example 3 with Settings

use of com.jagrosh.jmusicbot.settings.Settings in project MusicBot by jagrosh.

the class SettingsCmd method execute.

@Override
protected void execute(CommandEvent event) {
    Settings s = event.getClient().getSettingsFor(event.getGuild());
    MessageBuilder builder = new MessageBuilder().append(EMOJI + " **").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.getAsMention()) + "\nDJ Role: " + (role == null ? "None" : "**" + role.getName() + "**") + "\nCustom Prefix: " + (s.getPrefix() == null ? "None" : "`" + s.getPrefix() + "`") + "\nRepeat Mode: " + (s.getRepeatMode() == RepeatMode.OFF ? s.getRepeatMode().getUserFriendlyName() : "**" + s.getRepeatMode().getUserFriendlyName() + "**") + "\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);
    event.getChannel().sendMessage(builder.setEmbeds(ebuilder.build()).build()).queue();
}
Also used : Role(net.dv8tion.jda.api.entities.Role) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Settings(com.jagrosh.jmusicbot.settings.Settings)

Example 4 with Settings

use of com.jagrosh.jmusicbot.settings.Settings in project MusicBot by jagrosh.

the class NowplayingHandler method updateTopic.

public void updateTopic(long guildId, AudioHandler handler, boolean wait) {
    Guild guild = bot.getJDA().getGuildById(guildId);
    if (guild == null)
        return;
    Settings settings = bot.getSettingsManager().getSettings(guildId);
    TextChannel tchan = settings.getTextChannel(guild);
    if (tchan != null && guild.getSelfMember().hasPermission(tchan, Permission.MANAGE_CHANNEL)) {
        String otherText;
        String topic = tchan.getTopic();
        if (topic == null || topic.isEmpty())
            otherText = "\u200B";
        else if (topic.contains("\u200B"))
            otherText = topic.substring(topic.lastIndexOf("\u200B"));
        else
            otherText = "\u200B\n " + topic;
        String text = handler.getTopicFormat(bot.getJDA()) + otherText;
        if (!text.equals(tchan.getTopic())) {
            try {
                // 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 | RateLimitedException ignore) {
            }
        }
    }
}
Also used : PermissionException(net.dv8tion.jda.api.exceptions.PermissionException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Guild(net.dv8tion.jda.api.entities.Guild) RateLimitedException(net.dv8tion.jda.api.exceptions.RateLimitedException) Settings(com.jagrosh.jmusicbot.settings.Settings)

Example 5 with Settings

use of com.jagrosh.jmusicbot.settings.Settings in project MusicBot by jagrosh.

the class DJCommand method checkDJPermission.

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());
}
Also used : Role(net.dv8tion.jda.api.entities.Role) Settings(com.jagrosh.jmusicbot.settings.Settings)

Aggregations

Settings (com.jagrosh.jmusicbot.settings.Settings)30 AudioHandler (com.jagrosh.jmusicbot.audio.AudioHandler)8 TextChannel (net.dv8tion.jda.api.entities.TextChannel)8 Role (net.dv8tion.jda.api.entities.Role)6 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)6 PermissionException (net.dv8tion.jda.api.exceptions.PermissionException)6 QueuedTrack (com.jagrosh.jmusicbot.audio.QueuedTrack)4 RepeatMode (com.jagrosh.jmusicbot.settings.RepeatMode)4 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)4 CommandEvent (com.jagrosh.jdautilities.command.CommandEvent)2 Paginator (com.jagrosh.jdautilities.menu.Paginator)2 Bot (com.jagrosh.jmusicbot.Bot)2 JMusicBot (com.jagrosh.jmusicbot.JMusicBot)2 MusicCommand (com.jagrosh.jmusicbot.commands.MusicCommand)2 Playlist (com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist)2 FormatUtil (com.jagrosh.jmusicbot.utils.FormatUtil)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 Permission (net.dv8tion.jda.api.Permission)2