use of io.discloader.discloader.network.json.EmojiJSON in project DiscLoader by R3alCl0ud.
the class Guild method createEmoji.
@Override
public CompletableFuture<IGuildEmoji> createEmoji(String name, String image, IRole... roles) {
CompletableFuture<IGuildEmoji> future = new CompletableFuture<>();
String base64 = null;
try {
base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(image))));
} catch (IOException e) {
e.printStackTrace();
}
String[] rids = new String[roles.length];
for (int i = 0; i < rids.length; i++) {
rids[i] = SnowflakeUtil.asString(roles[i]);
}
CreateEmoji ce = new CreateEmoji(name, base64, rids);
CompletableFuture<EmojiJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildEmojis(getID()), new RESTOptions(ce), EmojiJSON.class);
cf.thenAcceptAsync(ed -> {
future.complete(new GuildEmoji(ed, this));
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.json.EmojiJSON in project DiscLoader by R3alCl0ud.
the class EmojiUpdate method handle.
@Override
public void handle(SocketPacket packet) {
String d = this.gson.toJson(packet.d);
EmojiUpdateJSON data = gson.fromJson(d, EmojiUpdateJSON.class);
IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
HashMap<Long, IGuildEmoji> emojis = new HashMap<>();
for (EmojiJSON e : data.emojis) {
IGuildEmoji emoji = new GuildEmoji(e, guild);
emojis.put(emoji.getID(), emoji);
}
if (shouldEmit()) {
if (data.emojis.length == guild.getEmojis().size()) {
IGuildEmoji oldEmoji;
for (IGuildEmoji emoji : emojis.values()) {
oldEmoji = guild.getEmojis().get(emoji.getID());
if (emoji.getID() == oldEmoji.getID() && !emoji.equals(oldEmoji)) {
GuildEmojiUpdateEvent event = new GuildEmojiUpdateEvent(emoji, oldEmoji);
loader.emit(Events.GUILD_EMOJI_UPDATE, event);
loader.emit(event);
}
}
} else if (data.emojis.length < guild.getEmojis().size()) {
for (IGuildEmoji emoji : guild.getEmojis().values()) {
if (!emojis.containsKey(emoji.getID())) {
GuildEmojiDeleteEvent event = new GuildEmojiDeleteEvent(emoji);
loader.emit("GuildEmojiDelete", event);
loader.emit(event);
}
}
} else if (data.emojis.length > guild.getEmojis().size()) {
for (IGuildEmoji emoji : emojis.values()) {
if (!guild.getEmojis().containsKey(emoji.getID())) {
GuildEmojiCreateEvent event = new GuildEmojiCreateEvent(emoji);
loader.emit("GuildEmojiCreate", event);
loader.emit(event);
}
}
}
}
guild.getEmojis().clear();
emojis.forEach((key, emoji) -> guild.getEmojis().put(key, emoji));
}
use of io.discloader.discloader.network.json.EmojiJSON in project DiscLoader by R3alCl0ud.
the class Guild method setup.
/**
* Sets up a guild with data from the gateway
*
* @param data
* The guild's data
*/
@Override
public void setup(GuildJSON data) {
try {
name = data.name;
icon = data.icon != null ? data.icon : null;
iconURL = icon != null ? Endpoints.guildIcon(getID(), icon) : null;
ownerID = SnowflakeUtil.parse(data.owner_id);
memberCount = data.member_count;
voiceRegion = new VoiceRegion(data.region);
splashHash = data.splash;
if (data.roles.length > 0) {
roles.clear();
for (RoleJSON role : data.roles) {
IRole r = gfac.buildRole(this, role);
roles.put(r.getID(), r);
}
}
if (data.members != null && data.members.length > 0) {
members.clear();
for (MemberJSON member : data.members) {
IGuildMember m = gfac.buildMember(this, member);
members.put(m.getID(), m);
}
}
if (data.channels != null && data.channels.length > 0) {
for (ChannelJSON channelData : data.channels) {
IGuildChannel chan = (IGuildChannel) EntityRegistry.addChannel(channelData, getLoader(), this);
if (chan instanceof IGuildTextChannel)
textChannels.put(chan.getID(), (IGuildTextChannel) chan);
else if (chan instanceof IGuildVoiceChannel)
voiceChannels.put(chan.getID(), (IGuildVoiceChannel) chan);
}
}
if (data.presences != null && data.presences.length > 0) {
presences.clear();
for (PresenceJSON presence : data.presences) {
this.setPresence(presence);
}
}
if (data.emojis != null && data.emojis.length > 0) {
this.guildEmojis.clear();
for (EmojiJSON e : data.emojis) {
this.guildEmojis.put(SnowflakeUtil.parse(e.id), new GuildEmoji(e, this));
}
}
if (data.voice_states != null && data.voice_states.length > 0) {
this.rawStates.clear();
for (VoiceStateJSON v : data.voice_states) {
this.rawStates.put(SnowflakeUtil.parse(v.user_id), new VoiceState(v, this));
}
}
this.available = data.unavailable == true ? false : true;
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations