Search in sources :

Example 1 with DLUser

use of io.discloader.discloader.core.entity.user.DLUser 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();
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) DLUser(io.discloader.discloader.core.entity.user.DLUser) ReadyJSON(io.discloader.discloader.network.json.ReadyJSON) GuildJSON(io.discloader.discloader.network.json.GuildJSON)

Aggregations

DLUser (io.discloader.discloader.core.entity.user.DLUser)1 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)1 GuildJSON (io.discloader.discloader.network.json.GuildJSON)1 ReadyJSON (io.discloader.discloader.network.json.ReadyJSON)1