use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class GroupChannel method sendMessage.
/*
* (non-Javadoc)
*
* @see io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.
* lang.String, io.discloader.discloader.core.entity.RichEmbed,
* io.discloader.discloader.entity.sendable.Attachment)
*/
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Attachment attachment) {
SendableMessage sendable = new SendableMessage(content, false, embed, attachment, new File(attachment.filename));
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;
}
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, Attachment attachment) {
File file = attachment == null ? null : new File(attachment.filename);
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;
}
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, Resource resource) {
Attachment attachment = resource == null ? null : new Attachment(resource.getFileName());
SendableMessage sendable = new SendableMessage(content, false, embed, attachment, resource);
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;
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class PrivateChannel method sendMessage.
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Attachment attachment, boolean tts) {
CompletableFuture<IMessage> future = new CompletableFuture<>();
File file = attachment == null ? null : new File(attachment.filename);
SendableMessage sendable = new SendableMessage(content, tts, embed, attachment, file);
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;
}
use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.
the class MessageDelete method handle.
@Override
public void handle(SocketPacket packet) {
MessageJSON data = this.gson.fromJson(this.gson.toJson(packet.d), MessageJSON.class);
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(data.channel_id);
if (channel == null)
return;
IMessage message = channel.getMessage(data.id);
if (message == null)
return;
channel.getMessages().remove(message.getID());
MessageDeleteEvent event = new MessageDeleteEvent(message);
loader.emit(event);
if (channel.getType() == ChannelTypes.DM) {
loader.emit(new PrivateMessageDeleteEvent(message));
} else if (channel.getType() == ChannelTypes.GROUP) {
loader.emit(new GroupMessageDeleteEvent(message));
}
if (message.getGuild() != null) {
loader.emit(new GuildMessageDeleteEvent(message));
}
}
Aggregations