Search in sources :

Example 1 with CategoryMap

use of st.photonbur.Discord.Bot.lightbotv3.misc.map.CategoryMap 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)

Aggregations

Permission (net.dv8tion.jda.core.Permission)1 Category (net.dv8tion.jda.core.entities.Category)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