Пример #1
0
 public GenericEventContext(Event event) {
   timestamp = System.currentTimeMillis();
   clazz = event.getClass();
   Method[] methods = clazz.getMethods();
   for (Method m : methods) {
     try {
       if (m.getName().equalsIgnoreCase("getUser")) user = (IUser) m.invoke(event);
       else if (m.getName().equalsIgnoreCase("getChannel")) {
         channel = new RateLimitedChannel((IChannel) m.invoke(event));
         guild = channel.getGuild();
       } else if (m.getName().equalsIgnoreCase("getMessage")) {
         msg = (IMessage) m.invoke(event);
         user = msg.getAuthor();
         channel = new RateLimitedChannel(msg.getChannel());
         guild = channel.getGuild();
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
 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());
 }