use of org.javacord.api.entity.channel.ServerChannel in project Javacord by BtoBastian.
the class MessageCreateHandler method handle.
private void handle(TextChannel channel, JsonNode packet) {
Message message = api.getOrCreateMessage(channel, packet);
MessageCreateEvent event = new MessageCreateEventImpl(message);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
MessageAuthor author = message.getAuthor();
api.getEventDispatcher().dispatchMessageCreateEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), optionalServer.orElse(null), channel, author.asUser().orElse(null), author.isWebhook() ? author.getId() : null, event);
}
use of org.javacord.api.entity.channel.ServerChannel in project Javacord by BtoBastian.
the class MessageReactionRemoveHandler method handle.
@Override
public void handle(JsonNode packet) {
long messageId = packet.get("message_id").asLong();
long userId = packet.get("user_id").asLong();
Optional<Message> message = api.getCachedMessageById(messageId);
long channelId = packet.get("channel_id").asLong();
TextChannel channel;
if (packet.hasNonNull("guild_id")) {
channel = api.getTextChannelById(channelId).orElse(null);
} else {
// if private channel:
channel = PrivateChannelImpl.getOrCreatePrivateChannel(api, channelId, userId, null);
}
if (channel == null) {
LoggerUtil.logMissingChannel(logger, channelId);
return;
}
Emoji emoji;
JsonNode emojiJson = packet.get("emoji");
if (!emojiJson.has("id") || emojiJson.get("id").isNull()) {
emoji = UnicodeEmojiImpl.fromString(emojiJson.get("name").asText());
} else {
emoji = api.getKnownCustomEmojiOrCreateCustomEmoji(emojiJson);
}
message.ifPresent(msg -> ((MessageImpl) msg).removeReaction(emoji, userId == api.getYourself().getId()));
ReactionRemoveEvent event = new ReactionRemoveEventImpl(api, messageId, channel, emoji, userId);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchReactionRemoveEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, userId, event);
}
use of org.javacord.api.entity.channel.ServerChannel in project Javacord by BtoBastian.
the class MessageDeleteBulkHandler method handle.
@Override
public void handle(JsonNode packet) {
long channelId = Long.parseLong(packet.get("channel_id").asText());
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
TextChannel channel = optionalChannel.get();
for (JsonNode messageIdJson : packet.get("ids")) {
long messageId = messageIdJson.asLong();
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);
}
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
use of org.javacord.api.entity.channel.ServerChannel 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.api.entity.channel.ServerChannel in project Javacord by BtoBastian.
the class InviteCreateHandler method handle.
@Override
protected void handle(JsonNode packet) {
InviteImpl invite = new InviteImpl(api, packet);
invite.getServer().ifPresent(server -> {
// An error here means a missing channel for the invite, which should have already thrown an error
ServerChannel channel = invite.getChannel().orElseThrow(AssertionError::new);
ServerChannelInviteCreateEvent event = new ServerChannelInviteCreateEventImpl(invite, channel);
api.getEventDispatcher().dispatchServerChannelInviteCreateEvent((DispatchQueueSelector) server, server, event);
});
}
Aggregations