Search in sources :

Example 1 with Category

use of net.dv8tion.jda.core.entities.Category in project TheLighterBot by PhotonBursted.

the class TemporaryChannelCommand method execute.

@Override
protected void execute() {
    // Gather the name of the channel from the remaining input
    String channelName = Utils.drainQueueToString(input);
    // Check if the channel name is available still
    if (ev.getGuild().getVoiceChannelsByName("[T] " + channelName, true).size() != 0 || ev.getGuild().getTextChannelsByName(Utils.ircify("tdc-" + channelName), true).size() != 0) {
        // If no channel is available, send feedback to the user
        if (ev.getGuild().getVoiceChannelsByName("[T] " + channelName, true).size() == 0) {
            handleError("A text channel with the specified name already exists!\n" + "Keep in mind that in order to generate a valid channel name, special characters are deleted.");
        } else {
            handleError("The voice channel name specified was already taken!\n" + "Try again with another name.");
        }
    } else {
        Category parent;
        CategoryMap categories = l.getChannelController().getCategories();
        LoggerUtils.logAndDelete(log, "Creating new temporary channel set\n" + " - Name: " + channelName);
        // If a default category has been specified it should point towards that.
        if (categories.containsKey(ev.getGuild()) && categories.get(ev.getGuild()) != null && ev.getGuild().getCategories().stream().anyMatch(c -> c.getId().equals(categories.get(ev.getGuild()).getId()))) {
            parent = categories.get(ev.getGuild());
        } else {
            // A category was specified but not found.
            // The category is removed from registry and a new parent category will be created.
            categories.removeByKeyStoring(ev.getGuild());
            parent = null;
        }
        // Create the temporary channels
        createTemporaryChannels(channelName, parent);
        // Send feedback to the user
        l.getDiscordController().sendMessage(ev, String.format("%s succesfully added temporary channel **%s**.\n" + "This channel will be deleted as soon as every person has left or when nobody has joined within 10 seconds.", ev.getMember().getAsMention(), channelName), 10);
        log.info("Created group " + channelName + "!");
    }
}
Also used : Logger(org.slf4j.Logger) Permission(net.dv8tion.jda.core.Permission) LoggerUtils(st.photonbur.Discord.Bot.lightbotv3.main.LoggerUtils) Utils(st.photonbur.Discord.Bot.lightbotv3.misc.Utils) Category(net.dv8tion.jda.core.entities.Category) LoggerFactory(org.slf4j.LoggerFactory) CommandAliasCollectionBuilder(st.photonbur.Discord.Bot.lightbotv3.command.alias.CommandAliasCollectionBuilder) CategoryMap(st.photonbur.Discord.Bot.lightbotv3.misc.map.CategoryMap) Category(net.dv8tion.jda.core.entities.Category) CategoryMap(st.photonbur.Discord.Bot.lightbotv3.misc.map.CategoryMap)

Example 2 with Category

use of net.dv8tion.jda.core.entities.Category in project TheLighterBot by PhotonBursted.

the class FileController method retrieveDefaultCategories.

private void retrieveDefaultCategories() throws SQLException {
    retrieveData("SELECT dc.*\n" + "FROM \"Servers\" AS s\n" + "  LEFT JOIN \"DefaultCategories\" AS dc ON dc.server_id = s.discord_id\n" + "WHERE dc.server_id IS NOT NULL", result -> {
        try {
            Guild g = l.getBot().getGuildById(result.getLong("server_id"));
            long entityId = result.getLong("category_id");
            Category c = l.getBot().getCategoryById(entityId);
            if (g != null && c != null) {
                l.getChannelController().getCategories().put(g, c);
            }
        } catch (SQLException ex) {
            log.error("Something went wrong retrieving the default categories", ex);
        }
    });
}
Also used : Category(net.dv8tion.jda.core.entities.Category) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

Category (net.dv8tion.jda.core.entities.Category)2 Permission (net.dv8tion.jda.core.Permission)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 CommandAliasCollectionBuilder (st.photonbur.Discord.Bot.lightbotv3.command.alias.CommandAliasCollectionBuilder)1 LoggerUtils (st.photonbur.Discord.Bot.lightbotv3.main.LoggerUtils)1 Utils (st.photonbur.Discord.Bot.lightbotv3.misc.Utils)1 CategoryMap (st.photonbur.Discord.Bot.lightbotv3.misc.map.CategoryMap)1