use of io.discloader.discloader.entity.guild.IGuild in project DiscLoader by R3alCl0ud.
the class Guild method clone.
public IGuild clone() {
Guild guild = new Guild(loader, null);
guildEmojis.forEach((id, emoji) -> guild.guildEmojis.put(id, emoji));
roles.forEach((id, role) -> guild.addRole(role));
members.forEach((id, member) -> guild.addMember(member));
rawStates.forEach((id, state) -> guild.rawStates.put(id, state));
textChannels.forEach((id, channel) -> guild.textChannels.put(id, channel));
voiceChannels.forEach((id, channel) -> guild.voiceChannels.put(id, channel));
presences.forEach((id, presence) -> guild.presences.put(id, presence));
guild.available = available;
guild.name = name;
guild.icon = icon;
guild.iconURL = iconURL;
guild.id = id;
guild.voiceRegion = voiceRegion;
guild.memberCount = memberCount;
guild.ownerID = ownerID;
guild.splash = splash;
guild.splashHash = splashHash;
guild.afk_channel_id = afk_channel_id;
return guild;
}
use of io.discloader.discloader.entity.guild.IGuild in project DiscLoader by R3alCl0ud.
the class Guild method edit.
public CompletableFuture<IGuild> edit(String name, String icon, IGuildVoiceChannel afkChannel) throws IOException {
if (!isOwner() && !getCurrentMember().getPermissions().hasPermission(Permissions.MANAGE_GUILD)) {
throw new PermissionsException();
}
CompletableFuture<IGuild> future = new CompletableFuture<>();
String base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(icon))));
JSONObject payload = new JSONObject().put("name", name).put("icon", base64);
CompletableFuture<GuildJSON> cf = getLoader().rest.request(Methods.PATCH, Endpoints.guild(getID()), new RESTOptions(payload), GuildJSON.class);
cf.thenAcceptAsync(guildJSON -> {
IGuild guild = clone();
guild.setup(guildJSON);
future.complete(guild);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.entity.guild.IGuild in project DiscLoader by R3alCl0ud.
the class ChannelCreate method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
IChannel channel = EntityRegistry.addChannel(data, loader, guild);
ChannelCreateEvent event = new ChannelCreateEvent(channel);
loader.emit(Events.CHANNEL_CREATE, event);
loader.emit(event);
}
use of io.discloader.discloader.entity.guild.IGuild in project DiscLoader by R3alCl0ud.
the class ChannelDelete method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
IGuild guild = null;
IChannel channel = null;
if (data.guild_id != null) {
guild = EntityRegistry.getGuildByID(data.guild_id);
channel = EntityRegistry.addChannel(data, loader, guild);
} else {
channel = EntityRegistry.addChannel(data, loader);
}
switch(channel.getType()) {
case TEXT:
guild.getTextChannels().remove(channel.getID());
break;
case VOICE:
guild.getVoiceChannels().remove(channel.getID());
break;
default:
EntityRegistry.removeChannel(channel);
break;
}
ChannelDeleteEvent event = new ChannelDeleteEvent(channel);
loader.emit(Events.CHANNEL_DELETE, event);
loader.emit(event);
}
use of io.discloader.discloader.entity.guild.IGuild in project DiscLoader by R3alCl0ud.
the class ChannelUpdate method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
ChannelJSON data = gson.fromJson(d, ChannelJSON.class);
IGuild guild = null;
IChannel oldChannel = EntityRegistry.getChannelByID(data.id);
IChannel channel = null;
if (data.guild_id != null) {
guild = EntityRegistry.getGuildByID(data.guild_id);
}
channel = EntityRegistry.addChannel(data, loader, guild);
if (oldChannel instanceof ITextChannel) {
ITextChannel oitc = (ITextChannel) oldChannel, itc = (ITextChannel) channel;
for (IMessage message : oitc.getMessages().values()) {
itc.getMessages().put(message.getID(), message);
}
}
ChannelUpdateEvent event = new ChannelUpdateEvent(channel, oldChannel);
if (channel instanceof IGuildChannel && oldChannel instanceof IGuildChannel) {
loader.emit(new GuildChannelUpdateEvent((IGuildChannel) channel, (IGuildChannel) oldChannel));
}
loader.emit(Events.CHANNEL_UPDATE, event);
loader.emit(event);
}
Aggregations