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));
}
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.getLoader().getSelfUser() == null || message.getAuthor() == null || message.getAuthor().isBot() || ((!e.getLoader().getSelfUser().isBot() && selfBot) && message.getAuthor().getID() != e.getLoader().getSelfUser().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;
}
label = label.substring(prefix.length());
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() && n < args.length) {
for (int i = 0; i < argM.groupCount() && i < args.length; i++) {
try {
args[n] = argM.group(i);
} catch (Exception ex) {
ex.printStackTrace();
}
}
n++;
}
Thread handler = new Thread(command.getUnlocalizedName() + " - Message Handler") {
@Override
public void run() {
try {
command.execute(e, args);
} catch (Exception ex) {
DLLogger.getLogger(CommandHandler.class).severe("Error Occurred While attempting to execute the command \"" + command.getUnlocalizedName() + "\".");
ex.printStackTrace();
}
}
};
handler.setPriority(Thread.MAX_PRIORITY - 2);
handler.start();
return;
}
} catch (Exception ex) {
System.err.println("Error occurred whilst attempting to handle commands.");
ex.printStackTrace();
}
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class PrivateChannel 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;
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class Main method testTextChannelThings.
public static CompletableFuture<Void> testTextChannelThings(IGuild guild, IChannelCategory category) {
CompletableFuture<Void> future = new CompletableFuture<>();
AvoidRateLimits();
CompletableFuture<IGuildTextChannel> f5 = category.createTextChannel("text-channel");
f5.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(5);
return null;
});
f5.thenAcceptAsync(textchannel -> {
logger.config("Text Channel Created");
AvoidRateLimits();
CompletableFuture<IMessage> f6 = textchannel.sendMessage("content", new RichEmbed("embed").addField().setTimestamp(), new File("README.md"));
f6.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(6);
return null;
});
f6.thenAcceptAsync(m1 -> {
logger.config("Message Created");
AvoidRateLimits();
CompletableFuture<IMessage> f7 = m1.edit("editted content");
f7.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(7);
return null;
});
f7.thenAcceptAsync(m2 -> {
logger.config("Message Edited");
AvoidRateLimits();
CompletableFuture<IMessage> f8 = m2.pin();
f8.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(8);
return null;
});
f8.thenAcceptAsync(m3 -> {
logger.config("Message Pinned");
AvoidRateLimits();
CompletableFuture<IMessage> f9 = m3.unpin();
f9.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(9);
return null;
});
f9.thenAcceptAsync(m4 -> {
logger.config("Message Unpinned");
AvoidRateLimits();
CompletableFuture<Void> f10 = m4.addReaction("🍠");
f10.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(10);
return null;
});
f10.thenAcceptAsync(n -> {
logger.config("Reaction added");
AvoidRateLimits();
CompletableFuture<IMessage> f11 = m4.deleteAllReactions();
f11.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(11);
return null;
});
f11.thenAcceptAsync(m5 -> {
logger.config("Reaction removed");
AvoidRateLimits();
future.complete(null);
});
});
});
});
});
});
});
return future;
}
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);
}
Aggregations