net.dv8tion.jda.api.entities.GuildChannel Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.GuildChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuditActionBuilder.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
private Object getReferenceForObject(Object object) {
    if (object instanceof User) {
        return getReference((User) object);
    }
    if (object instanceof LocalUser) {
        return getReference((LocalUser) object);
    }
    if (object instanceof Member) {
        return getReference((Member) object);
    }
    if (object instanceof LocalMember) {
        return getReference((LocalMember) object);
    }
    if (object instanceof GuildChannel) {
        return getReference((GuildChannel) object);
    }
    return object;
}
 
Example #2
Source File: ChannelOrderActionImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Override
protected RequestBody finalizeData()
{
    final Member self = guild.getSelfMember();
    if (!self.hasPermission(Permission.MANAGE_CHANNEL))
        throw new InsufficientPermissionException(guild, Permission.MANAGE_CHANNEL);
    DataArray array = DataArray.empty();
    for (int i = 0; i < orderList.size(); i++)
    {
        GuildChannel chan = orderList.get(i);
        array.add(DataObject.empty()
                .put("id", chan.getId())
                .put("position", i));
    }

    return getRequestBody(array);
}
 
Example #3
Source File: ChannelOrderActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
protected static Collection<GuildChannel> getChannelsOfType(Guild guild, int bucket)
{
    return guild.getChannels().stream()
        .filter(it -> it.getType().getSortBucket() == bucket)
        .sorted()
        .collect(Collectors.toList());
}
 
Example #4
Source File: CategoryOrderActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Collection<GuildChannel> getChannelsOfType(Category category, int bucket)
{
    Checks.notNull(category, "Category");
    return ChannelOrderActionImpl.getChannelsOfType(category.getGuild(), bucket).stream()
         .filter(it -> category.equals(it.getParent()))
         .sorted()
         .collect(Collectors.toList());
}
 
Example #5
Source File: CategoryOrderActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected void validateInput(GuildChannel entity)
{
    Checks.notNull(entity, "Provided channel");
    Checks.check(getCategory().equals(entity.getParent()), "Provided channel's Category is not this Category!");
    Checks.check(orderList.contains(entity), "Provided channel is not in the list of orderable channels!");
}
 
Example #6
Source File: RoleImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasPermission(@Nonnull GuildChannel channel, @Nonnull Collection<Permission> permissions)
{
    Checks.notNull(permissions, "Permission Collection");

    return hasPermission(channel, permissions.toArray(Permission.EMPTY_PERMISSIONS));
}
 
Example #7
Source File: RoleImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasPermission(@Nonnull GuildChannel channel, @Nonnull Permission... permissions)
{
    long effectivePerms = PermissionUtil.getEffectivePermission(channel, this);
    for (Permission perm : permissions)
    {
        final long rawValue = perm.getRawValue();
        if ((effectivePerms & rawValue) != rawValue)
            return false;
    }
    return true;
}
 
Example #8
Source File: InviteDeleteHandler.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild guild = getJDA().getGuildById(guildId);
    if (guild == null)
    {
        EventCache.LOG.debug("Caching INVITE_DELETE for unknown guild {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }
    long channelId = content.getUnsignedLong("channel_id");
    GuildChannel channel = guild.getGuildChannelById(channelId);
    if (channel == null)
    {
        EventCache.LOG.debug("Caching INVITE_DELETE for unknown channel {} in guild {}", channelId, guildId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }

    String code = content.getString("code");
    getJDA().handleEvent(
        new GuildInviteDeleteEvent(
            getJDA(), responseNumber,
            code, channel));
    return null;
}
 
Example #9
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 5 votes vote down vote up
private InsufficientPermissionException(@Nonnull Guild guild, @Nullable GuildChannel channel, @Nonnull Permission permission)
{
    super(permission, "Cannot perform action due to a lack of Permission. Missing permission: " + permission.toString());
    this.guildId = guild.getIdLong();
    this.channelId = channel == null ? 0 : channel.getIdLong();
    this.channelType = channel == null ? ChannelType.UNKNOWN : channel.getType();
}
 
Example #10
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 5 votes vote down vote up
private InsufficientPermissionException(@Nonnull Guild guild, @Nullable GuildChannel channel, @Nonnull Permission permission, @Nonnull String reason)
{
    super(permission, reason);
    this.guildId = guild.getIdLong();
    this.channelId = channel == null ? 0 : channel.getIdLong();
    this.channelType = channel == null ? ChannelType.UNKNOWN : channel.getType();
}
 
Example #11
Source File: RoleImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public EnumSet<Permission> getPermissions(@Nonnull GuildChannel channel)
{
    return Permission.getPermissions(PermissionUtil.getEffectivePermission(channel, this));
}
 
Example #12
Source File: AuditActionBuilder.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public AuditActionBuilder withChannel(GuildChannel channel) {
    this.action.setChannel(getReference(channel));
    return this;
}
 
Example #13
Source File: ChannelOrderActionImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected void validateInput(GuildChannel entity)
{
    Checks.check(entity.getGuild().equals(guild), "Provided channel is not from this Guild!");
    Checks.check(orderList.contains(entity), "Provided channel is not in the list of orderable channels!");
}
 
Example #14
Source File: AuditActionBuilder.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
private NamedReference getReference(GuildChannel channel) {
    return channel != null ? new NamedReference(channel.getId(), channel.getName()) : null;
}
 
Example #15
Source File: ChannelOrderActionImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new ChannelOrderAction instance using the provided
 * {@link net.dv8tion.jda.api.entities.Guild Guild}, as well as the provided
 * list of {@link net.dv8tion.jda.api.entities.GuildChannel Channels}.
 *
 * @param  guild
 *         The target {@link net.dv8tion.jda.api.entities.Guild Guild}
 *         of which to order the channels defined by the specified type
 * @param  bucket
 *         The sorting bucket
 * @param  channels
 *         The {@link net.dv8tion.jda.api.entities.GuildChannel Channels} to order, all of which
 *         are on the same Guild specified, and all of which are of the same generic type of GuildChannel
 *         corresponding to the the ChannelType specified.
 *
 * @throws java.lang.IllegalArgumentException
 *         If the channels are {@code null}, an empty collection,
 *         or any of them do not have the same ChannelType as the one
 *         provided.
 */
public ChannelOrderActionImpl(Guild guild, int bucket, Collection<? extends GuildChannel> channels)
{
    super(guild.getJDA(), Route.Guilds.MODIFY_CHANNELS.compile(guild.getId()));

    Checks.notNull(channels, "Channels to order");
    Checks.notEmpty(channels, "Channels to order");
    Checks.check(channels.stream().allMatch(c -> guild.equals(c.getGuild())),
        "One or more channels are not from the correct guild");
    Checks.check(channels.stream().allMatch(c -> c.getType().getSortBucket() == bucket),
        "One or more channels did not match the expected bucket " + bucket);

    this.guild = guild;
    this.bucket = bucket;
    this.orderList.addAll(channels);
}
 
Example #16
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 4 votes vote down vote up
public InsufficientPermissionException(@Nonnull GuildChannel channel, @Nonnull Permission permission)
{
    this(channel.getGuild(), channel, permission);
}
 
Example #17
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 4 votes vote down vote up
public InsufficientPermissionException(@Nonnull GuildChannel channel, @Nonnull Permission permission, @Nonnull String reason)
{
    this(channel.getGuild(), channel, permission, reason);
}
 
Example #18
Source File: RoleImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public EnumSet<Permission> getPermissionsExplicit(@Nonnull GuildChannel channel)
{
    return Permission.getPermissions(PermissionUtil.getExplicitPermission(channel, this));
}
 
Example #19
Source File: InviteCreateHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild realGuild = getJDA().getGuildById(guildId);
    if (realGuild == null)
    {
        EventCache.LOG.debug("Caching INVITE_CREATE for unknown guild with id {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }

    long channelId = content.getUnsignedLong("channel_id");
    GuildChannel realChannel = realGuild.getGuildChannelById(channelId);
    if (realChannel == null)
    {
        EventCache.LOG.debug("Caching INVITE_CREATE for unknown channel with id {} in guild with id {}", channelId, guildId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }

    String code = content.getString("code");
    boolean temporary = content.getBoolean("temporary");
    int maxAge = content.getInt("max_age", -1);
    int maxUses = content.getInt("max_uses", -1);
    OffsetDateTime creationTime = content.opt("created_at")
            .map(String::valueOf)
            .map(OffsetDateTime::parse)
            .orElse(null);

    Optional<DataObject> inviterJson = content.optObject("inviter");
    boolean expanded = maxUses != -1;

    User inviter = inviterJson.map(json -> getJDA().getEntityBuilder().createFakeUser(json)).orElse(null);
    InviteImpl.ChannelImpl channel = new InviteImpl.ChannelImpl(realChannel);
    InviteImpl.GuildImpl guild = new InviteImpl.GuildImpl(realGuild);

    Invite invite = new InviteImpl(getJDA(), code, expanded, inviter, maxAge, maxUses, temporary, creationTime, 0, channel, guild, null, Invite.InviteType.GUILD);
    getJDA().handleEvent(
        new GuildInviteCreateEvent(
            getJDA(), responseNumber,
            invite, realChannel));
    return null;
}
 
Example #20
Source File: GuildInviteCreateEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public GuildInviteCreateEvent(@Nonnull JDA api, long responseNumber, @Nonnull Invite invite, @Nonnull GuildChannel channel)
{
    super(api, responseNumber, invite.getCode(), channel);
    this.invite = invite;
}
 
Example #21
Source File: GuildInviteDeleteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public GuildInviteDeleteEvent(@Nonnull JDA api, long responseNumber, @Nonnull String code, @Nonnull GuildChannel channel)
{
    super(api, responseNumber, code, channel);
}
 
Example #22
Source File: PermissionOverrideCreateEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public PermissionOverrideCreateEvent(@Nonnull JDA api, long responseNumber, @Nonnull GuildChannel channel, @Nonnull PermissionOverride override)
{
    super(api, responseNumber, channel, override);
}
 
Example #23
Source File: PermissionOverrideDeleteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public PermissionOverrideDeleteEvent(@Nonnull JDA api, long responseNumber, @Nonnull GuildChannel channel, @Nonnull PermissionOverride override)
{
    super(api, responseNumber, channel, override);
}
 
Example #24
Source File: PermissionOverrideUpdateEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public PermissionOverrideUpdateEvent(@Nonnull JDA api, long responseNumber, @Nonnull GuildChannel channel, @Nonnull PermissionOverride override, long oldAllow, long oldDeny)
{
    super(api, responseNumber, channel, override);
    this.oldAllow = oldAllow;
    this.oldDeny = oldDeny;
}
 
Example #25
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * The {@link net.dv8tion.jda.api.entities.GuildChannel} instance for the {@link #getChannelId() channel id}.
 *
 * @param  api
 *         The shard to perform the lookup in
 *
 * @throws java.lang.IllegalArgumentException
 *         If the provided JDA instance is null
 *
 * @since  4.0.0
 *
 * @return The GuildChannel instance or null
 */
@Nullable
public GuildChannel getChannel(@Nonnull JDA api)
{
    Checks.notNull(api, "JDA");
    return api.getGuildChannelById(channelType, channelId);
}
 
Example #26
Source File: PermOverrideManager.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} this Manager's
 * {@link net.dv8tion.jda.api.entities.PermissionOverride PermissionOverride} is in.
 * <br>This is logically the same as calling {@code getPermissionOverride().getChannel()}
 *
 * @return The parent {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel}
 */
@Nonnull
default GuildChannel getChannel()
{
    return getPermissionOverride().getChannel();
}
 
Example #27
Source File: AbstractChannel.java    From Arraybot with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new abstract channel.
 * @param underlying The underlying channel.
 */
protected AbstractChannel(GuildChannel underlying) {
    this.underlying = underlying;
}