Search in sources :

Example 6 with SendableMessage

use of io.discloader.discloader.entity.sendable.SendableMessage 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 7 with SendableMessage

use of io.discloader.discloader.entity.sendable.SendableMessage 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 8 with SendableMessage

use of io.discloader.discloader.entity.sendable.SendableMessage 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

SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)8 IMessage (io.discloader.discloader.entity.message.IMessage)6 MessageJSON (io.discloader.discloader.network.json.MessageJSON)6 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)6 File (java.io.File)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Attachment (io.discloader.discloader.entity.sendable.Attachment)3 BaseRequest (com.mashape.unirest.request.BaseRequest)2 HttpRequestWithBody (com.mashape.unirest.request.HttpRequestWithBody)2 MultipartBody (com.mashape.unirest.request.body.MultipartBody)2 Resource (io.discloader.discloader.client.render.util.Resource)2 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 HttpRequest (com.mashape.unirest.request.HttpRequest)1 DiscordException (io.discloader.discloader.common.exceptions.DiscordException)1 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)1 IMessageAttachment (io.discloader.discloader.entity.message.IMessageAttachment)1 JSONObject (org.json.JSONObject)1