Search in sources :

Example 31 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) MessageJSON(io.discloader.discloader.network.json.MessageJSON) SendableMessage(io.discloader.discloader.entity.sendable.SendableMessage) IMessage(io.discloader.discloader.entity.message.IMessage) Attachment(io.discloader.discloader.entity.sendable.Attachment)

Example 32 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) MessageJSON(io.discloader.discloader.network.json.MessageJSON) SendableMessage(io.discloader.discloader.entity.sendable.SendableMessage) IMessage(io.discloader.discloader.entity.message.IMessage) File(java.io.File)

Example 33 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) MessageJSON(io.discloader.discloader.network.json.MessageJSON) SendableMessage(io.discloader.discloader.entity.sendable.SendableMessage) IMessage(io.discloader.discloader.entity.message.IMessage) File(java.io.File)

Example 34 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) MessageJSON(io.discloader.discloader.network.json.MessageJSON) SendableMessage(io.discloader.discloader.entity.sendable.SendableMessage) IMessage(io.discloader.discloader.entity.message.IMessage) Attachment(io.discloader.discloader.entity.sendable.Attachment)

Aggregations

IMessage (io.discloader.discloader.entity.message.IMessage)34 MessageJSON (io.discloader.discloader.network.json.MessageJSON)21 CompletableFuture (java.util.concurrent.CompletableFuture)20 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)17 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)15 File (java.io.File)10 Attachment (io.discloader.discloader.entity.sendable.Attachment)9 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)6 RichEmbed (io.discloader.discloader.core.entity.message.embed.RichEmbed)4 Message (io.discloader.discloader.core.entity.message.Message)3 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)3 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)2 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)2 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)2 IPrivateChannel (io.discloader.discloader.entity.channel.IPrivateChannel)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 IUser (io.discloader.discloader.entity.user.IUser)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 HashMap (java.util.HashMap)2