Search in sources :

Example 1 with Attachment

use of io.discloader.discloader.entity.sendable.Attachment in project DiscLoader by R3alCl0ud.

the class PrivateChannel method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file) {
    Attachment attachment = null;
    if (file != null)
        attachment = new Attachment(file.getName());
    if (embed != null && embed.getThumbnail() != null && embed.getThumbnail().file != null) {
        file = embed.getThumbnail().file;
        embed.getThumbnail().file = null;
        attachment = new Attachment(file.getName());
    }
    return new SendMessage<IPrivateChannel>(this, content, embed, attachment, file).execute();
}
Also used : IPrivateChannel(io.discloader.discloader.entity.channel.IPrivateChannel) Attachment(io.discloader.discloader.entity.sendable.Attachment)

Example 2 with Attachment

use of io.discloader.discloader.entity.sendable.Attachment in project DiscLoader by R3alCl0ud.

the class Message method edit.

/**
 * Edit's the messages content. Only possible if the {@link DiscLoader loader}
 * is the message's {@link #author}
 *
 * @param content
 *            The new content of the message
 * @param embed
 *            The new embed for the message
 * @return A Future that completes with {@literal this} when sucessfull
 */
@Override
public CompletableFuture<IMessage> edit(String content, RichEmbed embed) {
    CompletableFuture<IMessage> future = new CompletableFuture<>();
    if (!canEdit()) {
        future.completeExceptionally(new PermissionsException("Only messages author by you can be editted"));
        return future;
    }
    SendableMessage sendable = null;
    Attachment attachment = null;
    File file = null;
    if (embed != null) {
        if ((embed.getThumbnail() != null && embed.getThumbnail().resource != null)) {
            attachment = new Attachment(embed.getThumbnail().resource.getName());
        }
        if (embed.getThumbnail() != null && embed.getThumbnail().file != null) {
            attachment = new Attachment(embed.getThumbnail().file.getName());
        }
        if ((embed.getImage() != null && embed.getImage().resource != null)) {
            attachment = new Attachment(embed.getImage().resource.getName());
        }
        if (embed.getImage() != null && embed.getImage().file != null) {
            attachment = new Attachment(embed.getImage().file.getName());
        }
    }
    sendable = new SendableMessage(content, false, embed, attachment, file);
    CompletableFuture<MessageJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.message(getChannel().getID(), getID()), new RESTOptions(sendable), MessageJSON.class);
    cf.thenAcceptAsync(messageJSON -> {
        future.complete(EntityBuilder.getChannelFactory().buildMessage(channel, messageJSON));
    });
    cf.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) IMessageAttachment(io.discloader.discloader.entity.message.IMessageAttachment) File(java.io.File) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 3 with Attachment

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

use of io.discloader.discloader.entity.sendable.Attachment in project DiscLoader by R3alCl0ud.

the class GroupChannel method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file) {
    Attachment attachment = null;
    if (embed != null && embed.getThumbnail() != null && embed.getThumbnail().file != null) {
        file = embed.getThumbnail().file;
        embed.getThumbnail().file = null;
        attachment = new Attachment(file.getName());
    }
    return new SendMessage<IGroupChannel>(this, content, embed, attachment, file).execute();
}
Also used : IGroupChannel(io.discloader.discloader.entity.channel.IGroupChannel) Attachment(io.discloader.discloader.entity.sendable.Attachment)

Example 5 with Attachment

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

Attachment (io.discloader.discloader.entity.sendable.Attachment)5 IMessage (io.discloader.discloader.entity.message.IMessage)3 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)3 MessageJSON (io.discloader.discloader.network.json.MessageJSON)3 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)1 IGroupChannel (io.discloader.discloader.entity.channel.IGroupChannel)1 IPrivateChannel (io.discloader.discloader.entity.channel.IPrivateChannel)1 IMessageAttachment (io.discloader.discloader.entity.message.IMessageAttachment)1 File (java.io.File)1