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

项目:JDA    文件:GuildRoleCreateHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    final long guildId = content.getLong("guild_id");
    if (api.getGuildLock().isLocked(guildId))
    {
        return guildId;
    }

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(guildId);
    if (guild == null)
    {
        api.getEventCache().cache(EventCache.Type.GUILD, guildId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("GUILD_ROLE_CREATE was received for a Guild that is not yet cached: {}", content);
        return null;
    }

    Role newRole = api.getEntityBuilder().createRole(content.getJSONObject("role"), guild.getIdLong());
    api.getEventManager().handle(
            new RoleCreateEvent(
                    api, responseNumber,
                    newRole));
    api.getEventCache().playbackCache(EventCache.Type.ROLE, newRole.getIdLong());
    return null;
}
项目:JDA    文件:GuildMemberAddHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    final long id = content.getLong("guild_id");
    if (api.getGuildLock().isLocked(id))
        return id;

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(id);
    if (guild == null)
    {
        api.getEventCache().cache(EventCache.Type.GUILD, id, () ->
        {
            handle(responseNumber, allContent);
        });
        return null;
    }

    Member member = api.getEntityBuilder().createMember(guild, content);
    api.getEventManager().handle(
            new GuildMemberJoinEvent(
                    api, responseNumber,
                    guild, member));
    api.getEventCache().playbackCache(EventCache.Type.USER, member.getUser().getIdLong());
    return null;
}
项目:JDA    文件:GuildSyncHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    final long guildId = content.getLong("id");
    if (!api.getGuildMap().containsKey(guildId))
    {
        JDAImpl.LOG.error("Received a GUILD_SYNC for a Guild that does not yet exist in JDA's guild cache. This is a BAD ERROR FOR CLIENTS!");
        return null;
    }

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(guildId);
    JSONArray members = content.getJSONArray("members");
    JSONArray presences = content.getJSONArray("presences");
    api.getEntityBuilder().handleGuildSync(guild, members, presences);

    return null;
}
项目:JDA    文件:GuildMemberUpdateHandler.java   
private List<Role> toRolesList(GuildImpl guild, JSONArray array)
{
    LinkedList<Role> roles = new LinkedList<>();
    for(int i = 0; i < array.length(); i++)
    {
        final long id = array.getLong(i);
        Role r = guild.getRolesMap().get(id);
        if (r != null)
        {
            roles.add(r);
        }
        else
        {
            api.getEventCache().cache(EventCache.Type.ROLE, id, () ->
            {
                handle(responseNumber, allContent);
            });
            EventCache.LOG.debug("Got GuildMember update but one of the Roles for the Member is not yet cached.");
            return null;
        }
    }
    return roles;
}
项目:JDA    文件:AuditLogEntry.java   
public AuditLogEntry(ActionType type, long id, long targetId, GuildImpl guild, UserImpl user, String reason,
                     Map<String, AuditLogChange> changes, Map<String, Object> options)
{
    this.type = type;
    this.id = id;
    this.targetId = targetId;
    this.guild = guild;
    this.user = user;
    this.reason = reason;
    this.changes = changes != null && !changes.isEmpty()
            ? Collections.unmodifiableMap(changes)
            : Collections.emptyMap();
    this.options = options != null && !options.isEmpty()
            ? Collections.unmodifiableMap(options)
            : Collections.emptyMap();
}
项目:GiveawayBot    文件:RestJDA.java   
@CheckReturnValue
public MessageAction editMessage(long channelId, long messageId, Message newContent)
{
    Checks.notNull(newContent, "message");
    Route.CompiledRoute route = Route.Messages.EDIT_MESSAGE.compile(Long.toString(channelId), Long.toString(messageId));
    return new MessageAction(fakeJDA, route, new TextChannelImpl(channelId, new GuildImpl(fakeJDA, 0))).apply(newContent);
}
项目:GiveawayBot    文件:RestJDA.java   
@CheckReturnValue
public MessageAction sendMessage(long channelId, Message msg)
{
    Checks.notNull(msg, "Message");
    Route.CompiledRoute route = Route.Messages.SEND_MESSAGE.compile(Long.toString(channelId));
    return new MessageAction(fakeJDA, route, new TextChannelImpl(channelId, new GuildImpl(fakeJDA, 0))).apply(msg);
}
项目:JDA    文件:GuildRoleDeleteHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    final long guildId = content.getLong("guild_id");
    if (api.getGuildLock().isLocked(guildId))
        return guildId;

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(guildId);
    if (guild == null)
    {
        api.getEventCache().cache(EventCache.Type.GUILD, guildId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("GUILD_ROLE_DELETE was received for a Guild that is not yet cached: {}", content);
        return null;
    }

    final long roleId = content.getLong("role_id");
    Role removedRole = guild.getRolesMap().remove(roleId);
    if (removedRole == null)
    {
        api.getEventCache().cache(EventCache.Type.ROLE, roleId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("GUILD_ROLE_DELETE was received for a Role that is not yet cached: {}", content);
        return null;
    }

    //Now that the role is removed from the Guild, remove it from all users.
    for (Member m : guild.getMembersMap().valueCollection())
    {
        MemberImpl member = (MemberImpl) m;
        member.getRoleSet().remove(removedRole);
    }
    api.getEventManager().handle(
            new RoleDeleteEvent(
                    api, responseNumber,
                    removedRole));
    api.getEventCache().clear(EventCache.Type.ROLE, roleId);
    return null;
}
项目:JDA    文件:GuildBanHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    final long id = content.getLong("guild_id");
    if (api.getGuildLock().isLocked(id))
        return id;

    JSONObject userJson = content.getJSONObject("user");
    GuildImpl guild = (GuildImpl) api.getGuildMap().get(id);
    if (guild == null)
    {
        api.getEventCache().cache(EventCache.Type.GUILD, id, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", JDALogger.getLazyString(() -> banned ? "Ban" : "Unban"));
        return null;
    }

    User user = api.getEntityBuilder().createFakeUser(userJson, false);

    if (banned)
    {
        api.getEventManager().handle(
                new GuildBanEvent(
                        api, responseNumber,
                        guild, user));
    }
    else
    {
        api.getEventManager().handle(
                new GuildUnbanEvent(
                        api, responseNumber,
                        guild, user));
    }
    return null;
}
项目: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    文件:AudioManagerImpl.java   
public AudioManagerImpl(GuildImpl guild)
{
    this.guild = guild;
    this.api = this.guild.getJDA();
    init(); //Just to make sure that the audio libs have been initialized.
}
项目:JDA    文件:PermissionUtil.java   
/**
     * Checks to see if the {@link net.dv8tion.jda.core.entities.Member Member} has the specified {@link net.dv8tion.jda.core.Permission Permissions}
     * in the specified {@link net.dv8tion.jda.core.entities.Channel Channel}. This method properly deals with
     * {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides} and Owner status.
     *
     * <p><b>Note:</b> this is based on effective permissions, not literal permissions. If a member has permissions that would
     * enable them to do something without the literal permission to do it, this will still return true.
     * <br>Example: If a member has the {@link net.dv8tion.jda.core.Permission#ADMINISTRATOR} permission, they will be able to
     * {@link net.dv8tion.jda.core.Permission#MESSAGE_WRITE} in every channel.
     *
     * @param  member
     *         The {@link net.dv8tion.jda.core.entities.Member Member} whose permissions are being checked.
     * @param  channel
     *         The {@link net.dv8tion.jda.core.entities.Channel Channel} being checked.
     * @param  permissions
     *         The {@link net.dv8tion.jda.core.Permission Permissions} being checked for.
     *
     * @throws IllegalArgumentException
     *         if any of the provided parameters is {@code null}
     *         or the provided entities are not from the same guild
     *
     * @return True -
     *         if the {@link net.dv8tion.jda.core.entities.Member Member} effectively has the specified {@link net.dv8tion.jda.core.Permission Permissions}.
     */
    public static boolean checkPermission(Channel channel, Member member, Permission... permissions)
    {
        Checks.notNull(channel, "Channel");
        Checks.notNull(member, "Member");
        Checks.notNull(permissions, "Permissions");

        GuildImpl guild = (GuildImpl) channel.getGuild();
        checkGuild(guild, member.getGuild(), "Member");

//        if (guild.getOwner().equals(member) // Admin or owner? If yes: no need to iterate
//                || guild.getPublicRole().hasPermission(Permission.ADMINISTRATOR)
//                || member.getRoles().stream().anyMatch(role -> role.hasPermission(Permission.ADMINISTRATOR)))
//            return true; // can be removed as getEffectivePermissions calculates these cases in

        long effectivePerms = getEffectivePermission(channel, member);
        return isApplied(effectivePerms, Permission.ADMINISTRATOR.getRawValue())
                || isApplied(effectivePerms, Permission.getRaw(permissions));
    }
项目:JDA    文件:WebSocketClient.java   
protected void updateAudioManagerReferences()
{
    final TLongObjectMap<AudioManager> managerMap = api.getAudioManagerMap();
    if (managerMap.size() > 0)
        LOG.trace("Updating AudioManager references");

    synchronized (managerMap)
    {
        for (TLongObjectIterator<AudioManager> it = managerMap.iterator(); it.hasNext(); )
        {
            it.advance();
            final long guildId = it.key();
            final AudioManagerImpl mng = (AudioManagerImpl) it.value();
            ConnectionListener listener = mng.getConnectionListener();

            GuildImpl guild = (GuildImpl) api.getGuildById(guildId);
            if (guild == null)
            {
                //We no longer have access to the guild that this audio manager was for. Set the value to null.
                queuedAudioConnections.remove(guildId);
                if (listener != null)
                    listener.onStatusChange(ConnectionStatus.DISCONNECTED_REMOVED_FROM_GUILD);
                it.remove();
            }
            else
            {
                final AudioManagerImpl newMng = new AudioManagerImpl(guild);
                newMng.setSelfMuted(mng.isSelfMuted());
                newMng.setSelfDeafened(mng.isSelfDeafened());
                newMng.setQueueTimeout(mng.getConnectTimeout());
                newMng.setSendingHandler(mng.getSendingHandler());
                newMng.setReceivingHandler(mng.getReceiveHandler());
                newMng.setConnectionListener(listener);
                newMng.setAutoReconnect(mng.isAutoReconnect());

                if (mng.isConnected() || mng.isAttemptingToConnect())
                {
                    final long channelId = mng.isConnected()
                        ? mng.getConnectedChannel().getIdLong()
                        : mng.getQueuedAudioConnection().getIdLong();

                    final VoiceChannel channel = api.getVoiceChannelById(channelId);
                    if (channel != null)
                    {
                        if (mng.isConnected())
                            mng.closeAudioConnection(ConnectionStatus.ERROR_CANNOT_RESUME);
                        //closing old connection in order to reconnect later
                        newMng.setQueuedAudioConnection(channel);
                    }
                    else
                    {
                        //The voice channel is not cached. It was probably deleted.
                        queuedAudioConnections.remove(guildId);
                        if (listener != null)
                            listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
                    }
                }
                it.setValue(newMng);
            }
        }
    }
}
项目:JDA    文件:GuildController.java   
/**
 * Creates a new GuildController instance
 * for the specified Guild instance
 *
 * @param guild
 *        The {@link net.dv8tion.jda.core.entities.Guild Guild}
 *        that will be modified
 */
public GuildController(Guild guild)
{
    this.guild = (GuildImpl) guild;
}