Ejemplo n.º 1
0
 private String editUserPermission(Operation op, Permission permission, IUser user) {
   DiscordUser u = cacheService.findUserById(user.getID()).orElseGet(() -> new DiscordUser(user));
   changePermission(op, permission, u);
   u = cacheService.saveUser(u);
   log.info("Saving new user permission settings: {}", u);
   permissionService.evict();
   return String.format(
       "Modified user %s: %s permission %s",
       u.getName(), op.name().toLowerCase(), permission.getName());
 }
Ejemplo n.º 2
0
 private String listPermissions(IMessage message, Permission permission, List<String> args) {
   List<String> matches = new ArrayList<>();
   // TODO narrow search by following args
   for (DiscordGuild guild : cacheService.findAllGuilds()) {
     if (guild.getDenied().contains(permission)) {
       matches.add(
           String.format(
               "deny everyone in guild %s (%s)", nullAsEmpty(guild.getName()), guild.getId()));
     } else if (guild.getAllowed().contains(permission)) {
       matches.add(
           String.format(
               "allow anyone in guild %s (%s)", nullAsEmpty(guild.getName()), guild.getId()));
     }
     for (DiscordRole role : guild.getRoles()) {
       if (role.getDenied().contains(permission)) {
         matches.add(
             String.format(
                 "deny everyone with role %s (%s) in guild %s (%s)",
                 nullAsEmpty(role.getName()),
                 role.getId(),
                 nullAsEmpty(guild.getName()),
                 guild.getId()));
       } else if (role.getAllowed().contains(permission)) {
         matches.add(
             String.format(
                 "allow anyone with role %s (%s) in guild %s (%s)",
                 nullAsEmpty(role.getName()),
                 role.getId(),
                 nullAsEmpty(guild.getName()),
                 guild.getId()));
       }
     }
   }
   for (DiscordChannel channel : cacheService.findAllChannels()) {
     if (channel.getDenied().contains(permission)) {
       matches.add(
           String.format(
               "deny everyone in channel %s (%s)",
               nullAsEmpty(channel.getName()), channel.getId()));
     } else if (channel.getAllowed().contains(permission)) {
       matches.add(
           String.format(
               "allow anyone in channel %s (%s)",
               nullAsEmpty(channel.getName()), channel.getId()));
     }
   }
   for (DiscordUser user : cacheService.findAllUsers()) {
     if (user.getDenied().contains(permission)) {
       matches.add(String.format("deny user %s (%s)", nullAsEmpty(user.getName()), user.getId()));
     } else if (user.getAllowed().contains(permission)) {
       matches.add(String.format("allow user %s (%s)", nullAsEmpty(user.getName()), user.getId()));
     }
   }
   if (permission.isDefaultAllow()) {
     matches.add("allow if not previously denied");
   }
   return matches.stream().collect(Collectors.joining(", "));
 }