コード例 #1
0
    @Override
    public String call() throws Exception {
      boolean found = false;
      StringBuffer sb = new StringBuffer();
      for (int i = lines.size() - 1; i >= 0 && !found; i--) {
        LineWithUsers line = lines.get(i);
        String text;
        if (line instanceof LineMessage) text = ((LineMessage) line).text;
        else if (line instanceof LineAction) text = ((LineAction) line).text;
        else continue;
        if (replacement == null) text = Colors.removeFormattingAndColors(text);
        matcher.reset(text);
        while (matcher.find() && !(single && found)) {
          found = true;
          if (replacement != null) matcher.appendReplacement(sb, replacement);
          else {
            String capture = matcher.group();
            char[] chars = capture.toCharArray();
            StringBuilder sb2 = new StringBuilder();
            Stack<Integer> color = new Stack<Integer>();
            int last = -1;
            for (int o = 0; o <= chars.length; o++) {
              for (int p = 0; p <= matcher.groupCount(); p++) {
                int s = matcher.start(p) - matcher.start();
                int e = matcher.end(p) - matcher.start();
                if (o == s) color.push(p);
                else if (o == e) color.pop();
              }

              if (color.isEmpty() && last != -1) {
                last = -1;
                sb2.append(Colors.NORMAL);
              } else if (!color.isEmpty() && last != color.peek()) {
                sb2.append(groupColors[color.peek() % groupColors.length]);
                last = color.peek();
              }

              if (o < chars.length) sb2.append(chars[o]);
            }
            matcher.appendReplacement(sb, sb2.toString());
          }
        }
        if (found) {
          matcher.appendTail(sb);
          if (line instanceof LineAction) {
            sb.insert(0, "ACTION ");
            sb.insert(0, '\001');
            sb.append('\001');
          }
          return StringTools.limitLength(sb);
        }
      }
      return null;
    }
コード例 #2
0
 @Override
 public void onMessage(MessageEvent event) {
   if (Config.LOGGED_CHANS.contains(event.getChannel().getName())) {
     String message =
         String.format(
             "%s %s: %s",
             Utils.getTime(),
             event.getUser().getNick(),
             Colors.removeFormattingAndColors(event.getMessage()));
     log(event.getChannel().getName(), message);
   }
 }