Search in sources :

Example 66 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class SongCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PlayerManager manager = FlareBot.instance().getMusicManager();
    if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
        Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
        EmbedBuilder eb = MessageUtils.getEmbed(sender).addField("Current Song", getLink(track), false).setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg");
        if (track.getTrack().getInfo().isStream)
            eb.addField("Amount Played", "Issa livestream ;)", false);
        else
            eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true).addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false);
        ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);
        buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId())) {
                if (manager.getPlayer(guild.getGuild().getId()).getPaused()) {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).play();
                    }
                } else {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).setPaused(true);
                    }
                }
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId()) && getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) {
                manager.getPlayer(guild.getGuildId()).stop();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
            if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) {
                Command cmd = FlareBot.getCommandManager().getCommand("skip", user);
                if (cmd != null)
                    cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user));
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> {
            updateSongMessage(user, message1, message1.getTextChannel());
        }));
        ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup);
    } else {
        channel.sendMessage(MessageUtils.getEmbed(sender).addField("Current song", "**No song playing right now!**", false).build()).queue();
    }
}
Also used : YouTubeExtractor(stream.flarebot.flarebot.music.extractors.YouTubeExtractor) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Track(com.arsenarsen.lavaplayerbridge.player.Track) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) ButtonUtil(stream.flarebot.flarebot.util.buttons.ButtonUtil) FlareBot(stream.flarebot.flarebot.FlareBot) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) FormatUtils(stream.flarebot.flarebot.util.general.FormatUtils) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) Command(stream.flarebot.flarebot.commands.Command) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) CommandType(stream.flarebot.flarebot.commands.CommandType) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Command(stream.flarebot.flarebot.commands.Command) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 67 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class EvalCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        channel.sendMessage("Eval something at least smh!").queue();
        return;
    }
    String imports = IMPORTS.stream().map(s -> "import " + s + ".*;").collect(Collectors.joining("\n"));
    ScriptEngine engine = manager.getEngineByName("groovy");
    engine.put("channel", channel);
    engine.put("guild", guild);
    engine.put("message", message);
    engine.put("jda", sender.getJDA());
    engine.put("sender", sender);
    String msg = MessageUtils.getMessage(args);
    final String[] code = { getCode(args) };
    boolean silent = hasOption(Options.SILENT, msg);
    if (hasOption(Options.SNIPPET, msg)) {
        String snippetName = MessageUtils.getNextArgument(msg, Options.SNIPPET.getAsArgument());
        if (snippetName == null) {
            MessageUtils.sendErrorMessage("Please specify the snippet you wish to run! Do `-snippet (name)`", channel);
            return;
        }
        CassandraController.runTask(session -> {
            ResultSet set = session.execute("SELECT encoded_code FROM flarebot.eval_snippets WHERE snippet_name = '" + snippetName + "'");
            Row row = set.one();
            if (row != null) {
                code[0] = StringUtils.newStringUtf8(Base64.getDecoder().decode(row.getString("encoded_code").getBytes()));
            } else {
                MessageUtils.sendErrorMessage("That eval snippet does not exist!", channel);
                code[0] = null;
            }
        });
    }
    if (hasOption(Options.SAVE, msg)) {
        String base64 = Base64.getEncoder().encodeToString(code[0].getBytes());
        CassandraController.runTask(session -> {
            String snippetName = MessageUtils.getNextArgument(msg, Options.SAVE.getAsArgument());
            if (snippetName == null) {
                MessageUtils.sendErrorMessage("Please specify the name of the snippet to save! Do `-save (name)`", channel);
                return;
            }
            if (insertSnippet == null)
                insertSnippet = session.prepare("UPDATE flarebot.eval_snippets SET encoded_code = ? WHERE snippet_name = ?");
            session.execute(insertSnippet.bind().setString(0, base64).setString(1, snippetName));
            MessageUtils.sendSuccessMessage("Saved the snippet `" + snippetName + "`!", channel);
        });
        return;
    }
    if (hasOption(Options.LIST, msg)) {
        ResultSet set = CassandraController.execute("SELECT snippet_name FROM flarebot.eval_snippets");
        if (set == null)
            return;
        MessageUtils.sendInfoMessage("**Available eval snippets**\n" + set.all().stream().map(row -> "`" + row.getString("snippet_name") + "`").collect(Collectors.joining(", ")), channel);
        return;
    }
    if (code[0] == null)
        return;
    final String finalCode = code[0];
    POOL.submit(() -> {
        try {
            String eResult = String.valueOf(engine.eval(imports + '\n' + finalCode));
            if (eResult.length() > 2000) {
                eResult = String.format("Eval too large, result pasted: %s", MessageUtils.paste(eResult));
            }
            if (!silent)
                channel.sendMessage(eResult).queue();
        } catch (Exception e) {
            // FlareBot.LOGGER.error("Error occurred in the evaluator thread pool! " + e.getMessage(), e, Markers.NO_ANNOUNCE);
            channel.sendMessage(MessageUtils.getEmbed(sender).addField("Result: ", "```bf\n" + e.getMessage() + "```", false).build()).queue();
        }
    });
}
Also used : Arrays(java.util.Arrays) Member(net.dv8tion.jda.core.entities.Member) Row(com.datastax.driver.core.Row) TextChannel(net.dv8tion.jda.core.entities.TextChannel) ScriptEngineManager(javax.script.ScriptEngineManager) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) InternalCommand(stream.flarebot.flarebot.commands.InternalCommand) Executors(java.util.concurrent.Executors) PreparedStatement(com.datastax.driver.core.PreparedStatement) Base64(java.util.Base64) List(java.util.List) ResultSet(com.datastax.driver.core.ResultSet) CassandraController(stream.flarebot.flarebot.database.CassandraController) Matcher(java.util.regex.Matcher) User(net.dv8tion.jda.core.entities.User) ScriptEngine(javax.script.ScriptEngine) StringUtils(org.apache.commons.codec.binary.StringUtils) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) Pattern(java.util.regex.Pattern) CommandType(stream.flarebot.flarebot.commands.CommandType) ExecutorService(java.util.concurrent.ExecutorService) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) ScriptEngine(javax.script.ScriptEngine)

Example 68 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class SkipCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    boolean songMessage = message.getAuthor().getIdLong() == Getters.getSelfUser().getIdLong();
    PlayerManager musicManager = FlareBot.instance().getMusicManager();
    if (!channel.getGuild().getAudioManager().isConnected() || musicManager.getPlayer(channel.getGuild().getId()).getPlayingTrack() == null) {
        MessageUtils.sendAutoDeletedMessage(new MessageBuilder().append("I am not playing anything!").build(), TimeUnit.SECONDS.toMillis(5), channel);
        channel.sendMessage("I am not playing anything!").queue();
        return;
    }
    if (member.getVoiceState().inVoiceChannel() && !channel.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(member.getVoiceState().getChannel().getId()) && !getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
        MessageUtils.sendAutoDeletedMessage(new MessageBuilder().append("You must be in the channel in order to skip songs!").build(), TimeUnit.SECONDS.toMillis(5), channel);
        return;
    }
    Track currentTrack = musicManager.getPlayer(guild.getGuildId()).getPlayingTrack();
    if (args.length == 0 && currentTrack.getMeta().get("requester").equals(sender.getId())) {
        MessageUtils.sendAutoDeletedMessage(new MessageBuilder().append("Skipped your own song!").build(), TimeUnit.SECONDS.toMillis(5), channel);
        musicManager.getPlayer(guild.getGuildId()).skip();
        if (songMessage)
            SongCommand.updateSongMessage(sender, message, channel);
        return;
    }
    if (args.length != 1) {
        if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
            MessageUtils.sendWarningMessage("You cannot skip if you aren't listening to it!", channel);
            return;
        }
        if (VoteUtil.contains(skipUUID, guild.getGuild()))
            MessageUtils.sendWarningMessage("There is already a vote to skip current song! Vote with `{%}skip yes | no`", channel, sender);
        else {
            VoteGroup group = new VoteGroup("Skip current song", skipUUID);
            List<User> users = new ArrayList<>();
            for (Member inChannelMember : channel.getGuild().getSelfMember().getVoiceState().getChannel().getMembers()) {
                if (channel.getGuild().getSelfMember().getUser().getIdLong() != inChannelMember.getUser().getIdLong()) {
                    users.add(inChannelMember.getUser());
                }
            }
            group.limitUsers(users);
            VoteUtil.sendVoteMessage(skipUUID, (vote) -> {
                if (vote.equals(VoteGroup.Vote.NONE) || vote.equals(VoteGroup.Vote.NO)) {
                    MessageUtils.sendAutoDeletedMessage(new MessageBuilder().append("Results are in: Keep!").build(), TimeUnit.SECONDS.toMillis(5), channel);
                } else {
                    MessageUtils.sendAutoDeletedMessage(new MessageBuilder().append("Skipping!").build(), TimeUnit.SECONDS.toMillis(5), channel);
                    if (songMessage)
                        SongCommand.updateSongMessage(sender, message, channel);
                    musicManager.getPlayer(guild.getGuildId()).skip();
                }
            }, group, TimeUnit.MINUTES.toMillis(1), channel, sender, ButtonGroupConstants.VOTE_SKIP, new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
                if (getPermissions(channel).hasPermission(channel.getGuild().getMember(user), Permission.SKIP_FORCE)) {
                    musicManager.getPlayer(channel.getGuild().getId()).skip();
                    if (songMessage) {
                        SongCommand.updateSongMessage(user, message1, channel);
                    }
                    musicManager.getPlayer(guild.getGuildId()).skip();
                    VoteUtil.remove(skipUUID, guild.getGuild());
                } else {
                    channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this button!").queue();
                }
            }));
        }
    } else {
        if (args[0].equalsIgnoreCase("force")) {
            if (getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
                if (songMessage)
                    SongCommand.updateSongMessage(sender, message, channel);
                VoteUtil.remove(skipUUID, guild.getGuild());
                musicManager.getPlayer(guild.getGuildId()).skip();
            } else {
                channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this command!").queue();
            }
            return;
        } else if (args[0].equalsIgnoreCase("cancel")) {
            if (getPermissions(channel).hasPermission(member, Permission.SKIP_CANCEL)) {
                VoteUtil.remove(skipUUID, channel.getGuild());
            } else
                channel.sendMessage("You are missing the permission `" + Permission.SKIP_CANCEL + "` which is required for use of this command!").queue();
            return;
        }
        if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
            MessageUtils.sendWarningMessage("You cannot vote to skip if you aren't listening to it!", channel);
            return;
        }
        VoteGroup.Vote vote = VoteGroup.Vote.parseVote(args[0]);
        if (vote != null) {
            if (!VoteUtil.contains(skipUUID, guild.getGuild()))
                MessageUtils.sendWarningMessage("Their is no vote currently running!", channel, sender);
            else
                VoteUtil.getVoteGroup(skipUUID, guild.getGuild()).addVote(vote, sender);
        } else
            MessageUtils.sendUsage(this, channel, sender, args);
    }
}
Also used : stream.flarebot.flarebot.commands(stream.flarebot.flarebot.commands) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Track(com.arsenarsen.lavaplayerbridge.player.Track) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) FlareBot(stream.flarebot.flarebot.FlareBot) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) UUID(java.util.UUID) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Message(net.dv8tion.jda.core.entities.Message) Getters(stream.flarebot.flarebot.Getters) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) VoteGroup(stream.flarebot.flarebot.util.votes.VoteGroup) VoteUtil(stream.flarebot.flarebot.util.votes.VoteUtil) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) User(net.dv8tion.jda.core.entities.User) PlayerManager(com.arsenarsen.lavaplayerbridge.PlayerManager) ArrayList(java.util.ArrayList) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) Member(net.dv8tion.jda.core.entities.Member) Track(com.arsenarsen.lavaplayerbridge.player.Track) VoteGroup(stream.flarebot.flarebot.util.votes.VoteGroup)

Example 69 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class PlayerListener method onTrackStart.

@Override
public void onTrackStart(AudioPlayer aplayer, AudioTrack atrack) {
    FlareBotManager.instance().getLastActive().remove(Long.parseLong(player.getGuildId()));
    GuildWrapper wrapper = FlareBotManager.instance().getGuild(player.getGuildId());
    if (wrapper.getMusicAnnounceChannelId() != null) {
        TextChannel c = Getters.getChannelById(wrapper.getMusicAnnounceChannelId());
        if (c != null) {
            if (c.getGuild().getSelfMember().hasPermission(c, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE)) {
                Track track = player.getPlayingTrack();
                Queue<Track> playlist = player.getPlaylist();
                c.sendMessage(MessageUtils.getEmbed().addField("Now Playing", SongCommand.getLink(track), false).addField("Duration", FormatUtils.formatDuration(track.getTrack().getDuration()), false).addField("Requested by", String.format("<@!%s>", track.getMeta().get("requester")), false).addField("Next up", playlist.isEmpty() ? "Nothing" : SongCommand.getLink(playlist.peek()), false).setImage("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg").build()).queue();
            } else {
                wrapper.setMusicAnnounceChannelId(null);
            }
        } else {
            wrapper.setMusicAnnounceChannelId(null);
        }
    }
    if (wrapper.isSongnickEnabled()) {
        Guild c = wrapper.getGuild();
        if (c == null || !GuildUtils.canChangeNick(player.getGuildId())) {
            if (!GuildUtils.canChangeNick(player.getGuildId())) {
                wrapper.setSongnick(false);
                MessageUtils.sendPM(wrapper.getGuild().getOwner().getUser(), "FlareBot can't change it's nickname so SongNick has been disabled!");
            }
        } else {
            Track track = player.getPlayingTrack();
            String str = null;
            if (track != null) {
                str = track.getTrack().getInfo().title;
                if (str.length() > 32)
                    str = str.substring(0, 32);
                str = str.substring(0, str.lastIndexOf(' ') + 1);
            }
            // Even I couldn't make this a one-liner
            c.getController().setNickname(c.getSelfMember(), str).queue();
        }
    }
}
Also used : GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild) Track(com.arsenarsen.lavaplayerbridge.player.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 70 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class NINOCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable")) {
            boolean enabled = args[0].equalsIgnoreCase("enable");
            ArrayList<URLCheckFlag> flags = new ArrayList<>();
            if (args.length >= 2) {
                if (args[1].equalsIgnoreCase("all"))
                    flags.addAll(Arrays.asList(URLCheckFlag.values));
                else if (args[1].equalsIgnoreCase("default"))
                    flags.addAll(URLCheckFlag.getDefaults());
                else {
                    String[] strFlags = seperator.split(MessageUtils.getMessage(args, 1));
                    URLCheckFlag checkFlag;
                    for (String flag : strFlags) {
                        if ((checkFlag = URLCheckFlag.getFlag(flag)) != null)
                            flags.add(checkFlag);
                        else {
                            MessageUtils.sendWarningMessage("'" + flag + "' is not a valid flag!", channel);
                            return;
                        }
                    }
                }
            }
            if (enabled) {
                if (flags.isEmpty())
                    flags.addAll(URLCheckFlag.getDefaults());
                guild.getNINO().getURLFlags().addAll(flags);
            } else {
                if (flags.isEmpty())
                    guild.getNINO().getURLFlags().clear();
                else
                    guild.getNINO().getURLFlags().removeAll(flags);
            }
            boolean all = (enabled ? guild.getNINO().getURLFlags().size() == URLCheckFlag.getAllFlags().size() : guild.getNINO().getURLFlags().isEmpty());
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription(FormatUtils.formatCommandPrefix(guild, "I have " + (enabled ? "enabled " : "disabled ") + (all ? "all the flags." : "the " + listToString(flags) + " flag(s)!") + "\n\nTo see the whitelist do `{%}nino whitelist list` and to post the" + " attempts to the modlog enable it with `{%}modlog enable NINO <#channel>`")).setColor(enabled ? ColorUtils.GREEN : ColorUtils.RED).build()).queue();
        } else if (args[0].equalsIgnoreCase("whitelist")) {
            if (args.length == 2) {
                if (args[1].equalsIgnoreCase("list")) {
                    StringBuilder sb = new StringBuilder();
                    StringBuilder channels = new StringBuilder();
                    for (String invite : guild.getNINO().getWhitelist()) sb.append("`").append(invite).append("`").append("\n");
                    for (long channelId : guild.getNINO().getChannels()) {
                        if (guild.getGuild().getTextChannelById(channelId) != null)
                            channels.append(guild.getGuild().getTextChannelById(channelId).getAsMention()).append("\n");
                        else
                            guild.getNINO().getChannels().remove(channelId);
                    }
                    channel.sendMessage(MessageUtils.getEmbed(sender).setColor(ColorUtils.FLAREBOT_BLUE).addField("Whitelisted Invites", sb.toString(), false).addField("Whitelisted Channels", channels.toString(), false).build()).queue();
                } else
                    MessageUtils.sendUsage(this, channel, sender, args);
            } else if (args.length == 3) {
                if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
                    String whitelist = args[2];
                    boolean added = args[1].equalsIgnoreCase("add");
                    TextChannel tc = GuildUtils.getChannel(whitelist, guild);
                    if (tc != null) {
                        if (added)
                            guild.getNINO().addChannel(tc.getIdLong());
                        else
                            guild.getNINO().removeChannel(tc.getIdLong());
                        MessageUtils.sendSuccessMessage((added ? "Added " : "Removed ") + tc.getAsMention() + (added ? " to" : " from") + " the whitelist!", channel, sender);
                    } else if (URLConstants.URL_PATTERN_NO_PROTOCOL.matcher(whitelist).matches()) {
                        if (added)
                            guild.getNINO().addUrl(whitelist);
                        else
                            guild.getNINO().removeUrl(whitelist);
                        MessageUtils.sendSuccessMessage((added ? "Added " : "Removed ") + "`" + whitelist + "` " + (added ? "to" : "from") + " the whitelist!", channel, sender);
                    } else {
                        MessageUtils.sendWarningMessage("That is an invalid input! " + "Please try and whitelist a Discord invite or ", channel);
                    }
                } else
                    MessageUtils.sendUsage(this, channel, sender, args);
            } else
                MessageUtils.sendUsage(this, channel, sender, args);
        } else if (args[0].equalsIgnoreCase("message")) {
            if (args.length == 1) {
                MessageUtils.sendUsage(this, channel, sender, args);
                return;
            }
            String msg = null;
            if (args.length >= 3) {
                msg = MessageUtils.getMessage(args, 2);
                if (msg.length() > 250) {
                    MessageUtils.sendWarningMessage("That message is a tad too long, please make it 250 characters max!" + "\n```\n" + msg + "\n```", channel, sender);
                    return;
                }
            }
            if (args[1].equalsIgnoreCase("set")) {
                if (msg != null) {
                    guild.getNINO().setRemoveMessage(msg);
                    MessageUtils.sendSuccessMessage("Message has been set!\n```" + msg + "\n```", channel, sender);
                } else
                    MessageUtils.sendWarningMessage("Please specify a message!", channel);
            } else if (args[1].equalsIgnoreCase("add")) {
                if (msg != null) {
                    guild.getNINO().addRemoveMessage(msg);
                    MessageUtils.sendSuccessMessage("Message has been added!\n```" + msg + "\n```", channel, sender);
                } else
                    MessageUtils.sendWarningMessage("Please specify a message!", channel);
            } else if (args[1].equalsIgnoreCase("remove")) {
                int messageId = 1;
                if (args.length > 2)
                    messageId = GeneralUtils.getInt(args[2], 1);
                int size = guild.getNINO().getRemoveMessages().size();
                if (size == 0) {
                    MessageUtils.sendInfoMessage("This guild has no remove messages!", channel);
                    return;
                }
                if (messageId <= 0 || messageId >= size) {
                    MessageUtils.sendWarningMessage("Invalid message ID!", channel);
                    return;
                }
                String tmp = guild.getNINO().getRemoveMessages().get(messageId);
                guild.getNINO().getRemoveMessages().remove(tmp);
                MessageUtils.sendSuccessMessage("Successfully removed message with ID " + messageId + "!\n```\n" + tmp + "\n```", channel);
            } else if (args[1].equalsIgnoreCase("clear")) {
                guild.getNINO().clearRemoveMessages();
                MessageUtils.sendSuccessMessage("Successfully removed **all** messages from this guild!", channel);
            } else if (args[1].equalsIgnoreCase("list")) {
                int page = 1;
                if (args.length > 2)
                    page = GeneralUtils.getInt(args[2], 1);
                listMessages(guild, page, channel, sender);
            } else
                MessageUtils.sendUsage(this, channel, sender, args);
        } else if (args[0].equalsIgnoreCase("flags")) {
            Set<URLCheckFlag> flags = guild.getNINO().getURLFlags();
            boolean all = flags.size() == URLCheckFlag.getAllFlags().size();
            EmbedBuilder eb = MessageUtils.getEmbed(sender);
            if (!flags.isEmpty())
                eb.addField("Enabled", flags.stream().map(URLCheckFlag::toString).collect(Collectors.joining("\n")), false);
            if (!all)
                eb.addField("Disabled", URLCheckFlag.getAllFlags().stream().filter(f -> !flags.contains(f)).map(URLCheckFlag::toString).collect(Collectors.joining("\n")), false);
            channel.sendMessage(eb.build()).queue();
        } else if (args[0].equalsIgnoreCase("mode")) {
            if (args.length == 2) {
                NINOMode mode = NINOMode.getMode(args[1]);
                if (mode == null)
                    MessageUtils.sendWarningMessage("That is an invalid mode!", channel);
                else {
                    guild.getNINO().setMode(mode.getMode());
                    MessageUtils.sendSuccessMessage("Changed NINO's mode to " + mode.toString(), channel, sender);
                }
            } else {
                StringBuilder sb = new StringBuilder();
                for (NINOMode mode : NINOMode.values()) sb.append(mode.toString()).append(" (").append(mode.getMode()).append(") - ").append(mode.getExplanation()).append("\n");
                MessageUtils.sendMessage("Current Mode: " + guild.getNINO().getNINOMode().toString() + "\nNINO will " + WordUtils.uncapitalize(guild.getNINO().getNINOMode().getExplanation(), '~') + "\n\n**Available Modes**\n" + sb.toString().trim() + "\n\n\n" + "Protocol is the `http://` or `https://` at the start of a URL. Example: `https://google.com`\n" + "Following a URL is when we will check to see if it is a masked link " + "(something like goo.gl, bit.ly etc) and if so follow the redirects and if we see a bad " + "link then it will be caught. This means people can't hide bad links. " + "It does have the disadvantage of being a bit slower though (it will still catch before " + "any human can click it). Example: `https://goo.gl/NfYi94`", channel, sender);
            }
        } else if (args[0].equalsIgnoreCase("test")) {
            if (!PerGuildPermissions.isCreator(sender))
                return;
            String links = MessageUtils.getMessage(args, 1);
            URLChecker.instance().runTests(links.split("\n"), channel);
        } else
            MessageUtils.sendUsage(this, channel, sender, args);
    } else
        MessageUtils.sendUsage(this, channel, sender, args);
}
Also used : Arrays(java.util.Arrays) WordUtils(org.apache.commons.lang3.text.WordUtils) URLChecker(stream.flarebot.flarebot.mod.nino.URLChecker) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Message(net.dv8tion.jda.core.entities.Message) ArrayList(java.util.ArrayList) FormatUtils(stream.flarebot.flarebot.util.general.FormatUtils) Permission(stream.flarebot.flarebot.permissions.Permission) PerGuildPermissions(stream.flarebot.flarebot.permissions.PerGuildPermissions) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) CommandType(stream.flarebot.flarebot.commands.CommandType) GuildUtils(stream.flarebot.flarebot.util.general.GuildUtils) NINOMode(stream.flarebot.flarebot.mod.nino.NINOMode) URLConstants(stream.flarebot.flarebot.mod.nino.URLConstants) Collection(java.util.Collection) Set(java.util.Set) ColorUtils(stream.flarebot.flarebot.util.ColorUtils) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) List(java.util.List) User(net.dv8tion.jda.core.entities.User) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Command(stream.flarebot.flarebot.commands.Command) Pattern(java.util.regex.Pattern) PaginationList(stream.flarebot.flarebot.util.pagination.PaginationList) URLCheckFlag(stream.flarebot.flarebot.mod.nino.URLCheckFlag) TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Set(java.util.Set) NINOMode(stream.flarebot.flarebot.mod.nino.NINOMode) ArrayList(java.util.ArrayList) URLCheckFlag(stream.flarebot.flarebot.mod.nino.URLCheckFlag)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)90 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)21 User (net.dv8tion.jda.core.entities.User)19 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)10 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6