use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.
the class GuildBanRemove method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
GuildMemberRemoveJSON data = gson.fromJson(d, GuildMemberRemoveJSON.class);
IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
IUser user = EntityRegistry.addUser(data.user);
GuildBanRemoveEvent event = new GuildBanRemoveEvent(guild, user);
loader.emit(DLUtil.Events.GUILD_BAN_REMOVE, event);
loader.emit(event);
}
use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.
the class PresenceUpdate method handle.
@Override
public void handle(SocketPacket packet) {
PresenceJSON data = this.gson.fromJson(gson.toJson(packet.d), PresenceJSON.class);
IUser user = EntityRegistry.getUserByID(data.user.id);
if (user == null) {
if (data.user.username != null) {
user = EntityRegistry.addUser(data.user);
} else {
return;
}
}
IUser oldUser = new User(user);
user.setup(data.user);
if (!user.equals(oldUser)) {
UserUpdateEvent event = new UserUpdateEvent(user, oldUser);
loader.emit(DLUtil.Events.USER_UPDATE, event);
loader.emit(event);
}
IGuild guild = data.guild_id == null ? null : EntityRegistry.getGuildByID(data.guild_id);
if (guild != null) {
IGuildMember oldMember = guild.getMember(user.getID()), member;
if (oldMember == null && !data.status.equalsIgnoreCase("offline")) {
member = guild.addMember(user, data.roles, false, false, data.nick, false);
loader.emit(DLUtil.Events.GUILD_MEMBER_AVAILABLE, member);
} else if (oldMember != null) {
member = guild.addMember(user, data.roles, oldMember.isDeafened(), oldMember.isMuted(), data.nick, false);
guild.setPresence(data);
loader.emit(new GuildMemberUpdateEvent(member, oldMember));
} else {
guild.setPresence(data);
}
}
}
use of io.discloader.discloader.entity.user.IUser 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.user.IUser in project DiscLoader by R3alCl0ud.
the class TypingStart method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
TypingStartJSON data = gson.fromJson(d, TypingStartJSON.class);
ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
if (channel == null)
channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
if (channel == null)
return;
IUser user = EntityRegistry.getUserByID(data.user_id);
if (user == null || channel.getTyping() == null)
return;
channel.getTyping().put(user.getID(), user);
TypingStartEvent e = new TypingStartEvent(user, channel);
loader.emit(e);
loader.emit("TypingStart", e);
}
use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.
the class EntityRegistry method addUser.
public static IUser addUser(UserJSON data) {
if (data == null)
return null;
if (userExists(data.id == null ? "0" : data.id))
return getUserByID(data.id == null ? "0" : data.id);
IUser user = EntityBuilder.getUserFactory().buildUser(data);
users.put(user.getID(), user);
return user;
}
Aggregations