use of io.discloader.discloader.network.json.ChannelJSON in project DiscLoader by R3alCl0ud.
the class Guild method createTextChannel.
@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name, IChannelCategory category, IOverwrite... overwrites) {
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
if (!hasPermission(Permissions.MANAGE_CHANNELS)) {
PermissionsException ex = new PermissionsException("Insufficient Permissions");
future.completeExceptionally(ex);
// return early
return future;
}
ChannelPayload data = new ChannelPayload(name, ChannelTypes.TEXT, overwrites);
data.setParent(category);
CompletableFuture<ChannelJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
cf.thenAcceptAsync(channelJSON -> {
IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), this, false);
future.complete(channel);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.network.json.ChannelJSON 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.network.json.ChannelJSON 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.network.json.ChannelJSON 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);
}
use of io.discloader.discloader.network.json.ChannelJSON in project DiscLoader by R3alCl0ud.
the class Ready method handle.
@Override
public void handle(SocketPacket packet) {
String d = gson.toJson(packet.d);
ReadyJSON readyJSON = gson.fromJson(d, ReadyJSON.class);
// set session id first just incase some screws up
socket.sessionID = readyJSON.session_id;
// setup the Loaders user object
try {
loader.user = new DLUser(EntityRegistry.addUser(readyJSON.user));
/*
* need to make sure that we don't already have the 'Bot ' prefix on the token
* otherwise bots fail to work if they've had to start a completely new session after disconnecting
*/
if (loader.user.isBot() && !loader.token.startsWith("Bot ")) {
loader.token = "Bot " + loader.token;
}
// load the guilds
for (GuildJSON guild : readyJSON.guilds) {
EntityRegistry.addGuild(guild);
}
// load the private channels
for (ChannelJSON data : readyJSON.private_channels) {
EntityRegistry.addChannel(data, null);
}
} catch (Exception e) {
e.printStackTrace();
}
// check if the loader is ready to rock & roll
loader.socket.setRetries(0);
loader.checkReady();
}
Aggregations