use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class MessageCreate method handle.
@Override
public void handle(SocketPacket packet) {
MessageJSON data = this.gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
try {
long channelID = SnowflakeUtil.parse(data.channel_id);
ITextChannel channel = EntityRegistry.getTextChannelByID(channelID);
if (channel == null)
channel = EntityRegistry.getPrivateChannelByID(channelID);
if (channel == null)
channel = EntityRegistry.getGroupChannelByID(channelID);
if (channel == null)
return;
IMessage message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
channel.getMessages().put(message.getID(), message);
if (channel.isTyping(message.getAuthor())) {
channel.getTyping().remove(message.getAuthor().getID());
}
MessageCreateEvent event = new MessageCreateEvent(message);
loader.emit(event);
if (channel.getType() == ChannelTypes.TEXT) {
loader.emit(event = new GuildMessageCreateEvent(message));
} else if (channel.getType() == ChannelTypes.DM) {
loader.emit(event = new PrivateMessageCreateEvent(message));
} else if (channel.getType() == ChannelTypes.GROUP) {
loader.emit(event = new GroupMessageCreateEvent(message));
}
CommandHandler.handleMessageCreate(event);
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class MessageUpdate method handle.
@Override
public void handle(SocketPacket packet) {
MessageJSON data = gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
if (channel == null)
channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
if (channel == null)
channel = EntityRegistry.getGroupChannelByID(data.channel_id);
if (channel == null)
return;
IMessage oldMessage = channel.getMessage(data.id), message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
MessageUpdateEvent event = new MessageUpdateEvent(message, oldMessage);
loader.emit(event);
if (message.getGuild() != null) {
loader.emit(new GuildMessageUpdateEvent(message, oldMessage));
} else if (channel.getType() == ChannelTypes.DM) {
loader.emit(new PrivateMessageUpdateEvent(message, oldMessage));
} else if (channel.getType() == ChannelTypes.GROUP) {
loader.emit(new GroupMessageUpdateEvent(message, oldMessage));
}
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class PinnedMessages method complete.
@Override
public void complete(String s, Throwable ex) {
if (ex != null) {
future.completeExceptionally(ex);
return;
} else {
MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
HashMap<Long, IMessage> messages = new HashMap<>();
for (MessageJSON m : data) {
IMessage message = new Message<T>(channel, m);
channel.getMessages().put(message.getID(), message);
messages.put(message.getID(), message);
}
future.complete(messages);
}
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class FetchMessages method complete.
@Override
public void complete(String s, Throwable ex) {
if (ex != null) {
future.completeExceptionally(ex);
return;
} else {
MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
HashMap<Long, IMessage> messages = new HashMap<>();
for (MessageJSON m : data) {
IMessage message = new Message<>(channel, m);
channel.getMessages().put(message.getID(), message);
messages.put(message.getID(), message);
}
future.complete(messages);
}
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class TextChannel method sendMessage.
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file) {
Attachment attachment = file == null ? null : new Attachment(file.getName());
SendableMessage sendable = new SendableMessage(content, false, embed, attachment, file);
CompletableFuture<IMessage> future = new CompletableFuture<>();
CompletableFuture<MessageJSON> mcf = loader.rest.request(Methods.POST, Endpoints.messages(getID()), new RESTOptions(sendable), MessageJSON.class);
mcf.thenAcceptAsync(e -> {
future.complete(new Message<>(this, e));
});
mcf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Aggregations