@Override public Member getMember() { return message.getMember(); }
public CommandMessage(CommandContainer container, DatabaseEventHolder databaseEventHolder, Message message, boolean mentionableCommand, String[] aliasArguments) { if (container != null) { setI18nCommandPrefix(container); } this.message = message; this.guild = message.getGuild(); this.member = message.getMember(); this.channel = message.getTextChannel(); this.databaseEventHolder = databaseEventHolder; this.mentionableCommand = mentionableCommand; this.aliasArguments = aliasArguments.length == 0 ? null : String.join(" ", aliasArguments); }
/** * Creates a new permission check instance for the current message. * * @param message The message that invoked the middleware stack. * @param args The arguments parsed to the middleware. */ public PermissionCheck(@Nonnull Message message, String[] args) { this.isUserAdmin = message.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission()); this.type = PermissionType.fromName(args[0]); this.message = message; this.args = args; if (isUserAdmin) { userHasAtleastOne = true; } }
/** * Checks if the user can interact with the given role by making sure the role * is not higher in the role hierarchy than any role the user has, if the * method returns true the user has at least one role which is in a * higher position in the role hierarchy. * <p> * <strong>Note:</strong> If the user is the owner of the current guild, * this method will always return {@code true}. * * @param message The JDA message instance for the current guild. * @param role The role that the user should be able to interact with. * @return {@code True} if the user can interact with the given role, {@code False} otherwise */ public static boolean canUserInteractWithRole(@Nonnull Message message, @Nonnull Role role) { if (message.getMember().isOwner()) { return true; } if (!RoleUtil.isRoleHierarchyHigher(message.getMember().getRoles(), role)) { return true; } MessageFactory.makeWarning(message, ":user The **:role** role is positioned higher in the hierarchy than any role you have, you can't add roles with a higher ranking than you have." ).set("role", role.getName()).queue(); return false; }
if (!isUserAdmin && type.isCheckUser() && !message.getMember().hasPermission(permission.getPermission())) { missingUserPermissions.add(permission);
@Override public boolean handle(@Nonnull Message message, @Nonnull MiddlewareStack stack, String... args) { if (!message.getChannelType().isGuild()) { return stack.next(); } if (message.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission())) { return stack.next(); } List<Role> roles = message.getMember().getRoles(); for (String roleName : args) { if (hasRole(roles, roleName)) { return stack.next(); } } return runMessageCheck(message, () -> { MessageFactory.makeError(message, "You don't have any of the required roles to execute this command:\n`:role`") .set("role", String.join("`, `", args)) .queue(newMessage -> newMessage.delete().queueAfter(45, TimeUnit.SECONDS, null, RestActionUtil.ignore)); return false; }); }
@Override public boolean handle(@Nonnull Message message, @Nonnull MiddlewareStack stack, String... args) { if (!message.getChannelType().isGuild()) { return stack.next(); } if (message.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission())) { return stack.next(); } List<Role> roles = message.getMember().getRoles(); for (String roleName : args) { if (!hasRole(roles, roleName)) { return runMessageCheck(message, () -> { MessageFactory.makeError(message, "You don't have the required role to execute this command:\n`:role`") .set("role", roleName) .queue(newMessage -> newMessage.delete().queueAfter(45, TimeUnit.SECONDS)); return false; }); } } return stack.next(); }