net.dv8tion.jda.core.entities.Guild Java Examples

The following examples show how to use net.dv8tion.jda.core.entities.Guild. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Counter.java    From DiscordBot with Apache License 2.0 8 votes vote down vote up
private void create(String[] args, MessageReceivedEvent event) {
    Guild g = event.getGuild();

    String name = String.join(" ", Arrays.asList(args).subList(1, args.length));
    CCounter count = new CCounter(name, event.getMember());

    if (args.length < 2) {
        Messages.message(event.getTextChannel(), help(), Color.red);
        return;
    }

    if (counters.containsKey(g))
        counters.get(g).add(count);
    else {
        List<CCounter> l = new ArrayList<>();
        l.add(count);
        counters.put(event.getGuild(), l);
    }

    event.getTextChannel().sendMessage(new EmbedBuilder().setColor(Color.green).setDescription(
            String.format("Successfully created counter `%s`. *(ID: %d)*", name, counters.get(g).size() - 1)
    ).build()).queue();
}
 
Example #2
Source File: ServerLimitListener.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void onGuildJoin(GuildJoinEvent event) {

    Guild guild = event.getGuild();
    wildcards = getWilrdcards();

    if (guild.getJDA().getGuilds().size() > STATICS.SERVER_LIMIT) {
        guild.getOwner().getUser().openPrivateChannel().queue(pc -> pc.sendMessage(
                new EmbedBuilder().setColor(Color.ORANGE).setTitle("Server Limit Reached", null).setDescription(
                        "Sorry, but because of currently limited resources the bot is limited to run on maximum " + STATICS.SERVER_LIMIT + " Servers.\n\n" +
                        "If you have a wildcard, you can send the token via PM to zekroBot.\n" +
                        "Otherwise, the bot will leave the server automatically after 2 minutes."
                ).build()
        ).queue());
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                guild.leave().queue();
            }
        }, 120000);
    }

}
 
Example #3
Source File: Autochannel.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private void setChan(String id, Guild g, TextChannel tc) {
    VoiceChannel vc = getVchan(id, g);

    if (vc == null) {
        tc.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(
                String.format("Voice channel with the ID `%s` does not exist.", id)
        ).build()).queue();
    } else if (autochans.containsKey(vc)) {
        tc.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(
                "This channel is just set as auto channel."
        ).build()).queue();
    } else {
        autochans.put(vc, g);
        saveVchan(vc, g);
        tc.sendMessage(new EmbedBuilder().setColor(Color.green).setDescription(
                String.format("Successfully set voice channel `%s` as auto channel.", vc.getName())
        ).build()).queue();
    }
}
 
Example #4
Source File: Autochannel.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private void unsetChan(String id, Guild g, TextChannel tc) {
    VoiceChannel vc = getVchan(id, g);

    if (vc == null) {
        tc.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(
                String.format("Voice channel with the ID `%s` does not exist.", id)
        ).build()).queue();
    } else if (!autochans.containsKey(vc)) {
        tc.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(
                String.format("Voice channel `%s` is not set as auto channel.", vc.getName())
        ).build()).queue();
    } else {
        autochans.remove(vc);
        unsetChan(vc);

        tc.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(
                String.format("Successfully unset auto channel state of `%s`.", vc.getName())
        ).build()).queue();
    }
}
 
Example #5
Source File: FlareBot.java    From FlareBot with MIT License 6 votes vote down vote up
private void sendData() {
    Guild g = Getters.getOfficialGuild();
    JSONObject data = new JSONObject()
            .put("guilds", Getters.getGuildCache().size())
            //.put("loaded_guilds", FlareBotManager.instance().getGuilds().size())
            .put("official_guild_users", g != null ? g.getMemberCache().size() : -1)
            .put("text_channels", Getters.getTextChannelCache().size())
            .put("voice_channels", Getters.getVoiceChannelCache().size())
            .put("connected_voice_channels", Getters.getConnectedVoiceChannels())
            .put("active_voice_channels", Getters.getActiveVoiceChannels())
            .put("num_queued_songs", getMusicManager().getPlayers().stream()
                    .mapToInt(player -> player.getPlaylist().size()).sum())
            .put("ram", (((runtime.totalMemory() - runtime.freeMemory()) / 1024) / 1024) + "MB")
            .put("uptime", getUptime())
            .put("http_requests", dataInterceptor.getRequests().intValue());

    ApiRequester.requestAsync(ApiRoute.UPDATE_DATA, data);
}
 
Example #6
Source File: Vote2.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private void closeVote(MessageReceivedEvent event) {

        if (!polls.containsKey(event.getGuild())) {
            message("There is currently no vote running!", Color.red);
            return;
        }

        Guild g = event.getGuild();
        Poll poll = polls.get(g);

        if (!poll.getCreator(g).equals(event.getMember())) {
            message("Only the creator of the poll (" + poll.getCreator(g).getAsMention() + ") can close this poll!", Color.red);
            return;
        }

        polls.remove(g);
        channel.sendMessage(getParsedPoll(poll, g).build()).queue();
        message("Poll closed by " + event.getAuthor().getAsMention() + ".", new Color(0xFF7000));

    }
 
Example #7
Source File: Vote2.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private EmbedBuilder getParsedPoll(Poll poll, Guild guild) {

        StringBuilder ansSTR = new StringBuilder();
        final AtomicInteger count = new AtomicInteger();

        poll.answers.forEach(s -> {
            long votescount = poll.votes.keySet().stream().filter(k -> poll.votes.get(k).equals(count.get() + 1)).count();
            ansSTR.append(EMOTI[count.get()] + "  -  " + s + "  -  Votes: `" + votescount + "` \n");
            count.addAndGet(1);
        });

        return new EmbedBuilder()
                .setAuthor(poll.getCreator(guild).getEffectiveName() + "'s poll.", null, poll.getCreator(guild).getUser().getAvatarUrl())
                .setDescription(":pencil:   " + poll.heading + "\n\n" + ansSTR.toString())
                .setFooter("Enter '" + SSSS.getPREFIX(guild) + "vote v <number>' to vote!", null)
                .setColor(Color.cyan);

    }
 
Example #8
Source File: MigrationHandler.java    From FlareBot with MIT License 6 votes vote down vote up
public int migrateSinglePermissionForGuild(String oldPermission, String newPermission, Guild guild) {
    int i = 0;
    GuildWrapper wrapper = null;
    try {
        wrapper = FlareBotManager.instance().getGuildNoCache(guild.getId());
        Pattern oldPerm =
                Pattern.compile("\\b" + oldPermission.replaceAll("\\.", "\\.") + "\\b"); // Make sure it is exact permission
        for (Group g : wrapper.getPermissions().getGroups()) {
            for (final Iterator<String> it = g.getPermissions().iterator(); it.hasNext(); ) {
                String perm = it.next();
                if (oldPerm.matcher(perm).find()) {
                    it.remove();
                    g.getPermissions().add(perm.replace(oldPermission, newPermission));
                    i++;
                }
            }
        }
    } catch (Exception e) {
        FlareBot.LOGGER.error("Migration failed", e);
    }
    FlareBotManager.instance().saveGuild(guild.getId(), wrapper, System.currentTimeMillis());
    return i;
}
 
Example #9
Source File: TrackManager.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
    try {
        Guild g = queue.poll().getAuthor().getGuild();
        if (queue.isEmpty()) {
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    g.getAudioManager().closeAudioConnection();
                }
            }, 500);
        } else {
            player.playTrack(queue.element().getTrack());
        }
    } catch (Exception e) {}
}
 
Example #10
Source File: Counter.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private void list(MessageReceivedEvent event) {
    Guild g = event.getGuild();

    if (!counters.containsKey(event.getGuild())) {
        Messages.message(event.getTextChannel(), "This guild has no counters!", Color.red);
        return;
    }

    StringBuilder sb = new StringBuilder();
    AtomicInteger count = new AtomicInteger();
    counters.get(g).forEach(c ->
        sb.append(String.format(":white_small_square:   `[%d]`  -  %s  -  **%d**\n", count.getAndAdd(1), c.name, c.count))
    );
    event.getTextChannel().sendMessage(new EmbedBuilder()
            .setColor(Color.cyan)
            .setTitle("Current counters")
            .setDescription(sb.toString())
            .build()).queue();
}
 
Example #11
Source File: AutochannelHandler.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
    HashMap<VoiceChannel, Guild> autochans = commands.guildAdministration.Autochannel.getAutochans();
    VoiceChannel vc = event.getChannelJoined();
    Guild g = event.getGuild();

    if (autochans.containsKey(vc)) {
        VoiceChannel nvc = (VoiceChannel) g.getController().createVoiceChannel(vc.getName() + " [AC]")
                .setBitrate(vc.getBitrate())
                .setUserlimit(vc.getUserLimit())
                .complete();
        System.out.println(vc.getParent());

        if (vc.getParent() != null)
            nvc.getManager().setParent(vc.getParent()).queue();

        g.getController().modifyVoiceChannelPositions().selectPosition(nvc).moveTo(vc.getPosition() + 1).queue();
        g.getController().modifyVoiceChannelPositions().selectPosition(nvc).moveTo(vc.getPosition() + 1).queue();
        g.getController().moveVoiceMember(event.getMember(), nvc).queue();
        active.add(nvc);
    }
}
 
Example #12
Source File: Stats.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private GuildStats(Guild g) {

            List<Member> l = g.getMembers();

            this.name = g.getName();
            this.id = g.getId();
            this.region = g.getRegion().getName();
            this.avatar = g.getIconUrl() == null ? "not set" : g.getIconUrl();
            this.textChans = g.getTextChannels().size();
            this.voiceChans = g.getVoiceChannels().size();
            this.categories = g.getCategories().size();
            this.rolesCount = g.getRoles().size();
            this.afk = g.getAfkChannel() == null ? "not set" : g.getAfkChannel().getName();
            this.owner = g.getOwner();

            this.all = l.size();
            this.users = l.stream().filter(m -> !m.getUser().isBot()).count();
            this.onlineUsers = l.stream().filter(m -> !m.getUser().isBot() && !m.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count();
            this.bots = l.stream().filter(m -> m.getUser().isBot()).count();
            this.onlineBots = l.stream().filter(m -> m.getUser().isBot() && !m.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count();

            this.roles = g.getRoles().stream()
                    .filter(r -> !r.getName().contains("everyone"))
                    .map(r -> String.format("%s (`%d`)", r.getName(), getMembsInRole(r)))
                    .collect(Collectors.joining(", "));
        }
 
Example #13
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static String getSERVERJOINMESSAGE(Guild guild) {

        String out = Main.getMySql().getString("guilds", "joinmsg", "id", guild.getId());
        if (out == null)
            return "OFF";
        return out;
    }
 
Example #14
Source File: ParseUtils.java    From FlareBot with MIT License 5 votes vote down vote up
/**
 * Parse user input to find a user.
 *
 * Accepts:
 * * Mention
 * * Name
 * * ID
 *
 * @param guild The guild to find the user from.
 * @param input The input of which to search.
 * @param searchGlobally If we should search the entirety of FlareBot or just the guild.
 * @return The User if found, null otherwise.
 */
@Nullable
public static User parseUser(Guild guild, String input, boolean searchGlobally) {
    Matcher matcher = Message.MentionType.USER.getPattern().matcher(input);
    if (matcher.matches()) {
        return Getters.getUserById(matcher.group(1));
    }

    for (Member m : guild.getMemberCache()) {
        if (m.getUser().getName().equalsIgnoreCase(input)
                || (m.getNickname() != null && m.getNickname().equalsIgnoreCase(input))
                || input.contains("#")
                && (m.getUser().getName() + '#' + m.getUser().getDiscriminator()).equalsIgnoreCase(input))
            return m.getUser();
    }

    if (searchGlobally) {
        for (User u : Getters.getUserCache())
            if (u.getName().equalsIgnoreCase(input) ||
                    input.contains("#") && (u.getName() + '#' + u.getDiscriminator()).equalsIgnoreCase(input))
                return u;
    }

    try {
        return Getters.getUserById(input);
    } catch (NumberFormatException e) {
        return null;
    }
}
 
Example #15
Source File: AutochannelHandler.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
    HashMap<VoiceChannel, Guild> autochans = commands.guildAdministration.Autochannel.getAutochans();
    Guild g = event.getGuild();

    VoiceChannel vc = event.getChannelJoined();

    if (autochans.containsKey(vc)) {
        VoiceChannel nvc = (VoiceChannel) g.getController().createVoiceChannel(vc.getName() + " [AC]")
                .setBitrate(vc.getBitrate())
                .setUserlimit(vc.getUserLimit())
                .complete();

        if (vc.getParent() != null)
            nvc.getManager().setParent(vc.getParent()).queue();

        g.getController().modifyVoiceChannelPositions().selectPosition(nvc).moveTo(vc.getPosition() + 1).queue();
        g.getController().moveVoiceMember(event.getMember(), nvc).queue();
        active.add(nvc);
    }

    vc = event.getChannelLeft();

    if (active.contains(vc) && vc.getMembers().size() == 0) {
        active.remove(vc);
        vc.delete().queue();
    }
}
 
Example #16
Source File: BotGuildJoinListener.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@Override
public void onGuildJoin(GuildJoinEvent event) {

    Guild guild = event.getGuild();
    GuildController controller = guild.getController();

    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {

            controller.createCategory("zekroBot").queue(cat -> {

                controller.modifyCategoryPositions()
                        .selectPosition(cat.getPosition())
                        .moveTo(0).queue();

                String[] list = {"music", "commands", "cmdlog", "warframealerts", "voicelog"};

                Arrays.stream(list).forEach(s ->
                        controller.createTextChannel(s).queue(chan -> chan.getManager().setParent((Category) cat).queue())
                );
            });

        }
    }, 500);

}
 
Example #17
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static void listSettings(MessageReceivedEvent event) {

        Guild g = event.getGuild();

        HashMap<String, String> sets = new HashMap<>();
        sets.put("PREFIX                ", getPREFIX(g));
        sets.put("SERVER_JOIN_MSG       ", getSERVERJOINMESSAGE(g));
        sets.put("SERVER_LEAVE_MSG      ", getSERVERJOINMESSAGE(g));
        sets.put("MUSIC_CHANNEL         ", getMUSICCHANNEL(g));
        sets.put("LOCK_MUSIC_CHANNEL    ", getLOCKMUSICCHANNEL(g) ? "TRUE" : "FALSE");
        sets.put("AUTOROLE              ", getAUTOROLE(g));
        sets.put("VKICK_CHANNEL         ", getVKICKCHANNEL(g));
        sets.put("RAND6_OPS_URL         ", getR6OPSID(g));
        sets.put("WARFRAMEALERTS_CHANNEL", getWARFRAMELAERTSCHAN(g));

        HashMap<String, String> setsMulti = new HashMap<>();
        setsMulti.put("PERMROLES_LVL1", String.join(", ", getPERMROLES_1(g)));
        setsMulti.put("PERMROLES_LVL2", String.join(", ", getPERMROLES_2(g)));
        setsMulti.put("BLACKLIST", String.join(", ", getBLACKLIST(g)));

        StringBuilder sb = new StringBuilder()
                .append("**GUILD SPECIFIC SETTINGS**\n\n")
                .append("```")
                .append("SETTINGS KEY            -  VALUE\n\n");

        sets.forEach((k, v) -> sb.append(
                String.format("%s  -  \"%s\"\n", k, v))
        );

        sb.append("\n- - - - -\n\n");
        setsMulti.forEach((k, v) -> sb.append(
                String.format("%s:\n\"%s\"\n\n", k, v))
        );

        event.getTextChannel().sendMessage(new EmbedBuilder().setDescription(sb.append("```").toString()).build()).queue();
    }
 
Example #18
Source File: Counter.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) throws ParseException, IOException {

    Message message = event.getMessage();
    Guild guild = event.getGuild();
    Member author = event.getMember();

    if (args.length < 1) {
        Messages.message(message.getTextChannel(), help(), Color.red);
        return;
    }

    switch (args[0]) {

        case "add":
        case "create":
            create(args, event);
            break;

        case "delete":
        case "remove":
            delete(args, event);
            break;

        case "list":
            list(event);
            break;

        default:
            changeValue(args, event);
    }

    saveAll();

}
 
Example #19
Source File: Counter.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
private void delete(String[] args, MessageReceivedEvent event) {
    Guild g = event.getGuild();

    if (!counters.containsKey(g)) {
        Messages.message(event.getTextChannel(), "This guild has no counters!", Color.red);
        return;
    }

    int id;

    try {
        id = Integer.valueOf(args[1]);
        if (id > counters.get(g).size() - 1)
            throw new Exception();
    } catch (Exception e) {
        Messages.message(event.getTextChannel(), "Please enter a valid ID.", Color.red);
        return;
    }

    Member creator = counters.get(g).get(id).getCreator(g);
    if (!creator.equals(event.getMember())) {
        Messages.error(event.getTextChannel(), String.format("Only the creator of the counter (%s) is allowed to delete this counter.", creator.getAsMention()));
        return;
    }

    CCounter tcount = counters.get(g).get(id);
    counters.get(g).remove(id);

    new File("SERVER_SETTINGS/" + g.getId() + "/counters/counter_" + id + ".dat").delete();

    event.getTextChannel().sendMessage(new EmbedBuilder().setColor(Color.orange).setDescription(
            String.format("Successfully removed counter `%s` *(%d)*.", tcount.name, id)
    ).build()).queue();
}
 
Example #20
Source File: FormatUtils.java    From FlareBot with MIT License 5 votes vote down vote up
/**
 * Formats a String to replace {%} with the prefix from the {@link Guild}.
 *
 * @param guild The {@link Guild} the get prefix from.
 * @param usage The String to format with prefix.
 * @return The String with the prefix in place of of {%}.
 */
public static String formatCommandPrefix(Guild guild, String usage) {
    if (guild == null) return Constants.COMMAND_CHAR_STRING;
    String prefix = String.valueOf(GuildUtils.getPrefix(guild));
    if (usage.contains("{%}"))
        return usage.replace("{%}", prefix);
    return usage;
}
 
Example #21
Source File: ModlogEvents.java    From FlareBot with MIT License 5 votes vote down vote up
private void onGuildUpdateExplicitContentLevel(GuildUpdateExplicitContentLevelEvent e, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.GUILD_EXPLICIT_FILTER_CHANGE)) return;
    AuditLogEntry entry = e.getGuild().getAuditLogs().complete().get(0);
    AuditLogChange levelChange = entry.getChanges().get("explicit_content_filter");

    ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.GUILD_EXPLICIT_FILTER_CHANGE, entry.getUser(),
            new MessageEmbed.Field("Old level", Guild.ExplicitContentLevel.fromKey(levelChange.getOldValue()).getDescription(), true),
            new MessageEmbed.Field("New level", Guild.ExplicitContentLevel.fromKey(levelChange.getNewValue()).getDescription(), true));
}
 
Example #22
Source File: PlayerListener.java    From FlareBot with MIT License 5 votes vote down vote up
@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!");
            }
        }
    }
}
 
Example #23
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static String getSERVERLEAVEMESSAGE(Guild guild) {

        String out = Main.getMySql().getString("guilds", "leavemsg", "id", guild.getId());
        if (out == null)
            return "OFF";
        return out;
    }
 
Example #24
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static String getMUSICCHANNEL(Guild guild) {

        String out = Main.getMySql().getString("guilds", "musicchan", "id", guild.getId());
        if (out == null)
            return "";
        return out;
    }
 
Example #25
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static String[] getPERMROLES_1(Guild guild) {

        String out = Main.getMySql().getString("guilds", "perm1", "id", guild.getId());
        if (out == null)
            return STATICS.PERMS;
        return out.split(",");

    }
 
Example #26
Source File: SSSS.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static String[] getPERMROLES_2(Guild guild) {

        String out = Main.getMySql().getString("guilds", "perm2", "id", guild.getId());
        if (out == null)
            return STATICS.FULLPERMS;
        return out.split(",");
    }
 
Example #27
Source File: VoteUtil.java    From FlareBot with MIT License 5 votes vote down vote up
public static void finishNow(UUID uuid, Guild guild) {
    VoteGroup group = groupMap.get(uuid + guild.getId());
    String message = group.getVoteMessage().getId();
    groupMap.remove(uuid + guild.getId());
    runnableMap.get(uuid + guild.getId()).run(group.won());
    runnableMap.remove(uuid + guild.getId());
    Scheduler.cancelTask("Votes-" + message);
    group.getVoteMessage().getChannel().deleteMessageById(group.getVoteMessage().getId()).queue();
}
 
Example #28
Source File: VoiceChannelCleanup.java    From FlareBot with MIT License 5 votes vote down vote up
private void cleanup(Guild guild, Player player, long id) {
    if (guild != null && guild.getSelfMember().getVoiceState() != null
            && guild.getSelfMember().getVoiceState().getChannel() != null
            && guild.getAudioManager().isConnected()
            && guild.getAudioManager().getConnectionStatus() == ConnectionStatus.CONNECTED
            && closedConnections.get() < WEBSOCKET_THRESHOLD) { // Cut off at threshold in-case we send too many
        guild.getAudioManager().closeAudioConnection();
        closedConnections.incrementAndGet();
    }

    FlareBot.instance().getMusicManager().deletePlayer(player);
    VC_LAST_USED.remove(id);
}
 
Example #29
Source File: HelpCommand.java    From FlareBot with MIT License 5 votes vote down vote up
private void sendCommands(Guild guild, TextChannel channel, User sender) {
    List<String> pages = new ArrayList<>();
    for (CommandType c : CommandType.getTypes()) {
        List<String> help = c.getCommands()
                .stream().filter(cmd -> cmd.getPermission() != null &&
                        FlareBotManager.instance().getGuild(guild.getId())
                                .getPermissions()
                                .hasPermission(guild
                                        .getMember(sender), cmd
                                        .getPermission()))
                .map(command -> FlareBotManager.instance().getGuild(guild.getId()).getPrefix() + command.getCommand() + " - " + command
                        .getDescription() + '\n')
                .collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();
        sb.append("**").append(c).append("**\n");
        for (String s : help) {
            if (sb.length() + s.length() > 1024) {
                pages.add(sb.toString());
                sb.setLength(0);
                sb.append("**").append(c).append("**\n");
            }
            sb.append(s);
        }
        if (sb.toString().trim().isEmpty()) continue;
        pages.add(sb.toString());
    }
    PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
    builder.setColor(Color.CYAN);
    PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
}
 
Example #30
Source File: Constants.java    From FlareBot with MIT License 5 votes vote down vote up
public static void logEG(String eg, Command command, Guild guild, User user) {
    EmbedBuilder builder = new EmbedBuilder().setTitle("Found `" + eg + "`")
            .addField("Guild", guild.getId() + " (`" + guild.getName() + "`) ", true)
            .addField("User", user.getAsMention() + " (`" + user.getName() + "#" + user.getDiscriminator() + "`)", true)
            .setTimestamp(LocalDateTime.now(Clock.systemUTC()));
    if (command != null) builder.addField("Command", command.getCommand(), true);
    Constants.getEGLogChannel().sendMessage(builder.build()).queue();
}