Java 类net.dv8tion.jda.core.entities.ISnowflake 实例源码

项目:Saber-Bot    文件:ListCommand.java   
/**
 * Determines if a user should be display based on the set filters
 * @param member (Member) User to evaluate
 * @param userFilters (List) list of user IDs to filter by
 * @param roleFilters (List) list of role IDs to filter by
 * @return (boolean) should the user be included in the list?
 */
private boolean checkMember(Member member, List<String> userFilters, List<String> roleFilters)
{
    if(member!=null)
    {
        boolean skip = false;
        if(!userFilters.isEmpty() && !userFilters.contains(member.getUser().getId()))
        {
            skip = true;
        }
        if(!roleFilters.isEmpty())
        {
            skip = true;
            for(String role : roleFilters)
            {
                List<String> memberRoles = member.getRoles().stream()
                        .map(ISnowflake::getId).collect(Collectors.toList());
                if(memberRoles.contains(role))
                {
                    skip = false;
                    break;
                }
            }
        }
        return !skip;
    }
    return false;
}
项目:JDA    文件:EmoteManagerUpdatable.java   
/**
 * Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
 * that will apply <b>all</b> changes that have been made to this manager instance.
 * <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
 *
 * <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
 * <br>This is automatically called if this method returns successfully.
 *
 * <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
 * update include the following:
 * <ul>
 *      <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
 *      <br>If the target Emote was deleted before finishing the task</li>
 *
 *      <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
 *      <br>If the currently logged in account was removed from the Guild before finishing the task</li>
 *
 *      <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
 *      <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_EMOTES MANAGE_EMOTES Permission}
 *          before finishing the task</li>
 * </ul>
 *
 * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
 *         If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_EMOTES MANAGE_EMOTES}
 *         in the underlying {@link net.dv8tion.jda.core.entities.Guild Guild}.
 *
 * @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
 *         <br>Applies all changes that have been made in a single api-call.
 */
@CheckReturnValue
public AuditableRestAction<Void> update()
{
    checkPermission(Permission.MANAGE_EMOTES);

    if (!needsUpdate())
        return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);

    JSONObject body = new JSONObject();

    if (name.shouldUpdate())
        body.put("name", name.getValue());
    if (roles.shouldUpdate())
        body.put("roles", roles.getValue().stream().map(ISnowflake::getId).collect(Collectors.toList()));

    reset(); //reset because we built the JSONObject needed to update
    Route.CompiledRoute route = Route.Emotes.MODIFY_EMOTE.compile(getGuild().getId(), emote.getId());
    return new AuditableRestAction<Void>(getJDA(), route, body)
    {
        @Override
        protected void handleResponse(Response response, Request<Void> request)
        {
            if (response.isOk())
                request.onSuccess(null);
            else
                request.onFailure(response);
        }
    };
}
项目:GabrielBot    文件:GabrielBot.java   
private <T extends ISnowflake> SnowflakeCacheView<T> view(Function<JDA, SnowflakeCacheView<T>> mapper) {
    return CacheView.allSnowflakes(Arrays.stream(shards).map(s->mapper.apply(s.getJDA())).collect(Collectors.toList()));
}
项目:pokeraidbot    文件:InstallEmotesCommand.java   
private void createEmote(String iconName, CommandEvent commandEvent, Icon icon, Role... roles) {
    JSONObject body = new JSONObject();
    body.put("name", iconName);
    body.put("image", icon.getEncoding());
    if (roles.length > 0) // making sure none of the provided roles are null before mapping them to the snowflake id
    {
        body.put("roles",
                Stream.of(roles).filter(Objects::nonNull).map(ISnowflake::getId).collect(Collectors.toSet()));
    }

    // todo: check bot permissions, must be able to handle emojis
    GuildImpl guild = (GuildImpl) commandEvent.getGuild();
    JDA jda = commandEvent.getJDA();
    Route.CompiledRoute route = Route.Emotes.CREATE_EMOTE.compile(guild.getId());
    AuditableRestAction<Emote> action = new AuditableRestAction<Emote>(jda, route, body)
    {
        @Override
        protected void handleResponse(Response response, Request<Emote> request)
        {
            if (response.isOk()) {
                JSONObject obj = response.getObject();
                final long id = obj.getLong("id");
                String name = obj.getString("name");
                EmoteImpl emote = new EmoteImpl(id, guild).setName(name);
                // managed is false by default, should always be false for emotes created by client accounts.

                JSONArray rolesArr = obj.getJSONArray("roles");
                Set<Role> roleSet = emote.getRoleSet();
                for (int i = 0; i < rolesArr.length(); i++)
                {
                    roleSet.add(guild.getRoleById(rolesArr.getString(i)));
                }

                // put emote into cache
                guild.getEmoteMap().put(id, emote);

                request.onSuccess(emote);
            }
            else {
                request.onFailure(response);
                throw new RuntimeException("Couldn't install emojis. " +
                        "Make sure that pokeraidbot has access to manage emojis.");
            }
        }
    };
    action.queue();
}
项目:JDA    文件:MiscUtil.java   
/**
 * Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
 * This returns the creation-time of the actual entity on Discords side, not inside JDA.
 *
 * @param  entity
 *         The JDA entity where the creation-time should be determined for
 *
 * @throws IllegalArgumentException
 *         If the provided entity is {@code null}
 *
 * @return The creation time of the JDA entity as OffsetDateTime
 */
public static OffsetDateTime getCreationTime(ISnowflake entity)
{
    Checks.notNull(entity, "Entity");
    return getCreationTime(entity.getIdLong());
}
项目:JDA    文件:CacheView.java   
/**
 * Creates a combined {@link net.dv8tion.jda.core.utils.cache.SnowflakeCacheView SnowflakeCacheView}
 * for all provided SnowflakeCacheView implementations.
 * <br>This allows to combine cache of multiple JDA sessions or Guilds.
 *
 * @param  cacheViews
 *         Collection of {@link net.dv8tion.jda.core.utils.cache.SnowflakeCacheView SnowflakeCacheView} implementations
 *
 * @param  <E>
 *         The target type of the chain
 *
 * @return Combined SnowflakeCacheView spanning over all provided implementation instances
 */
static <E extends ISnowflake> SnowflakeCacheView<E> allSnowflakes(Collection<SnowflakeCacheView<E>> cacheViews)
{
    Checks.noneNull(cacheViews, "Collection");
    return new UnifiedCacheViewImpl.UnifiedSnowflakeCacheView<>(cacheViews::stream);
}
项目:JDA    文件:CacheView.java   
/**
 * Creates a combined {@link net.dv8tion.jda.core.utils.cache.SnowflakeCacheView SnowflakeCacheView}
 * for all provided SnowflakeCacheView implementations.
 * <br>This allows to combine cache of multiple JDA sessions or Guilds.
 *
 * @param  generator
 *         Stream generator of {@link net.dv8tion.jda.core.utils.cache.SnowflakeCacheView SnowflakeCacheView} implementations
 *
 * @param  <E>
 *         The target type of the chain
 *
 * @return Combined SnowflakeCacheView spanning over all provided implementation instances
 */
static <E extends ISnowflake> SnowflakeCacheView<E> allSnowflakes(Supplier<Stream<SnowflakeCacheView<E>>> generator)
{
    Checks.notNull(generator, "Generator");
    return new UnifiedCacheViewImpl.UnifiedSnowflakeCacheView<>(generator);
}