Ejemplo n.º 1
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(", "));
 }
Ejemplo n.º 2
0
 private String editGuildPermission(Operation op, Permission permission, IGuild guild) {
   DiscordGuild g =
       cacheService.findGuildById(guild.getID()).orElseGet(() -> new DiscordGuild(guild));
   changePermission(op, permission, g);
   g = cacheService.saveGuild(g);
   log.info("Saving new guild permission settings: {}", g);
   permissionService.evict();
   return String.format(
       "Modified server %s: %s permission %s",
       g.getName(), op.name().toLowerCase(), permission.getName());
 }