コード例 #1
0
ファイル: ModuleHighFive.java プロジェクト: Cazzar/Shocky
  public void onMessage(MessageEvent<ShockyBot> event) {
    if (Data.isBlacklisted(event.getUser())) return;
    String msg = event.getMessage();
    if (!pattern.matcher(msg).find()) return;

    String chan = event.getChannel().getName();
    Long time = timers.get(chan);
    User s = started.get(chan);

    if (s != null && time != null && time < System.currentTimeMillis()) {
      started.remove(chan);
      timers.remove(chan);
      s = null;
    }

    if (s == null) {
      time = System.currentTimeMillis() + Data.forChannel(event.getChannel()).getInt("hf-maxtime");
      // event.respond(String.format("Will expired at %s",
      // DateFormat.getDateTimeInstance().format(new Date(time))));
      started.put(chan, event.getUser());
      timers.put(chan, time);
    } else {
      int stat = changeStat(s.getNick(), event.getUser().getNick(), 1);
      if (stat != 0) {
        if (event.getChannel().isOp(event.getBot().getUserBot())
            && stat >= Data.forChannel(event.getChannel()).getInt("hf-kickat")) {
          stat = changeStat(s.getNick(), event.getUser().getNick(), -stat);
          msg = s.getNick() + " o/ * \\o " + event.getUser().getNick() + " - have been kicked!";
          event.getBot().kick(event.getChannel(), s);
          event.getBot().kick(event.getChannel(), event.getUser());
          if (Data.forChannel(event.getChannel()).getBoolean("hf-announce"))
            Shocky.sendChannel(event.getBot(), event.getChannel(), msg);
          else {
            Shocky.sendNotice(event.getBot(), event.getUser(), msg);
            Shocky.sendNotice(event.getBot(), s, msg);
          }
        } else {
          msg =
              s.getNick()
                  + " o/ * \\o "
                  + event.getUser().getNick()
                  + " - "
                  + getOrderNumber(stat)
                  + " time";
          if (Data.forChannel(event.getChannel()).getBoolean("hf-announce"))
            Shocky.sendChannel(event.getBot(), event.getChannel(), msg);
          else {
            Shocky.sendNotice(event.getBot(), event.getUser(), msg);
            Shocky.sendNotice(event.getBot(), s, msg);
          }
        }

        started.remove(chan);
        timers.remove(chan);
      }
    }
  }
コード例 #2
0
  @Override
  public void onMessage(MessageEvent<PircBotX> event) throws Exception {
    if (Data.isBlacklisted(event.getUser())) return;
    IRollback module = (IRollback) Module.getModule("rollback");
    if (module == null) return;
    String s = event.getMessage().trim();
    if (!s.startsWith("s/") && !s.startsWith("m/")) return;
    String[] args = s.split("(?<!\\\\)/", -1);
    boolean replace = args[0].contentEquals("s");
    if (!replace && event.getChannel().getMode().contains("c")) return;

    int flagPos = 2;
    if (replace) flagPos = 3;

    if (args.length != flagPos + 1) return;
    if (args[1].isEmpty()) return;

    String[] params = args[flagPos].split(" ", -1);
    String user = null;

    int flags = 0;
    boolean single = true;
    if (params.length > 0) {
      for (char c : params[0].toCharArray()) {
        switch (c) {
          case 'd':
            flags |= Pattern.UNIX_LINES;
            break;
          case 'g':
            single = false;
            break;
          case 'i':
            flags |= Pattern.CASE_INSENSITIVE;
            break;
          case 'm':
            flags |= Pattern.MULTILINE;
            break;
          case 's':
            flags |= Pattern.DOTALL;
            break;
          case 'u':
            flags |= Pattern.UNICODE_CASE;
            break;
          case 'x':
            flags |= Pattern.COMMENTS;
            break;
        }
      }

      if (params.length > 1) user = params[1];
    }
    Matcher matcher;
    try {
      Pattern pattern = Pattern.compile(args[1], flags);
      matcher = pattern.matcher("");
    } catch (PatternSyntaxException e) {
      Shocky.sendChannel(
          event.getBot(), event.getChannel(), StringTools.deleteWhitespace(e.getMessage()));
      return;
    }
    ArrayList<LineWithUsers> lines =
        module.getRollbackLines(
            LineWithUsers.class, event.getChannel().getName(), user, null, s, true, 10, 0);

    final ExecutorService service = Executors.newFixedThreadPool(1);
    try {
      Future<String> run =
          service.submit(new Run(lines, matcher, single, replace ? args[2] : null));
      String output = run.get(5, TimeUnit.SECONDS);
      if (output != null) Shocky.sendChannel(event.getBot(), event.getChannel(), output);
    } catch (TimeoutException e) {
    } finally {
      service.shutdown();
    }
  }