Search in sources :

Example 1 with Timeout

use of net.dv8tion.jda.api.entities.Guild.Timeout in project JDA by DV8FromTheWorld.

the class EntityBuilder method createTemplate.

public Template createTemplate(DataObject object) {
    final String code = object.getString("code");
    final String name = object.getString("name");
    final String description = object.getString("description", null);
    final int uses = object.getInt("usage_count");
    final User creator = createUser(object.getObject("creator"));
    final OffsetDateTime createdAt = OffsetDateTime.parse(object.getString("created_at"));
    final OffsetDateTime updatedAt = OffsetDateTime.parse(object.getString("updated_at"));
    final long guildId = object.getLong("source_guild_id");
    final DataObject guildObject = object.getObject("serialized_source_guild");
    final String guildName = guildObject.getString("name");
    final String guildDescription = guildObject.getString("description", null);
    final String guildIconId = guildObject.getString("icon_hash", null);
    final VerificationLevel guildVerificationLevel = VerificationLevel.fromKey(guildObject.getInt("verification_level", -1));
    final NotificationLevel notificationLevel = NotificationLevel.fromKey(guildObject.getInt("default_message_notifications", 0));
    final ExplicitContentLevel explicitContentLevel = ExplicitContentLevel.fromKey(guildObject.getInt("explicit_content_filter", 0));
    final Locale locale = Locale.forLanguageTag(guildObject.getString("preferred_locale", "en"));
    final Timeout afkTimeout = Timeout.fromKey(guildObject.getInt("afk_timeout", 0));
    final DataArray roleArray = guildObject.getArray("roles");
    final DataArray channelsArray = guildObject.getArray("channels");
    final long afkChannelId = guildObject.getLong("afk_channel_id", -1L);
    final long systemChannelId = guildObject.getLong("system_channel_id", -1L);
    final List<TemplateRole> roles = new ArrayList<>();
    for (int i = 0; i < roleArray.length(); i++) {
        DataObject obj = roleArray.getObject(i);
        final long roleId = obj.getLong("id");
        final String roleName = obj.getString("name");
        final int roleColor = obj.getInt("color");
        final boolean hoisted = obj.getBoolean("hoist");
        final boolean mentionable = obj.getBoolean("mentionable");
        final long rawPermissions = obj.getLong("permissions");
        roles.add(new TemplateRole(roleId, roleName, roleColor == 0 ? Role.DEFAULT_COLOR_RAW : roleColor, hoisted, mentionable, rawPermissions));
    }
    final List<TemplateChannel> channels = new ArrayList<>();
    for (int i = 0; i < channelsArray.length(); i++) {
        DataObject obj = channelsArray.getObject(i);
        final long channelId = obj.getLong("id");
        final int type = obj.getInt("type");
        final ChannelType channelType = ChannelType.fromId(type);
        final String channelName = obj.getString("name");
        final String topic = obj.getString("topic", null);
        final int rawPosition = obj.getInt("position");
        final long parentId = obj.getLong("parent_id", -1);
        final boolean nsfw = obj.getBoolean("nsfw");
        final int slowmode = obj.getInt("rate_limit_per_user");
        final int bitrate = obj.getInt("bitrate");
        final int userLimit = obj.getInt("user_limit");
        final List<TemplateChannel.PermissionOverride> permissionOverrides = new ArrayList<>();
        DataArray overrides = obj.getArray("permission_overwrites");
        for (int j = 0; j < overrides.length(); j++) {
            DataObject overrideObj = overrides.getObject(j);
            final long overrideId = overrideObj.getLong("id");
            final long allow = overrideObj.getLong("allow");
            final long deny = overrideObj.getLong("deny");
            permissionOverrides.add(new TemplateChannel.PermissionOverride(overrideId, allow, deny));
        }
        channels.add(new TemplateChannel(channelId, channelType, channelName, topic, rawPosition, parentId, type == 5, permissionOverrides, nsfw, slowmode, bitrate, userLimit));
    }
    TemplateChannel afkChannel = channels.stream().filter(templateChannel -> templateChannel.getIdLong() == afkChannelId).findFirst().orElse(null);
    TemplateChannel systemChannel = channels.stream().filter(templateChannel -> templateChannel.getIdLong() == systemChannelId).findFirst().orElse(null);
    final TemplateGuild guild = new TemplateGuild(guildId, guildName, guildDescription, guildIconId, guildVerificationLevel, notificationLevel, explicitContentLevel, locale, afkTimeout, afkChannel, systemChannel, roles, channels);
    final boolean synced = !object.getBoolean("is_dirty", false);
    return new Template(getJDA(), code, name, description, uses, creator, createdAt, updatedAt, guild, synced);
}
Also used : TemplateChannel(net.dv8tion.jda.api.entities.templates.TemplateChannel) Timeout(net.dv8tion.jda.api.entities.Guild.Timeout) TemplateGuild(net.dv8tion.jda.api.entities.templates.TemplateGuild) VerificationLevel(net.dv8tion.jda.api.entities.Guild.VerificationLevel) DataArray(net.dv8tion.jda.api.utils.data.DataArray) TemplateRole(net.dv8tion.jda.api.entities.templates.TemplateRole) Template(net.dv8tion.jda.api.entities.templates.Template) DataObject(net.dv8tion.jda.api.utils.data.DataObject) ExplicitContentLevel(net.dv8tion.jda.api.entities.Guild.ExplicitContentLevel) OffsetDateTime(java.time.OffsetDateTime) NotificationLevel(net.dv8tion.jda.api.entities.Guild.NotificationLevel)

Aggregations

OffsetDateTime (java.time.OffsetDateTime)1 ExplicitContentLevel (net.dv8tion.jda.api.entities.Guild.ExplicitContentLevel)1 NotificationLevel (net.dv8tion.jda.api.entities.Guild.NotificationLevel)1 Timeout (net.dv8tion.jda.api.entities.Guild.Timeout)1 VerificationLevel (net.dv8tion.jda.api.entities.Guild.VerificationLevel)1 Template (net.dv8tion.jda.api.entities.templates.Template)1 TemplateChannel (net.dv8tion.jda.api.entities.templates.TemplateChannel)1 TemplateGuild (net.dv8tion.jda.api.entities.templates.TemplateGuild)1 TemplateRole (net.dv8tion.jda.api.entities.templates.TemplateRole)1 DataArray (net.dv8tion.jda.api.utils.data.DataArray)1 DataObject (net.dv8tion.jda.api.utils.data.DataObject)1