use of org.javacord.core.entity.channel.PrivateChannelImpl in project Javacord by BtoBastian.
the class MessageReactionRemoveAllHandler method handle.
@Override
public void handle(JsonNode packet) {
long messageId = packet.get("message_id").asLong();
Optional<Message> message = api.getCachedMessageById(messageId);
message.ifPresent(msg -> ((MessageImpl) msg).removeAllReactionsFromCache());
long channelId = packet.get("channel_id").asLong();
TextChannel channel = api.getTextChannelById(channelId).orElse(null);
if (channel == null) {
if (packet.hasNonNull("guild_id")) {
// we don't know anything about the channel as it is part of a server and not cached
LoggerUtil.logMissingChannel(logger, channelId);
return;
}
// channel is a private channel:
channel = PrivateChannelImpl.dispatchPrivateChannelCreateEvent(api, new PrivateChannelImpl(api, channelId, null, null));
}
ReactionRemoveAllEvent event = new ReactionRemoveAllEventImpl(api, messageId, channel);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchReactionRemoveAllEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, event);
}
use of org.javacord.core.entity.channel.PrivateChannelImpl in project Javacord by BtoBastian.
the class ReadyHandler method handle.
@Override
public void handle(JsonNode packet) {
// Purge the cache first
api.purgeCache();
JsonNode guilds = packet.get("guilds");
for (JsonNode guildJson : guilds) {
if (guildJson.has("unavailable") && guildJson.get("unavailable").asBoolean()) {
api.addUnavailableServerToCache(guildJson.get("id").asLong());
continue;
}
new ServerImpl(api, guildJson);
}
// https://github.com/hammerandchisel/discord-api-docs/issues/184
if (packet.has("private_channels")) {
JsonNode privateChannels = packet.get("private_channels");
for (JsonNode channelJson : privateChannels) {
switch(ChannelType.fromId(channelJson.get("type").asInt())) {
case PRIVATE_CHANNEL:
new PrivateChannelImpl(api, channelJson);
break;
case GROUP_CHANNEL:
new GroupChannelImpl(api, channelJson);
break;
default:
logger.warn("Unknown or unexpected channel type. Your Javacord version might be out of date!");
}
}
}
api.setYourself(new UserImpl(api, packet.get("user"), (MemberImpl) null, null));
}
use of org.javacord.core.entity.channel.PrivateChannelImpl in project Javacord by BtoBastian.
the class ChannelCreateHandler method handlePrivateChannel.
/**
* Handles a private channel creation.
*
* @param channel The channel data.
*/
private void handlePrivateChannel(JsonNode channel) {
// A CHANNEL_CREATE packet was sent every time a bot account receives a message, see
// https://github.com/discord/discord-api-docs/issues/184 and
// https://github.com/discord/discord-api-docs/issues/2248
UserImpl recipient = new UserImpl(api, channel.get("recipients").get(0), (MemberImpl) null, null);
if (!recipient.getPrivateChannel().isPresent()) {
PrivateChannel privateChannel = new PrivateChannelImpl(api, channel.get("id").asText(), recipient, recipient.getId());
PrivateChannelCreateEvent event = new PrivateChannelCreateEventImpl(privateChannel);
api.getEventDispatcher().dispatchPrivateChannelCreateEvent(api, recipient, event);
}
}
use of org.javacord.core.entity.channel.PrivateChannelImpl 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);
}
}
Aggregations