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;
}
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);
}
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);
}
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);
});
}
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);
}
Aggregations