Search in sources :

Example 1 with IGuild

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;
}
Also used : ModifyGuild(io.discloader.discloader.network.rest.actions.guild.ModifyGuild) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 2 with IGuild

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) GuildJSON(io.discloader.discloader.network.json.GuildJSON) IGuild(io.discloader.discloader.entity.guild.IGuild) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 3 with IGuild

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);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IChannel(io.discloader.discloader.entity.channel.IChannel) ChannelCreateEvent(io.discloader.discloader.common.event.channel.ChannelCreateEvent) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 4 with IGuild

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);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) IChannel(io.discloader.discloader.entity.channel.IChannel) ChannelDeleteEvent(io.discloader.discloader.common.event.channel.ChannelDeleteEvent) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 5 with IGuild

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);
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) IChannel(io.discloader.discloader.entity.channel.IChannel) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent) ChannelUpdateEvent(io.discloader.discloader.common.event.channel.ChannelUpdateEvent) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) IMessage(io.discloader.discloader.entity.message.IMessage) IGuild(io.discloader.discloader.entity.guild.IGuild) GuildChannelUpdateEvent(io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)

Aggregations

IGuild (io.discloader.discloader.entity.guild.IGuild)23 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)4 GuildJSON (io.discloader.discloader.network.json.GuildJSON)4 MemberJSON (io.discloader.discloader.network.json.MemberJSON)4 IChannel (io.discloader.discloader.entity.channel.IChannel)3 IRole (io.discloader.discloader.entity.guild.IRole)3 IUser (io.discloader.discloader.entity.user.IUser)3 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)3 GuildMemberRemoveJSON (io.discloader.discloader.network.json.GuildMemberRemoveJSON)3 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)2 PresenceJSON (io.discloader.discloader.network.json.PresenceJSON)2 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 IEventListener (io.discloader.discloader.common.event.IEventListener)1 UserUpdateEvent (io.discloader.discloader.common.event.UserUpdateEvent)1 ChannelCreateEvent (io.discloader.discloader.common.event.channel.ChannelCreateEvent)1 ChannelDeleteEvent (io.discloader.discloader.common.event.channel.ChannelDeleteEvent)1 ChannelUpdateEvent (io.discloader.discloader.common.event.channel.ChannelUpdateEvent)1 GuildChannelUpdateEvent (io.discloader.discloader.common.event.channel.GuildChannelUpdateEvent)1 GuildBanAddEvent (io.discloader.discloader.common.event.guild.GuildBanAddEvent)1