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;
}
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;
}
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);
}
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));
}
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();
}
Aggregations