use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class MessageCreate method handle.
@Override
public void handle(SocketPacket packet) {
MessageJSON data = this.gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
try {
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 = EntityBuilder.getChannelFactory().buildMessage(channel, data);
channel.getMessages().put(message.getID(), message);
if (channel.isTyping(message.getAuthor())) {
channel.getTyping().remove(message.getAuthor().getID());
}
MessageCreateEvent event = new MessageCreateEvent(message);
loader.emit(DLUtil.Events.MESSAGE_CREATE, event);
loader.emit(event);
if (channel.getType() == ChannelTypes.TEXT) {
GuildMessageCreateEvent event2 = new GuildMessageCreateEvent(message);
loader.emit("GuildMessageCreate", event2);
loader.emit(event2);
} else if (channel.getType() == ChannelTypes.DM) {
PrivateMessageCreateEvent event2 = new PrivateMessageCreateEvent(message);
loader.emit(DLUtil.Events.PRIVATE_MESSAGE_CREATE, event2);
loader.emit(event2);
}
CommandHandler.handleMessageCreate(event);
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class MessageUpdate method handle.
@Override
public void handle(SocketPacket packet) {
MessageJSON data = gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
if (channel == null)
channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
if (channel == null)
return;
IMessage oldMessage = channel.getMessage(data.id), message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
MessageUpdateEvent event = new MessageUpdateEvent(message, oldMessage);
loader.emit(Events.MESSAGE_UPDATE, event);
loader.emit(event);
if (message.getGuild() != null) {
loader.emit(new GuildMessageUpdateEvent(message, oldMessage));
} else if (channel.getType() == ChannelTypes.DM) {
loader.emit(new PrivateMessageUpdateEvent(message, oldMessage));
} else if (channel.getType() == ChannelTypes.GROUP) {
loader.emit(new GroupMessageUpdateEvent(message, oldMessage));
}
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class ReactionRemove 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);
for (IReaction r : message.getReactions()) {
if (r.getEmoji().toString().equals(reaction.toString()))
reaction = r;
}
message.getReactions().remove(reaction);
loader.emit(new MessageReactionRemoveEvent(message, reaction, user));
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class FetchMessages method complete.
@Override
public void complete(String s, Throwable ex) {
if (ex != null) {
future.completeExceptionally(ex);
return;
} else {
MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
HashMap<Long, IMessage> messages = new HashMap<>();
for (MessageJSON m : data) {
IMessage message = new Message<>(channel, m);
channel.getMessages().put(message.getID(), message);
messages.put(message.getID(), message);
}
future.complete(messages);
}
}
use of io.discloader.discloader.entity.message.IMessage in project DiscLoader by R3alCl0ud.
the class PinnedMessages method complete.
@Override
public void complete(String s, Throwable ex) {
if (ex != null) {
future.completeExceptionally(ex);
return;
} else {
MessageJSON[] data = DLUtil.gson.fromJson(s, MessageJSON[].class);
HashMap<Long, IMessage> messages = new HashMap<>();
for (MessageJSON m : data) {
IMessage message = new Message<T>(channel, m);
channel.getMessages().put(message.getID(), message);
messages.put(message.getID(), message);
}
future.complete(messages);
}
}
Aggregations