public ConnectionRequest(Guild guild) { this.stage = ConnectionStage.DISCONNECT; this.guildId = guild.getIdLong(); }
/** * Returns the shard id the given {@link net.dv8tion.jda.core.entities.Guild Guild} will be loaded on for the given amount of shards. * * Discord determines which guilds a shard is connect to using the following format: * {@code shardId == (guildId >>> 22) % totalShards} * <br>Source for formula: <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">Discord Documentation</a> * * @param guild * The guild. * @param shards * The amount of shards. * * @return The shard id for the guild. */ public static int getShardForGuild(Guild guild, int shards) { return getShardForGuild(guild.getIdLong(), shards); }
public ConnectionRequest(VoiceChannel channel, ConnectionStage stage) { this.channelId = channel.getIdLong(); this.guildId = channel.getGuild().getIdLong(); this.stage = stage; this.nextAttemptEpoch = System.currentTimeMillis(); }
@Override protected void handleResponse(Response response, Request<Channel> request) { if (!response.isOk()) { request.onFailure(response); return; } EntityBuilder builder = api.get().getEntityBuilder(); Channel channel; switch (type) { case VOICE: channel = builder.createVoiceChannel(response.getObject(), guild.getIdLong()); break; case TEXT: channel = builder.createTextChannel(response.getObject(), guild.getIdLong()); break; case CATEGORY: channel = builder.createCategory(response.getObject(), guild.getIdLong()); break; default: request.onFailure(new IllegalStateException("Created channel of unknown type!")); return; } request.onSuccess(channel); }
public void queueAudioDisconnect(Guild guild) { locked("There was an error queueing the audio disconnect", () -> { final long guildId = guild.getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // If we do not have a request queuedAudioConnections.put(guildId, new ConnectionRequest(guild)); } else { // If we have a request, change to DISCONNECT request.setStage(ConnectionStage.DISCONNECT); } }); }
@Override protected void handleResponse(Response response, Request<Role> request) { if (response.isOk()) request.onSuccess(api.get().getEntityBuilder().createRole((GuildImpl) guild, response.getObject(), guild.getIdLong())); else request.onFailure(response); }
public void queueAudioReconnect(VoiceChannel channel) { locked("There was an error queueing the audio reconnect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // If no request, then just reconnect request = new ConnectionRequest(channel, ConnectionStage.RECONNECT); queuedAudioConnections.put(guildId, request); } else { // If there is a request we change it to reconnect, no matter what it is request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }
protected AudioHandler(PlayerManager manager, Guild guild, AudioPlayer player) { this.manager = manager; this.audioPlayer = player; this.guildId = guild.getIdLong(); }
public void queueAudioConnect(VoiceChannel channel) { locked("There was an error queueing the audio connect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // starting a whole new connection request = new ConnectionRequest(channel, ConnectionStage.CONNECT); queuedAudioConnections.put(guildId, request); } else if (request.getStage() == ConnectionStage.DISCONNECT) { // if planned to disconnect, we want to reconnect request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }
/** * Gets non-null settings for a Guild * * @param guild the guild to get settings for * @return the existing settings, or new settings for that guild */ @Override public Settings getSettings(Guild guild) { return getSettings(guild.getIdLong()); }
/** * Retrieves the internal guild id for {@link MessageChannel} channel * * @param channel the channel to check * @return internal guild-id OR 0 if no guild could be found */ public static int getCachedId(MessageChannel channel) { if (channel instanceof TextChannel) { return getCachedId(((TextChannel) channel).getGuild().getIdLong()); } return 0; }
/** * load data for a guild * * @param guild guild to load for */ public void loadGuild(Guild guild) { int cachedId = CGuild.getCachedId(guild.getIdLong()); CommandHandler.loadCustomCommands(cachedId); }
public static String getGuild(Guild guild, String keyPhrase){ if(guild == null){ return getGlobal(keyPhrase); } return getGuild(CGuild.getCachedId(guild.getIdLong()), keyPhrase); } public static String getGuild(int guildId, String keyPhrase) {
public String formatGuild(MessageChannel channel, Object... vars) { if (channel.getType().equals(ChannelType.TEXT)) { return formatFull(((TextChannel) channel).getGuild().getIdLong(), false, vars); } return formatFull(0, false, vars); }