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 + "!");
}
}
Aggregations