Search in sources :

Example 1 with Packet

use of io.discloader.discloader.entity.sendable.Packet in project DiscLoader by R3alCl0ud.

the class Guild method fetchMembers.

@Override
public CompletableFuture<Map<Long, IGuildMember>> fetchMembers(int limit) {
    CompletableFuture<Map<Long, IGuildMember>> future = new CompletableFuture<>();
    final Consumer<GuildMembersChunkEvent> consumer = new Consumer<GuildMembersChunkEvent>() {

        @Override
        public void accept(GuildMembersChunkEvent e) {
            if (e.getGuild().getID() != getID()) {
                loader.onceEvent(GuildMembersChunkEvent.class, this);
                return;
            }
            future.complete(e.getMembers());
        }
    };
    loader.onceEvent(GuildMembersChunkEvent.class, consumer);
    Packet payload = new Packet(8, new MemberQuery(limit, ""));
    loader.socket.send(payload);
    return future;
}
Also used : Packet(io.discloader.discloader.entity.sendable.Packet) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(java.util.function.Consumer) GuildMembersChunkEvent(io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Packet

use of io.discloader.discloader.entity.sendable.Packet in project DiscLoader by R3alCl0ud.

the class DLUser method setPresence.

/**
 * Set's the currently logged in user's presence
 *
 * @param status
 *            The new status
 * @param activity
 *            The new activity
 * @param afk
 *            Are you afk?
 * @return this
 */
public DLUser setPresence(String status, Activity activity, boolean afk) {
    StatusUpdate d = new StatusUpdate(activity, status, afk, 0);
    Packet payload = new Packet(3, d);
    presence.update(status, activity);
    loader.socket.send(payload);
    return this;
}
Also used : StatusUpdate(io.discloader.discloader.network.gateway.packets.request.StatusUpdate) Packet(io.discloader.discloader.entity.sendable.Packet)

Example 3 with Packet

use of io.discloader.discloader.entity.sendable.Packet in project DiscLoader by R3alCl0ud.

the class DiscLoader method syncGuilds.

/**
 * Syncs guilds to client if the logged in user is not a bot
 *
 * @param guilds
 *            the guilds to sync
 * @throws GuildSyncException
 * @throws AccountTypeException
 */
public void syncGuilds(IGuild... guilds) throws GuildSyncException, AccountTypeException {
    if (user.isBot())
        throw new AccountTypeException("Only user accounts are allowed to sync guilds");
    String[] ids = new String[guilds.length];
    for (int i = 0; i < guilds.length; i++) {
        if (isGuildSyncing(guilds[i]))
            throw new GuildSyncException("Cannot syncing a guild that is currently syncing");
        ids[i] = Long.toUnsignedString(guilds[i].getID());
    }
    Packet packet = new Packet(12, ids);
    socket.send(packet, true);
}
Also used : Packet(io.discloader.discloader.entity.sendable.Packet) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) GuildSyncException(io.discloader.discloader.common.exceptions.GuildSyncException)

Example 4 with Packet

use of io.discloader.discloader.entity.sendable.Packet in project DiscLoader by R3alCl0ud.

the class VoiceConnection method sendStateUpdate.

private void sendStateUpdate(IVoiceChannel channel) {
    this.stateUpdated = false;
    VoiceStateUpdate d = new VoiceStateUpdate(getGuild(), channel, false, false);
    getLoader().socket.send(new Packet(4, d));
}
Also used : Packet(io.discloader.discloader.entity.sendable.Packet) VoiceStateUpdate(io.discloader.discloader.entity.sendable.VoiceStateUpdate)

Example 5 with Packet

use of io.discloader.discloader.entity.sendable.Packet in project DiscLoader by R3alCl0ud.

the class Gateway method handleQueue.

public void handleQueue() {
    if (!ws.isOpen() || remaining == 0 || queue.isEmpty())
        return;
    Object raw_payload = queue.get(0);
    // loader.em
    remaining--;
    String payload = "";
    if (raw_payload instanceof JSONObject) {
        payload = raw_payload.toString();
    } else {
        if (raw_payload instanceof Packet && ((Packet) raw_payload).d instanceof VoiceStateUpdate) {
            payload = gson.toJson(raw_payload);
        } else {
            payload = DLUtil.gson.toJson(raw_payload);
        }
    }
    logger.info("Sending: " + payload);
    ws.sendText(payload);
    queue.remove(raw_payload);
    handleQueue();
}
Also used : Packet(io.discloader.discloader.entity.sendable.Packet) VoiceStateUpdate(io.discloader.discloader.entity.sendable.VoiceStateUpdate) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

Packet (io.discloader.discloader.entity.sendable.Packet)9 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)3 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)2 VoiceStateUpdate (io.discloader.discloader.entity.sendable.VoiceStateUpdate)2 GuildMembersChunkEvent (io.discloader.discloader.common.event.guild.member.GuildMembersChunkEvent)1 GatewayIdentify (io.discloader.discloader.network.gateway.packets.request.GatewayIdentify)1 GatewayResume (io.discloader.discloader.network.gateway.packets.request.GatewayResume)1 Properties (io.discloader.discloader.network.gateway.packets.request.Properties)1 StatusUpdate (io.discloader.discloader.network.gateway.packets.request.StatusUpdate)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1 JSONObject (org.json.JSONObject)1