Search in sources :

Example 1 with Channel

use of org.javacord.api.entity.channel.Channel in project Javacord by BtoBastian.

the class AudioConnectionImpl method tryConnect.

/**
 * Tries to establish a connection if all required information is available and there's not already a connection.
 *
 * @return Whether it will try to connect or not.
 */
public synchronized boolean tryConnect() {
    if (movingFuture != null && !movingFuture.isDone()) {
        movingFuture.complete(null);
        return true;
    }
    if (connectingOrConnected || sessionId == null || token == null || endpoint == null) {
        return false;
    }
    connectingOrConnected = true;
    logger.debug("Received all information required to connect to voice channel {}", getChannel());
    websocketAdapter = new AudioWebSocketAdapter(this);
    channel = channel.getCurrentCachedInstance().flatMap(Channel::asServerVoiceChannel).orElse(channel);
    return true;
}
Also used : Channel(org.javacord.api.entity.channel.Channel) ServerVoiceChannel(org.javacord.api.entity.channel.ServerVoiceChannel) AudioWebSocketAdapter(org.javacord.core.util.gateway.AudioWebSocketAdapter)

Example 2 with Channel

use of org.javacord.api.entity.channel.Channel in project Javacord by BtoBastian.

the class ThreadListSyncHandler method handle.

@Override
public void handle(final JsonNode packet) {
    final long serverId = packet.get("guild_id").asLong();
    final ServerImpl server = api.getServerById(serverId).map(ServerImpl.class::cast).orElse(null);
    if (server == null) {
        logger.warn("Unable to find server with id {}", serverId);
        return;
    }
    final List<Long> channelIds = new ArrayList<>();
    if (packet.has("channel_ids")) {
        for (final JsonNode channelId : packet.get("channel_ids")) {
            channelIds.add(channelId.asLong());
        }
    }
    final List<ServerThreadChannel> threads = new ArrayList<>();
    for (final JsonNode thread : packet.get("threads")) {
        threads.add(server.getOrCreateServerThreadChannel(thread));
    }
    final List<Long> threadIds = new ArrayList<>();
    for (final ServerThreadChannel thread : threads) {
        threadIds.add(thread.getId());
    }
    final List<ThreadMember> members = new ArrayList<>();
    for (final JsonNode member : packet.get("members")) {
        members.add(new ThreadMemberImpl(api, server, member));
    }
    // Removes lost threads from cache
    for (final Channel channel : api.getChannels()) {
        if (channel.getType() == ChannelType.SERVER_PRIVATE_THREAD || channel.getType() == ChannelType.SERVER_PUBLIC_THREAD && !threadIds.contains(channel.getId())) {
            api.removeChannelFromCache(channel.getId());
        }
    }
    final ThreadListSyncEvent event = new ThreadListSyncEventImpl(server, channelIds, threads, members);
    api.getEventDispatcher().dispatchThreadListSyncEvent(server, server, event);
}
Also used : Channel(org.javacord.api.entity.channel.Channel) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ThreadMember(org.javacord.api.entity.channel.ThreadMember) ThreadListSyncEventImpl(org.javacord.core.event.channel.thread.ThreadListSyncEventImpl) ThreadMemberImpl(org.javacord.core.entity.channel.ThreadMemberImpl) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) ThreadListSyncEvent(org.javacord.api.event.channel.thread.ThreadListSyncEvent)

Example 3 with Channel

use of org.javacord.api.entity.channel.Channel in project Javacord by BtoBastian.

the class Message method getMentionedChannels.

/**
 * Gets a list with all channels mentioned in this message.
 *
 * @return A list with all channels mentioned in this message.
 */
default List<ServerTextChannel> getMentionedChannels() {
    List<ServerTextChannel> mentionedChannels = new ArrayList<>();
    Matcher channelMention = DiscordRegexPattern.CHANNEL_MENTION.matcher(getContent());
    while (channelMention.find()) {
        String channelId = channelMention.group("id");
        getApi().getServerTextChannelById(channelId).filter(channel -> !mentionedChannels.contains(channel)).ifPresent(mentionedChannels::add);
    }
    return Collections.unmodifiableList(mentionedChannels);
}
Also used : ChannelType(org.javacord.api.entity.channel.ChannelType) Arrays(java.util.Arrays) ServerChannel(org.javacord.api.entity.channel.ServerChannel) Channel(org.javacord.api.entity.channel.Channel) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) URL(java.net.URL) GroupChannel(org.javacord.api.entity.channel.GroupChannel) CompletableFuture(java.util.concurrent.CompletableFuture) PrivateChannel(org.javacord.api.entity.channel.PrivateChannel) DiscordRegexPattern(org.javacord.api.util.DiscordRegexPattern) ArrayList(java.util.ArrayList) DiscordEntity(org.javacord.api.entity.DiscordEntity) Matcher(java.util.regex.Matcher) HighLevelComponent(org.javacord.api.entity.message.component.HighLevelComponent) Embed(org.javacord.api.entity.message.embed.Embed) StickerItem(org.javacord.api.entity.sticker.StickerItem) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) TextChannel(org.javacord.api.entity.channel.TextChannel) Emoji(org.javacord.api.entity.emoji.Emoji) UpdatableFromCache(org.javacord.api.entity.UpdatableFromCache) PermissionType(org.javacord.api.entity.permission.PermissionType) MessageAttachableListenerManager(org.javacord.api.listener.message.MessageAttachableListenerManager) MalformedURLException(java.net.MalformedURLException) Predicate(java.util.function.Predicate) Set(java.util.Set) EmbedBuilder(org.javacord.api.entity.message.embed.EmbedBuilder) CustomEmoji(org.javacord.api.entity.emoji.CustomEmoji) Instant(java.time.Instant) Javacord(org.javacord.api.Javacord) AutoArchiveDuration(org.javacord.api.entity.channel.AutoArchiveDuration) List(java.util.List) Stream(java.util.stream.Stream) User(org.javacord.api.entity.user.User) Role(org.javacord.api.entity.permission.Role) DiscordApi(org.javacord.api.DiscordApi) Server(org.javacord.api.entity.server.Server) Optional(java.util.Optional) Collections(java.util.Collections) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 4 with Channel

use of org.javacord.api.entity.channel.Channel in project Javacord by BtoBastian.

the class InviteDeleteHandler method handle.

@Override
protected void handle(JsonNode packet) {
    String code = packet.get("code").asText();
    Channel channel = api.getChannelById(packet.get("channel_id").asLong()).orElseThrow(AssertionError::new);
    channel.asServerChannel().ifPresent(serverChannel -> {
        Server server = serverChannel.getServer();
        ServerChannelInviteDeleteEvent event = new ServerChannelInviteDeleteEventImpl(code, serverChannel);
        api.getEventDispatcher().dispatchServerChannelInviteDeleteEvent((DispatchQueueSelector) server, server, event);
    });
}
Also used : Server(org.javacord.api.entity.server.Server) ServerChannelInviteDeleteEventImpl(org.javacord.core.event.channel.server.invite.ServerChannelInviteDeleteEventImpl) Channel(org.javacord.api.entity.channel.Channel) ServerChannelInviteDeleteEvent(org.javacord.api.event.channel.server.invite.ServerChannelInviteDeleteEvent)

Example 5 with Channel

use of org.javacord.api.entity.channel.Channel in project Javacord by BtoBastian.

the class ServerImpl method getChannels.

@Override
public List<ServerChannel> getChannels() {
    final List<ServerChannel> channels = getUnorderedChannels().stream().filter(channel -> channel.asCategorizable().map(categorizable -> !categorizable.getCategory().isPresent()).orElse(false)).map(Channel::asRegularServerChannel).filter(Optional::isPresent).map(Optional::get).sorted(Comparator.<RegularServerChannel>comparingInt(channel -> channel.getType().getId()).thenComparing(RegularServerChannelImpl.COMPARE_BY_RAW_POSITION)).collect(Collectors.toList());
    getChannelCategories().forEach(category -> {
        channels.add(category);
        channels.addAll(category.getChannels());
    });
    final Map<ServerTextChannel, List<ServerThreadChannel>> serverTextChannelThreads = new HashMap<>();
    getThreadChannels().forEach(serverThreadChannel -> {
        final ServerTextChannel serverTextChannel = serverThreadChannel.getParent();
        serverTextChannelThreads.merge(serverTextChannel, new ArrayList<>(Collections.singletonList(serverThreadChannel)), (serverThreadChannels, serverThreadChannels2) -> {
            serverThreadChannels.addAll(serverThreadChannels2);
            return new ArrayList<>(serverThreadChannels);
        });
    });
    serverTextChannelThreads.forEach((serverTextChannel, serverThreadChannels) -> channels.addAll(channels.indexOf(serverTextChannel) + 1, serverThreadChannels));
    return Collections.unmodifiableList(channels);
}
Also used : AudioConnection(org.javacord.api.audio.AudioConnection) RegularServerChannelImpl(org.javacord.core.entity.channel.RegularServerChannelImpl) ServerChannel(org.javacord.api.entity.channel.ServerChannel) ServerVoiceChannelImpl(org.javacord.core.entity.channel.ServerVoiceChannelImpl) IconImpl(org.javacord.core.entity.IconImpl) Member(org.javacord.core.entity.user.Member) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) URL(java.net.URL) AuditLogImpl(org.javacord.core.entity.auditlog.AuditLogImpl) RestMethod(org.javacord.core.util.rest.RestMethod) ServerStageVoiceChannelImpl(org.javacord.core.entity.channel.ServerStageVoiceChannelImpl) StickerImpl(org.javacord.core.entity.sticker.StickerImpl) Ban(org.javacord.api.entity.server.Ban) BoostLevel(org.javacord.api.entity.server.BoostLevel) RoleImpl(org.javacord.core.entity.permission.RoleImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerTextChannelImpl(org.javacord.core.entity.channel.ServerTextChannelImpl) Locale(java.util.Locale) Map(java.util.Map) RestRequest(org.javacord.core.util.rest.RestRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) VanityUrlCodeImpl(org.javacord.core.entity.VanityUrlCodeImpl) AuditLog(org.javacord.api.entity.auditlog.AuditLog) Webhook(org.javacord.api.entity.webhook.Webhook) NsfwLevel(org.javacord.api.entity.server.NsfwLevel) Activity(org.javacord.api.entity.activity.Activity) InternalServerAttachableListenerManager(org.javacord.core.listener.server.InternalServerAttachableListenerManager) InviteImpl(org.javacord.core.entity.server.invite.InviteImpl) UserImpl(org.javacord.core.entity.user.UserImpl) Collection(java.util.Collection) ChannelCategoryImpl(org.javacord.core.entity.channel.ChannelCategoryImpl) WebhookImpl(org.javacord.core.entity.webhook.WebhookImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) SlashCommand(org.javacord.api.interaction.SlashCommand) MultiFactorAuthenticationLevel(org.javacord.api.entity.server.MultiFactorAuthenticationLevel) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) VanityUrlCode(org.javacord.api.entity.VanityUrlCode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ServerVoiceChannel(org.javacord.api.entity.channel.ServerVoiceChannel) Objects(java.util.Objects) ExplicitContentFilterLevel(org.javacord.api.entity.server.ExplicitContentFilterLevel) RestEndpoint(org.javacord.core.util.rest.RestEndpoint) Sticker(org.javacord.api.entity.sticker.Sticker) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AudioConnectionImpl(org.javacord.core.audio.AudioConnectionImpl) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Role(org.javacord.api.entity.permission.Role) Optional(java.util.Optional) IncomingWebhookImpl(org.javacord.core.entity.webhook.IncomingWebhookImpl) AuditLogActionType(org.javacord.api.entity.auditlog.AuditLogActionType) ActiveThreads(org.javacord.api.entity.server.ActiveThreads) RichInvite(org.javacord.api.entity.server.invite.RichInvite) DispatchQueueSelector(org.javacord.core.util.event.DispatchQueueSelector) ChannelType(org.javacord.api.entity.channel.ChannelType) KnownCustomEmoji(org.javacord.api.entity.emoji.KnownCustomEmoji) ActivityImpl(org.javacord.core.entity.activity.ActivityImpl) ServerThreadChannelImpl(org.javacord.core.entity.channel.ServerThreadChannelImpl) Channel(org.javacord.api.entity.channel.Channel) DiscordClient(org.javacord.api.entity.DiscordClient) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IncomingWebhook(org.javacord.api.entity.webhook.IncomingWebhook) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscordEntity(org.javacord.api.entity.DiscordEntity) Region(org.javacord.api.entity.Region) Icon(org.javacord.api.entity.Icon) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) Cleanupable(org.javacord.core.util.Cleanupable) DefaultMessageNotificationLevel(org.javacord.api.entity.server.DefaultMessageNotificationLevel) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MalformedURLException(java.net.MalformedURLException) MemberImpl(org.javacord.core.entity.user.MemberImpl) DiscordApiImpl(org.javacord.core.DiscordApiImpl) AuditLogEntry(org.javacord.api.entity.auditlog.AuditLogEntry) Javacord(org.javacord.api.Javacord) Consumer(java.util.function.Consumer) LoggerUtil(org.javacord.core.util.logging.LoggerUtil) ServerFeature(org.javacord.api.entity.server.ServerFeature) ChannelCategory(org.javacord.api.entity.channel.ChannelCategory) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ServerStageVoiceChannel(org.javacord.api.entity.channel.ServerStageVoiceChannel) Intent(org.javacord.api.entity.intent.Intent) User(org.javacord.api.entity.user.User) RestRequestResult(org.javacord.core.util.rest.RestRequestResult) VerificationLevel(org.javacord.api.entity.server.VerificationLevel) UserStatus(org.javacord.api.entity.user.UserStatus) DiscordApi(org.javacord.api.DiscordApi) Server(org.javacord.api.entity.server.Server) Comparator(java.util.Comparator) Collections(java.util.Collections) RegularServerChannel(org.javacord.api.entity.channel.RegularServerChannel) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) Optional(java.util.Optional) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServerChannel(org.javacord.api.entity.channel.ServerChannel) ServerThreadChannel(org.javacord.api.entity.channel.ServerThreadChannel) ServerVoiceChannel(org.javacord.api.entity.channel.ServerVoiceChannel) Channel(org.javacord.api.entity.channel.Channel) ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) ServerStageVoiceChannel(org.javacord.api.entity.channel.ServerStageVoiceChannel) RegularServerChannel(org.javacord.api.entity.channel.RegularServerChannel) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ServerChannel(org.javacord.api.entity.channel.ServerChannel) RegularServerChannel(org.javacord.api.entity.channel.RegularServerChannel)

Aggregations

Channel (org.javacord.api.entity.channel.Channel)5 ArrayList (java.util.ArrayList)3 ServerThreadChannel (org.javacord.api.entity.channel.ServerThreadChannel)3 Server (org.javacord.api.entity.server.Server)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Instant (java.time.Instant)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 DiscordApi (org.javacord.api.DiscordApi)2 Javacord (org.javacord.api.Javacord)2 DiscordEntity (org.javacord.api.entity.DiscordEntity)2 ChannelType (org.javacord.api.entity.channel.ChannelType)2 ServerChannel (org.javacord.api.entity.channel.ServerChannel)2 ServerTextChannel (org.javacord.api.entity.channel.ServerTextChannel)2 Role (org.javacord.api.entity.permission.Role)2