Search in sources :

Example 1 with GuildWrapper

use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.

the class DebugCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length < 1) {
        MessageUtils.sendUsage(this, channel, sender, args);
        return;
    }
    FlareBot fb = FlareBot.instance();
    EmbedBuilder eb = MessageUtils.getEmbed();
    if (args[0].equalsIgnoreCase("flarebot") || args[0].equalsIgnoreCase("bot")) {
        eb.setTitle("Bot Debug").setDescription(String.format("Debug for FlareBot v" + FlareBot.getVersion() + "\nUptime: %s" + "\nMemory Usage: %s" + "\nMemory Free: %s" + "\nVideo Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\n\nGuilds: %d" + "\nLoaded Guilds: %d" + "\nVoice Channels: %d" + "\nActive Voice Channels: %d" + "\nCommands Executed: %d" + "\nQueued RestActions: %s", fb.getUptime(), getMB(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()), getMB(Runtime.getRuntime().freeMemory()), VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), fb.getShardManager().getGuildCache().size(), FlareBotManager.instance().getGuilds().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels(), fb.getEvents().getCommandCount(), getQueuedRestActions()));
        StringBuilder sb = new StringBuilder();
        for (DataInterceptor interceptor : DataInterceptor.getInterceptors()) sb.append(WordUtils.capitalize(interceptor.getSender().getName())).append(" - ").append(interceptor.getRequests()).append(" requests").append("\n");
        eb.addField("HTTP Requests", sb.toString(), false);
    } else if (args[0].equalsIgnoreCase("threads")) {
        eb.setTitle("Thread Debug").setDescription(String.format("Video Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\nThread list: %s", VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), MessageUtils.paste(Thread.getAllStackTraces().keySet().stream().map(th -> th.getName() + " - " + th.getState() + " (" + th.getThreadGroup().getName() + ")").collect(Collectors.joining("\n")))));
    } else if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("guild")) {
    } else if (args[0].equalsIgnoreCase("player") || args[0].equalsIgnoreCase("music")) {
        GuildWrapper wrapper = guild;
        if (args.length == 2)
            wrapper = FlareBotManager.instance().getGuild(args[1]);
        if (wrapper == null) {
            channel.sendMessage("I can't find that guild!").queue();
            return;
        }
        Player player = FlareBot.instance().getMusicManager().getPlayer(wrapper.getGuildId());
        VoiceChannel vc = (wrapper.getGuild().getSelfMember().getVoiceState() != null && wrapper.getGuild().getSelfMember().getVoiceState().getChannel() != null ? wrapper.getGuild().getSelfMember().getVoiceState().getChannel() : null);
        String lastActive = "Not tracked.";
        if (VoiceChannelCleanup.VC_LAST_USED.containsKey(vc != null ? vc.getIdLong() : guild.getGuildIdLong())) {
            long ms = VoiceChannelCleanup.VC_LAST_USED.get(vc != null ? vc.getIdLong() : guild.getGuildIdLong());
            lastActive = String.valueOf(ms) + " (" + (System.currentTimeMillis() - ms) + "ms ago)";
        }
        boolean isPlaying = player.getPlayingTrack() != null;
        Track track = player.getPlayingTrack();
        eb.setTitle("Bot Debug").setDescription(String.format("Player Debug for `" + wrapper.getGuildId() + "`" + "\nCurrent Track: %s" + "\nCurrent Position: %s" + "\nIs Paused: %b" + "\nPlaylist Length: %s" + "\nIs Looping: %b" + "\nVoice Channel: %s" + "\nLast Active: %s", (isPlaying ? track.getTrack().getIdentifier() : "No current track"), (isPlaying ? track.getTrack().getPosition() + "/" + track.getTrack().getDuration() : "N/A"), player.getPaused(), player.getPlaylist().size(), player.getLooping(), (vc == null ? "null" : vc.toString()), lastActive));
    } else {
        channel.sendMessage("Invalid debug option").queue();
        return;
    }
    channel.sendMessage(eb.build()).queue();
}
Also used : Track(com.arsenarsen.lavaplayerbridge.player.Track) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) WordUtils(org.apache.commons.lang3.text.WordUtils) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannelCleanup(stream.flarebot.flarebot.tasks.VoiceChannelCleanup) Player(com.arsenarsen.lavaplayerbridge.player.Player) FlareBot(stream.flarebot.flarebot.FlareBot) VideoThread(stream.flarebot.flarebot.music.VideoThread) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) Getters(stream.flarebot.flarebot.Getters) InternalCommand(stream.flarebot.flarebot.commands.InternalCommand) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Events(stream.flarebot.flarebot.Events) JDAImpl(net.dv8tion.jda.core.entities.impl.JDAImpl) User(net.dv8tion.jda.core.entities.User) FlareBotManager(stream.flarebot.flarebot.FlareBotManager) DataInterceptor(stream.flarebot.flarebot.web.DataInterceptor) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) CommandType(stream.flarebot.flarebot.commands.CommandType) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Player(com.arsenarsen.lavaplayerbridge.player.Player) DataInterceptor(stream.flarebot.flarebot.web.DataInterceptor) FlareBot(stream.flarebot.flarebot.FlareBot) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 2 with GuildWrapper

use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.

the class HelpCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        CommandType type;
        try {
            type = CommandType.valueOf(args[0].toUpperCase());
        } catch (IllegalArgumentException ignored) {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
            return;
        }
        if (GeneralUtils.canRunInternalCommand(type, sender)) {
            List<String> pages = new ArrayList<>();
            List<String> help = type.getCommands().stream().filter(cmd -> getPermissions(channel).hasPermission(member, cmd.getPermission())).map(command -> guild.getPrefix() + command.getCommand() + " - " + command.getDescription() + '\n').collect(Collectors.toList());
            StringBuilder sb = new StringBuilder();
            for (String s : help) {
                if (sb.length() + s.length() > 1024) {
                    pages.add(sb.toString());
                    sb.setLength(0);
                }
                sb.append(s);
            }
            pages.add(sb.toString());
            PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
            builder.setTitle("***FlareBot " + type + " commands!***");
            builder.setColor(Color.CYAN);
            PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
        } else {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
        }
    } else {
        sendCommands(channel.getGuild(), channel, sender);
    }
}
Also used : Color(java.awt.Color) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) ArrayList(java.util.ArrayList) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) Command(stream.flarebot.flarebot.commands.Command) FlareBotManager(stream.flarebot.flarebot.FlareBotManager) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) PaginationList(stream.flarebot.flarebot.util.pagination.PaginationList) CommandType(stream.flarebot.flarebot.commands.CommandType) CommandType(stream.flarebot.flarebot.commands.CommandType) PagedEmbedBuilder(stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder) ArrayList(java.util.ArrayList)

Example 3 with GuildWrapper

use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.

the class PlayerListener method onTrackEnd.

@Override
public void onTrackEnd(AudioPlayer aplayer, AudioTrack atrack, AudioTrackEndReason reason) {
    GuildWrapper wrapper = FlareBotManager.instance().getGuild(player.getGuildId());
    if (wrapper == null)
        return;
    // No song on next
    if (player.getPlaylist().isEmpty()) {
        FlareBotManager.instance().getLastActive().put(Long.parseLong(player.getGuildId()), System.currentTimeMillis());
    }
    VoteUtil.remove(SkipCommand.getSkipUUID(), wrapper.getGuild());
    if (wrapper.isSongnickEnabled()) {
        if (GuildUtils.canChangeNick(player.getGuildId())) {
            Guild c = wrapper.getGuild();
            if (c == null) {
                wrapper.setSongnick(false);
            } else {
                if (player.getPlaylist().isEmpty())
                    c.getController().setNickname(c.getSelfMember(), null).queue();
            }
        } else {
            if (!GuildUtils.canChangeNick(player.getGuildId())) {
                MessageUtils.sendPM(Getters.getGuildById(player.getGuildId()).getOwner().getUser(), "FlareBot can't change it's nickname so SongNick has been disabled!");
            }
        }
    }
}
Also used : GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Guild(net.dv8tion.jda.core.entities.Guild)

Example 4 with GuildWrapper

use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.

the class Events method handleCommand.

private void handleCommand(GuildMessageReceivedEvent event, Command cmd, String[] args) {
    Metrics.commandsReceived.labels(cmd.getClass().getSimpleName()).inc();
    GuildWrapper guild = flareBot.getManager().getGuild(event.getGuild().getId());
    if (cmd.getType().isInternal()) {
        if (GeneralUtils.canRunInternalCommand(cmd.getType(), event.getAuthor())) {
            dispatchCommand(cmd, args, event, guild);
            return;
        } else {
            GeneralUtils.sendImage("https://flarebot.stream/img/trap.jpg", "trap.jpg", event.getAuthor());
            Constants.logEG("It's a trap", cmd, guild.getGuild(), event.getAuthor());
            return;
        }
    }
    if (guild.hasBetaAccess()) {
        if ((guild.getSettings().getChannelBlacklist().contains(event.getChannel().getIdLong()) || guild.getSettings().getUserBlacklist().contains(event.getAuthor().getIdLong())) && !guild.getPermissions().hasPermission(event.getMember(), stream.flarebot.flarebot.permissions.Permission.BLACKLIST_BYPASS))
            return;
    }
    if (guild.isBlocked() && System.currentTimeMillis() > guild.getUnBlockTime() && guild.getUnBlockTime() != -1)
        guild.revokeBlock();
    handleSpamDetection(event, guild);
    if (guild.isBlocked() && !(cmd.getType() == CommandType.SECRET))
        return;
    if (handleMissingPermission(cmd, event))
        return;
    if (!guild.hasBetaAccess() && cmd.isBetaTesterCommand()) {
        if (flareBot.isTestBot())
            LOGGER.error("Guild " + event.getGuild().getId() + " tried to use the beta command '" + cmd.getCommand() + "'!");
        return;
    }
    if (FlareBot.UPDATING.get()) {
        event.getChannel().sendMessage("**Currently updating!**").queue();
        return;
    }
    if (flareBot.getManager().isCommandDisabled(cmd.getCommand())) {
        MessageUtils.sendErrorMessage(flareBot.getManager().getDisabledCommandReason(cmd.getCommand()), event.getChannel(), event.getAuthor());
        return;
    }
    // Internal stuff
    if (event.getGuild().getIdLong() == Constants.OFFICIAL_GUILD && !handleOfficialGuildStuff(event, cmd))
        return;
    if (event.getGuild().getIdLong() != Constants.OFFICIAL_GUILD && cmd.getType() == CommandType.MUSIC) {
        MessageUtils.sendInfoMessage("FlareBot is closing down, as part of this we have disabled music commands, please read the announcement [here](https://docs.flarebot.stream). Please use the remaining available commands to move any data you wish over to other bots.\nBots we recommend:\nFredBoat - Music\nDyno - Moderation\nMee6 - Random stuff", event.getChannel());
        return;
    }
    dispatchCommand(cmd, args, event, guild);
}
Also used : GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper)

Example 5 with GuildWrapper

use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.

the class URLChecker method runTests.

public void runTests() {
    List<String> tests = ImmutableList.of("Check this out https://i.go.iplogger.com/12dxzfcs.php", "http://cool.webcam", "http://www.discord.gg/b1nzy", "https://flarebot.stream", // "http://bit.ly/2Ix3h5k",
    "www.iplogger.com", "http://test.iplogger.com/t?=192.0.0.1", "http://bit.ly/2FY9rJW");
    GuildWrapper wrapper = new GuildWrapper("1");
    wrapper.getNINO().addURLFlags(URLCheckFlag.IP_GRABBER, /*URLCheckFlag.BLACKLISTED,*/
    URLCheckFlag.DISCORD_INVITE, URLCheckFlag.PHISHING, URLCheckFlag.SUSPICIOUS);
    for (String url : tests) {
        instance().checkMessage(wrapper, null, url, (flag, u) -> logger.info(url + " - " + flag));
    }
}
Also used : GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper)

Aggregations

GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)25 TextChannel (net.dv8tion.jda.core.entities.TextChannel)12 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)12 CommandType (stream.flarebot.flarebot.commands.CommandType)11 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)10 Member (net.dv8tion.jda.core.entities.Member)10 User (net.dv8tion.jda.core.entities.User)10 Message (net.dv8tion.jda.core.entities.Message)9 Permission (stream.flarebot.flarebot.permissions.Permission)9 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Command (stream.flarebot.flarebot.commands.Command)8 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 ArrayList (java.util.ArrayList)6 FlareBot (stream.flarebot.flarebot.FlareBot)6 ButtonGroupConstants (stream.flarebot.flarebot.util.buttons.ButtonGroupConstants)6 GeneralUtils (stream.flarebot.flarebot.util.general.GeneralUtils)5 Color (java.awt.Color)4 Pattern (java.util.regex.Pattern)4 GuildUtils (stream.flarebot.flarebot.util.general.GuildUtils)4