@Override public List<IRole> getRoleMentions() { return roleMentions.stream() .map(m -> getGuild().getRoleByID(m)) .collect(Collectors.toList()); }
@Override public boolean isDeleted() { return getGuild().getRoleByID(id) != this; }
@Override public IRole getRoleByID(long roleID) { return guildCache.findResult((guildID, guild) -> guild.getRoleByID(roleID)); }
public static long getRole(String toLookFor, IGuild guild) { toLookFor = GeneralUtils.trim(toLookFor); final String lower = toLookFor.toLowerCase(); if (lower.matches("@&[0-9]+") || lower.matches("[0-9]+")) { final String parse = toLookFor.replaceAll("[<@&>]", ""); IRole exists = guild.getRoleByID(Long.parseLong(toLookFor.replaceAll("[<@&>]", ""))); if (exists != null) return exists.getLongID(); } List<IRole> roles = new ArrayList<>(); List<IRole> rs = guild.getRoles(); roles.addAll(rs.stream().filter(r -> r.getName().equalsIgnoreCase(lower)).collect(Collectors.toList())); roles.addAll(rs.stream().filter(r -> r.getName().toLowerCase().contains(lower)).collect(Collectors.toList())); if (!roles.isEmpty()) return roles.get(0).getLongID(); return 0; } }
/** * Converts a json {@link EmojiObject} to a {@link IEmoji}. * * @param guild The guild the emoji belongs to. * @param json The json object representing the emoji. * @return The converted emoji object. */ public static IEmoji getEmojiFromJSON(IGuild guild, EmojiObject json) { long id = Long.parseUnsignedLong(json.id); List<IRole> roles = Arrays.stream(json.roles) .map(role -> guild.getRoleByID(Long.parseUnsignedLong(role))) .collect(Collectors.toList()); EmojiImpl emoji = (EmojiImpl) guild.getEmojiByID(id); if (emoji != null) { emoji.setName(json.name); emoji.setRoles(roles); return emoji; } Cache<IRole> roleCache = new Cache<>((DiscordClientImpl) guild.getClient(), IRole.class); roleCache.putAll(roles); return new EmojiImpl(id, guild, json.name, roleCache, json.require_colons, json.managed, json.animated); }
private void guildRoleUpdate(GuildRoleEventResponse event) { IGuild guild = client.getGuildByID(Long.parseUnsignedLong(event.guild_id)); if (guild != null) { IRole toUpdate = guild.getRoleByID(Long.parseUnsignedLong(event.role.id)); if (toUpdate != null) { IRole oldRole = toUpdate.copy(); toUpdate = DiscordUtils.getRoleFromJSON(guild, event.role); client.dispatcher.dispatch(new RoleUpdateEvent(oldRole, toUpdate)); if (guild.getRolesForUser(client.getOurUser()).contains(toUpdate)) ((Guild) guild).loadWebhooks(); } } }
/** * 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; }
if (client.getOurUser().getRolesForGuild(channel.getGuild()).contains(channel.getGuild().getRoleByID(Long.parseUnsignedLong(role)))) { mentioned = true; break;
/** * Converts a json {@link RoleObject} to a {@link IRole}. This method first checks the internal role cache * and returns that object with updated information if it exists. Otherwise, it constructs a new role. * * @param guild The guild the role belongs to. * @param json The json object representing the role. * @return The converted role object. */ public static IRole getRoleFromJSON(IGuild guild, RoleObject json) { Role role; if ((role = (Role) guild.getRoleByID(Long.parseUnsignedLong(json.id))) != null) { role.setColor(json.color); role.setHoist(json.hoist); role.setName(json.name); role.setPermissions(json.permissions); role.setPosition(json.position); role.setMentionable(json.mentionable); } else { role = new Role(json.position, json.permissions, json.name, json.managed, Long.parseUnsignedLong(json.id), json.hoist, json.color, json.mentionable, guild); ((Guild) guild).roles.put(role); } return role; }
case ROLE_CREATE: case ROLE_UPDATE: IRole role = guild.getRoleByID(targetID);