@Override public IShard getShard() { return getGuild().getShard(); }
@Override public IShard getShard() { return getGuild().getShard(); }
@Override public IShard getShard() { return getGuild().getShard(); }
/** * Converts a json {@link AuditLogObject} to a {@link AuditLog}. * * @param guild The guild the audit log belongs to. * @param json The json object representing the audit log. * @return The converted audit log object. */ public static AuditLog getAuditLogFromJSON(IGuild guild, AuditLogObject json) { LongMap<IUser> users = Arrays.stream(json.users) .map(u -> DiscordUtils.getUserFromJSON(guild.getShard(), u)) .collect(LongMapCollector.toLongMap()); LongMap<IWebhook> webhooks = Arrays.stream(json.webhooks) .map(w -> DiscordUtils.getWebhookFromJSON(guild.getChannelByID(Long.parseUnsignedLong(w.channel_id)), w)) .collect(LongMapCollector.toLongMap()); LongMap<AuditLogEntry> entries = Arrays.stream(json.audit_log_entries) .map(e -> DiscordUtils.getAuditLogEntryFromJSON(guild, users, webhooks, e)) .collect(LongMapCollector.toLongMap()); return new AuditLog(entries); }
@Override public void mute(IGuild guild, boolean isSelfMuted) { VoiceState voiceState = (VoiceState) ourUser.getVoiceStateForGuild(guild); String channelID = null; long connectingID = ((Guild) guild).connectingVoiceChannelID; if (connectingID != 0) { channelID = Long.toUnsignedString(connectingID); } else if (voiceState.getChannel() != null) { channelID = voiceState.getChannel().getStringID(); } voiceState.setSelfMuted(isSelfMuted); ((ShardImpl) guild.getShard()).ws.send(GatewayOps.VOICE_STATE_UPDATE, new VoiceStateUpdateRequest( guild.getStringID(), channelID, isSelfMuted, voiceState.isSelfDeafened())); }
@Override public void deafen(IGuild guild, boolean isSelfDeafened) { VoiceState voiceState = (VoiceState) ourUser.getVoiceStateForGuild(guild); String channelID = null; long connectingID = ((Guild) guild).connectingVoiceChannelID; if (connectingID != 0) { channelID = Long.toUnsignedString(connectingID); } else if (voiceState.getChannel() != null) { channelID = voiceState.getChannel().getStringID(); } voiceState.setSelfDeafened(isSelfDeafened); ((ShardImpl) guild.getShard()).ws.send(GatewayOps.VOICE_STATE_UPDATE, new VoiceStateUpdateRequest( guild.getStringID(), channelID, voiceState.isSelfMuted(), isSelfDeafened)); }
/** * Converts a json {@link MemberObject} to a {@link IUser}. This method uses {@link #getUserFromJSON(IShard, UserObject)} * to get or create a {@link IUser} and then updates the guild's appropriate member caches for that user. * * @param guild The guild the member belongs to. * @param json The json object representing the member. * @return The converted user object. */ public static IUser getUserFromGuildMemberResponse(IGuild guild, MemberObject json) { User user = getUserFromJSON(guild.getShard(), json.user); for (String role : json.roles) { Role roleObj = (Role) guild.getRoleByID(Long.parseUnsignedLong(role)); if (roleObj != null && !user.getRolesForGuild(guild).contains(roleObj)) user.addRole(guild.getLongID(), roleObj); } user.addRole(guild.getLongID(), guild.getRoleByID(guild.getLongID())); //@everyone role user.addNick(guild.getLongID(), json.nick); VoiceState voiceState = (VoiceState) user.getVoiceStateForGuild(guild); voiceState.setDeafened(json.deaf); voiceState.setMuted(json.mute); ((Guild) guild).joinTimes.put(new Guild.TimeStampHolder(user.getLongID(), convertFromTimestamp(json.joined_at))); return user; }