Search in sources :

Example 16 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class User method sendMessage.

@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Resource resource) {
    CompletableFuture<IMessage> future = new CompletableFuture<>();
    IPrivateChannel channel = getPrivateChannel();
    if (channel == null) {
        try {
            channel = openPrivateChannel().get();
            return channel.sendMessage(content, embed, resource);
        } catch (ExecutionException | InterruptedException e) {
            future.completeExceptionally(e.getCause());
            return future;
        }
    }
    return channel.sendMessage(content, embed, resource);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IMessage(io.discloader.discloader.entity.message.IMessage) IPrivateChannel(io.discloader.discloader.entity.channel.IPrivateChannel) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with IMessage

use of io.discloader.discloader.entity.message.IMessage 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)
        return;
    IMessage message = channel.getMessage(data.id);
    if (message == null)
        return;
    channel.getMessages().remove(message.getID());
    MessageDeleteEvent event = new MessageDeleteEvent(message);
    loader.emit(Events.MESSAGE_DELETE, event);
    loader.emit(event);
    if (channel.getType() == ChannelTypes.DM) {
        loader.emit(new PrivateMessageDeleteEvent(message));
    }
    if (message.getGuild() != null) {
        loader.emit(new GuildMessageDeleteEvent(message));
    }
}
Also used : PrivateMessageDeleteEvent(io.discloader.discloader.common.event.message.PrivateMessageDeleteEvent) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage) GuildMessageDeleteEvent(io.discloader.discloader.common.event.message.GuildMessageDeleteEvent) PrivateMessageDeleteEvent(io.discloader.discloader.common.event.message.PrivateMessageDeleteEvent) GuildMessageDeleteEvent(io.discloader.discloader.common.event.message.GuildMessageDeleteEvent) MessageDeleteEvent(io.discloader.discloader.common.event.message.MessageDeleteEvent)

Example 18 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class ReactionAdd method handle.

public void handle(SocketPacket packet) {
    ReactionJSON data = gson.fromJson(gson.toJson(packet.d), ReactionJSON.class);
    IUser user = EntityRegistry.getUserByID(data.user_id);
    ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
    if (channel == null)
        return;
    IMessage message = channel.getMessage(data.message_id);
    if (message == null || user == null)
        return;
    IReaction reaction = new Reaction(data, message);
    message.getReactions().add(reaction);
    loader.emit(new MessageReactionAddEvent(message, reaction, user));
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageReactionAddEvent(io.discloader.discloader.common.event.message.MessageReactionAddEvent) IMessage(io.discloader.discloader.entity.message.IMessage) IUser(io.discloader.discloader.entity.user.IUser) IReaction(io.discloader.discloader.entity.message.IReaction) ReactionJSON(io.discloader.discloader.network.json.ReactionJSON) Reaction(io.discloader.discloader.core.entity.message.Reaction) IReaction(io.discloader.discloader.entity.message.IReaction)

Example 19 with IMessage

use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.

the class FetchMessage method complete.

@Override
public void complete(String s, Throwable ex) {
    if (ex != null) {
        future.completeExceptionally(ex);
        return;
    }
    MessageJSON data = DLUtil.gson.fromJson(s, MessageJSON.class);
    IMessage message = new Message<>(channel, data);
    channel.getMessages().put(message.getID(), message);
    future.complete(message);
}
Also used : IMessage(io.discloader.discloader.entity.message.IMessage) Message(io.discloader.discloader.core.entity.message.Message) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage)

Example 20 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)

Aggregations

IMessage (io.discloader.discloader.entity.message.IMessage)23 MessageJSON (io.discloader.discloader.network.json.MessageJSON)12 CompletableFuture (java.util.concurrent.CompletableFuture)10 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)8 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)6 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)6 File (java.io.File)5 Message (io.discloader.discloader.core.entity.message.Message)3 Attachment (io.discloader.discloader.entity.sendable.Attachment)3 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)2 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)2 RichEmbed (io.discloader.discloader.core.entity.RichEmbed)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 Lists (com.google.common.collect.Lists)1