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