/** * Determines if user1 is higher in the role hierarchy than user2 in the given guild. * This is determined by the positions of each of the users' highest roles. * * @param guild The guild both users belongs to. * @param user1 The user who must be higher in the role hierarchy. * @param user2 The user who must be lower in the role hierarchy. * @return True if user1 is higher in the role hierarchy than user2. */ public static boolean isUserHigher(IGuild guild, IUser user1, IUser user2) { if (guild.getOwner().equals(user1)) return true; if (guild.getOwner().equals(user2)) return false; return hasHigherRoles(guild.getRolesForUser(user1), guild.getRolesForUser(user2)); }
/** * Determines if the given user is higher in the role hierarchy than all of the given roles. * This is determined by the position of the user's highest role and the position of the highest role in roles. * * @param guild The guild the user and roles belong to. * @param user The user who must be higher in the role hierarchy. * @param roles The roles which must be lower in the role hierarchy. * @return True if the user is higher in the role hierarchy than every role in roles. */ public static boolean isUserHigher(IGuild guild, IUser user, List<IRole> roles) { if (guild.getOwner().equals(user)) return true; return hasHigherRoles(guild.getRolesForUser(user), roles); }
@Override public EnumSet<Permissions> getPermissionsForGuild(IGuild guild) { if (guild.getOwner().equals(this)) { return EnumSet.allOf(Permissions.class); } IRole everyone = guild.getEveryoneRole(); EnumSet<Permissions> permissions = everyone.getPermissions(); for (IRole role : guild.getRolesForUser(this)) { permissions.addAll(role.getPermissions()); } if (permissions.contains(Permissions.ADMINISTRATOR)) { return EnumSet.allOf(Permissions.class); } return permissions; }
EnumSet<Permissions> deny = EnumSet.noneOf(Permissions.class); for (IRole role : guild.getRolesForUser(user)) { PermissionOverride roleOverride = roleOverrides.get(role.getLongID()); if (roleOverride != null) {
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(); } } }
private void messageUpdate(MessageObject json) { Channel channel = (Channel) client.getChannelByID(Long.parseUnsignedLong(json.channel_id)); if (channel == null) return; IMessage toUpdate = channel.messages.get(json.id); if (toUpdate == null) { // Cannot resolve update type. MessageObject is incomplete, so we'll have to request for the full message. if (channel.isPrivate() || PermissionUtils.hasHierarchicalPermissions(channel, client.ourUser, channel.getGuild().getRolesForUser(client.ourUser), Permissions.READ_MESSAGE_HISTORY)) client.dispatcher.dispatch(new MessageUpdateEvent(null, channel.fetchMessage(Long.parseUnsignedLong(json.id)))); // else //FIXME: unable to fire message update events when the user doesn't have the read message history permission } else { IMessage oldMessage = toUpdate.copy(); IMessage updatedMessage = DiscordUtils.getUpdatedMessageFromJSON(client, toUpdate, json); if (json.pinned != null && oldMessage.isPinned() && !json.pinned) { client.dispatcher.dispatch(new MessageUnpinEvent(oldMessage, updatedMessage)); } else if (json.pinned != null && !oldMessage.isPinned() && json.pinned) { client.dispatcher.dispatch(new MessagePinEvent(oldMessage, updatedMessage)); } else if (oldMessage.getEmbeds().size() < updatedMessage.getEmbeds().size()) { client.dispatcher.dispatch(new MessageEmbedEvent(oldMessage, updatedMessage, oldMessage.getEmbeds())); } else if (json.content != null && !oldMessage.getContent().equals(json.content)) { client.dispatcher.dispatch(new MessageEditEvent(oldMessage, updatedMessage)); } else { client.dispatcher.dispatch(new MessageUpdateEvent(oldMessage, updatedMessage)); } } }