コード例 #1
0
 private String editRolePermission(Operation op, Permission permission, IRole role) {
   IGuild parent = role.getGuild();
   DiscordGuild g =
       cacheService.findGuildById(parent.getID()).orElseGet(() -> new DiscordGuild(parent));
   DiscordRole edit = null;
   for (DiscordRole r : g.getRoles()) {
     if (r.getId().equals(role.getID())) {
       edit = r;
       break;
     }
   }
   if (edit == null) {
     edit = new DiscordRole(role);
     g.getRoles().add(edit);
   }
   if (edit.getName() == null) {
     edit.setName(role.getName());
   }
   changePermission(op, permission, edit);
   g = cacheService.saveGuild(g);
   log.info("Saving new guild/role permission settings: {}", g);
   permissionService.evict();
   return String.format(
       "Modified role %s: %s permission %s",
       edit.getName(), op.name().toLowerCase(), permission.getName());
 }
コード例 #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(", "));
 }
コード例 #3
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());
 }
コード例 #4
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());
 }
コード例 #5
0
 private String editChannelPermission(Operation op, Permission permission, IChannel channel) {
   if (channel.isPrivate()) {
     throw new IllegalArgumentException("No private channels allowed!");
   }
   DiscordGuild g =
       cacheService
           .findGuildById(channel.getGuild().getID())
           .orElseGet(() -> new DiscordGuild(channel.getGuild()));
   g = cacheService.saveGuild(g);
   DiscordChannel ch =
       cacheService.findChannelById(channel.getID()).orElseGet(() -> new DiscordChannel(channel));
   ch.setGuild(g);
   g.getChannels().add(ch);
   changePermission(op, permission, ch);
   ch = cacheService.saveChannel(ch);
   cacheService.saveGuild(g);
   log.info("Saving new permission data: {}", g);
   permissionService.evict();
   return String.format(
       "Modified channel %s: %s permission %s",
       ch.getName(), op.name().toLowerCase(), permission.getName());
 }