Search in sources :

Example 21 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 22 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)

Example 23 with IMessage

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

the class CommandHandler method handleMessageCreate.

public static void handleMessageCreate(MessageCreateEvent e) {
    try {
        IMessage message = e.getMessage();
        if (!handleCommands || e.loader.user == null || message.getAuthor() == null || message.getAuthor().isBot() || ((!e.loader.user.isBot() && selfBot) && message.getAuthor().getID() != e.loader.user.getID()) || message.getContent().length() < prefix.length()) {
            return;
        }
        String[] Args = e.args;
        String label = Args[0];
        String rest = "";
        if (label.length() < message.getContent().length())
            rest = message.getContent().substring(label.length() + 1);
        int argc = Args.length > 1 ? Args.length - 1 : 0;
        if (label.length() < prefix.length() || !label.substring(0, prefix.length()).equals(prefix)) {
            return;
        }
        try {
            label = label.substring(prefix.length());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        Command command = getCommand(label, message);
        if (command != null) {
            if (message.getChannel() instanceof IGuildTextChannel && !command.shouldExecute(message.getMember(), (IGuildTextChannel) message.getChannel()))
                return;
            String[] args = new String[argc];
            Matcher argM = command.getArgsPattern().matcher(rest);
            int n = 0;
            while (argM.find()) {
                for (int i = 0; i < argM.groupCount() && i < args.length; i++) {
                    try {
                        args[n] = argM.group(i);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                n++;
            }
            command.execute(e, args);
            return;
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : Matcher(java.util.regex.Matcher) IMessage(io.discloader.discloader.entity.message.IMessage) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel)

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