use of org.javacord.api.entity.channel.TextChannel in project Javacord by BtoBastian.
the class MessageCreateHandler method handle.
@Override
public void handle(JsonNode packet) {
long channelId = packet.get("channel_id").asLong();
// See https://github.com/discord/discord-api-docs/issues/2248
if (!packet.hasNonNull("guild_id")) {
// Check for EPHEMERAL messages as they do NOT include a guild_id when the EPHEMERAL flag is set.
if (packet.hasNonNull("flags") && (packet.get("flags").asInt() & MessageFlag.EPHEMERAL.getId()) > 0) {
Optional<ServerTextChannel> serverTextChannel = api.getServerTextChannelById(channelId);
if (serverTextChannel.isPresent()) {
handle(serverTextChannel.get(), packet);
return;
}
Optional<ServerThreadChannel> serverThreadChannel = api.getServerThreadChannelById(channelId);
if (serverThreadChannel.isPresent()) {
handle(serverThreadChannel.get(), packet);
return;
}
}
UserImpl author = new UserImpl(api, packet.get("author"), (MemberImpl) null, null);
PrivateChannelImpl privateChannel = PrivateChannelImpl.getOrCreatePrivateChannel(api, channelId, author.getId(), author);
handle(privateChannel, packet);
return;
}
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
handle(optionalChannel.get(), packet);
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
use of org.javacord.api.entity.channel.TextChannel in project Javacord by BtoBastian.
the class MessageDeleteHandler method handle.
@Override
public void handle(JsonNode packet) {
long messageId = packet.get("id").asLong();
long channelId = packet.get("channel_id").asLong();
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
TextChannel channel = optionalChannel.get();
MessageDeleteEvent event = new MessageDeleteEventImpl(api, messageId, channel);
api.getCachedMessageById(messageId).ifPresent(((MessageCacheImpl) channel.getMessageCache())::removeMessage);
api.removeMessageFromCache(messageId);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchMessageDeleteEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, event);
api.removeObjectListeners(Message.class, messageId);
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
Aggregations