Search in sources :

Example 6 with MessageJSON

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, boolean tts) {
    Attachment attachment = file == null ? null : new Attachment(file.getName());
    SendableMessage sendable = new SendableMessage(content, tts, 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 7 with MessageJSON

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, boolean tts) {
    Attachment attachment = resource == null ? null : new Attachment(resource.getFileName());
    SendableMessage sendable = new SendableMessage(content, tts, 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)

Example 8 with MessageJSON

use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.

the class GroupChannel 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;
}
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 9 with MessageJSON

use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.

the class GroupChannel method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Resource resource, boolean tts) {
    Attachment attachment = resource == null ? null : new Attachment(resource.getFileName());
    SendableMessage sendable = new SendableMessage(content, tts, 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)

Example 10 with MessageJSON

use of io.discloader.discloader.network.json.MessageJSON in project DiscLoader by R3alCl0ud.

the class GroupChannel method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, File file, boolean tts) {
    Attachment attachment = file == null ? null : new Attachment(file.getName());
    SendableMessage sendable = new SendableMessage(content, tts, 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)

Aggregations

IMessage (io.discloader.discloader.entity.message.IMessage)21 MessageJSON (io.discloader.discloader.network.json.MessageJSON)21 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)15 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)15 CompletableFuture (java.util.concurrent.CompletableFuture)15 Attachment (io.discloader.discloader.entity.sendable.Attachment)9 File (java.io.File)7 Message (io.discloader.discloader.core.entity.message.Message)3 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)3 HashMap (java.util.HashMap)2 GroupMessageCreateEvent (io.discloader.discloader.common.event.message.GroupMessageCreateEvent)1 GroupMessageDeleteEvent (io.discloader.discloader.common.event.message.GroupMessageDeleteEvent)1 GroupMessageUpdateEvent (io.discloader.discloader.common.event.message.GroupMessageUpdateEvent)1 GuildMessageCreateEvent (io.discloader.discloader.common.event.message.GuildMessageCreateEvent)1 GuildMessageDeleteEvent (io.discloader.discloader.common.event.message.GuildMessageDeleteEvent)1 GuildMessageUpdateEvent (io.discloader.discloader.common.event.message.GuildMessageUpdateEvent)1 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)1 MessageDeleteEvent (io.discloader.discloader.common.event.message.MessageDeleteEvent)1 MessageUpdateEvent (io.discloader.discloader.common.event.message.MessageUpdateEvent)1 PrivateMessageCreateEvent (io.discloader.discloader.common.event.message.PrivateMessageCreateEvent)1