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;
}
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;
}
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();
}
}
Aggregations