Exemplo n.º 1
0
  private void ban(MessageContext context, String args) {
    if (args.isEmpty()) {
      return;
    }
    String[] split = args.split(" ");
    List<String> banned = new ArrayList<>();
    List<String> failed = new ArrayList<>();
    Channel channel = context.getChannel();
    for (String userStr : split) {
      User user = findUser(context, userStr);
      String userId = user.getId();
      if (user == NO_USER) {
        userId = userStr;
      }

      if (banChecked(channel, context.getAuthor(), user, context.getServer())) {
        banned.add(userId + " " + user.getUsername());
      } else {
        failed.add(userId + " " + user.getUsername());
      }
    }

    if (channel.getId() != null) {
      StringJoiner joiner = new StringJoiner("\n");
      for (String s : banned) {
        String[] pair = s.split(" ", 2);
        joiner.add(loc.localize("commands.mod.ban.response", pair[1], pair[0]));
      }
      apiClient.sendMessage(joiner.toString(), channel);
    }
  }
Exemplo n.º 2
0
 private void setDnTrackChannel(MessageContext context, String args) {
   if (context.getServer() == null || context.getServer() == NO_SERVER) {
     return;
   }
   String serverId = context.getServer().getId();
   TempServerConfig config = serverStorage.get(serverId);
   if (config == null) {
     config = new TempServerConfig(serverId);
     serverStorage.put(serverId, config);
   }
   Channel channel = context.getChannel();
   if (args.equalsIgnoreCase("off")) {
     config.setDnTrackChannel(null);
     apiClient.sendMessage(loc.localize("commands.mod.dntrack.response.none"), channel);
   } else {
     config.setDnTrackChannel(channel.getId());
     apiClient.sendMessage(loc.localize("commands.mod.dntrack.response.set"), channel);
   }
   saveServerConfig(config);
 }
Exemplo n.º 3
0
 private void joinLeave(MessageContext context, String args) {
   if (args.isEmpty()) {
     return;
   }
   args = args.toLowerCase();
   String[] split = args.split(" ");
   String cid = split[0];
   JoinLeave target = JoinLeave.BOTH;
   if (split.length != 1) {
     String jlStr = split[1].toLowerCase();
     for (JoinLeave joinLeave : JoinLeave.values()) {
       if (joinLeave.name().toLowerCase().startsWith(jlStr)) {
         target = joinLeave;
         break;
       }
     }
   }
   if ("default".equals(cid)) {
     cid = context.getServer().getId();
   } else if ("this".equals(cid)) {
     cid = context.getChannel().getId();
   }
   Channel channel = apiClient.getChannelById(cid);
   if (channel != NO_CHANNEL) {
     if (target == JoinLeave.JOIN) {
       bot.getEventListener().joinMessageRedirect.put(context.getServer().getId(), cid);
     }
     if (target == JoinLeave.LEAVE) {
       bot.getEventListener().leaveMessageRedirect.put(context.getServer().getId(), cid);
     }
     if (target == JoinLeave.BOTH) {
       bot.getEventListener().joinMessageRedirect.put(context.getServer().getId(), cid);
       bot.getEventListener().leaveMessageRedirect.put(context.getServer().getId(), cid);
     }
     apiClient.sendMessage(
         loc.localize("commands.mod.jl.response", channel.getName(), channel.getId()),
         context.getChannel());
   } else {
     apiClient.sendMessage(loc.localize("commands.mod.jl.response.invalid"), context.getChannel());
   }
 }