コード例 #1
0
ファイル: ModuleRSS.java プロジェクト: BigRenegade/Shocky
 public void newEntries(Feed feed, Iterable<FeedEntry> entries) throws InterruptedException {
   for (String s : feed.channels) {
     Channel channel = Shocky.getChannel(s);
     if (channel == null) return;
     PircBotX bot = channel.getBot();
     for (FeedEntry entry : entries) {
       Shocky.sendChannel(bot, channel, Utils.mungeAllNicks(channel, 0, "RSS: " + entry));
       Thread.sleep(2000);
     }
   }
 }
コード例 #2
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);
      }
    }
  }
コード例 #3
0
ファイル: ModuleRSS.java プロジェクト: BigRenegade/Shocky
    public void doCommand(Parameters params, CommandCallback callback) {
      String action = null;
      URL url = null;
      long interval = (5 * 60 * 1000);
      Channel c = null;
      callback.type = EType.Notice;

      try {
        if (params.type == EType.Channel) {
          if (params.tokenCount == 0) {
            c = params.channel;
          } else if (params.tokenCount == 1) {
            c = Shocky.getChannel(params.nextParam());
          } else if (params.tokenCount == 2) {
            action = params.nextParam();
            c = params.channel;
            url = new URL(params.nextParam());
          } else if (params.tokenCount == 3) {
            action = params.nextParam();
            String s = params.nextParam();
            if (s.startsWith("#")) c = Shocky.getChannel(s);
            else {
              interval = Utils.parseInterval(s);
              c = params.channel;
            }
            url = new URL(params.nextParam());
          } else if (params.tokenCount == 4) {
            action = params.nextParam();
            interval = Utils.parseInterval(params.nextParam());
            c = Shocky.getChannel(params.nextParam());
            url = new URL(params.nextParam());
          }
          if (c == null) {
            callback.append("No such channel");
            return;
          }
        } else {
          if (params.tokenCount == 1) {
            c = Shocky.getChannel(params.nextParam());
          } else if (params.tokenCount == 3) {
            action = params.nextParam();
            c = Shocky.getChannel(params.nextParam());
            url = new URL(params.nextParam());
          }
          if (c == null) {
            callback.append("No such channel");
            return;
          }
        }
      } catch (MalformedURLException e) {
        callback.append("Malformed URL");
        return;
      }
      if (action != null) params.checkOp();

      if (action == null) {
        StringBuffer sb = new StringBuffer();
        for (Feed feed : feeds) {
          if (!feed.channels.contains(c.getName())) continue;
          if (sb.length() != 0) sb.append("\n");
          sb.append(feed.getURL()).append(' ').append(Utils.timeAgo(feed.getInterval() / 1000));
        }
        callback.append(sb);
      } else if (action.equals("add")) {
        for (Feed feed : feeds) {
          if (feed.getURL().equals(url)) {
            if (feed.channels.contains(c.getName())) {
              callback.append("Feed already on channel's list");
            } else {
              feed.channels.add(c.getName());
              callback.append("Added");
            }
            return;
          }
        }
        if (interval < 300) interval = 300;
        interval *= 1000;
        feeds.add(new Feed(url, interval, null, c.getName()));
        callback.append("Added");
        startUpdater();
      } else if (action.equals("remove")) {
        Iterator<Feed> iter = feeds.iterator();
        boolean modified = false;
        try {
          while (iter.hasNext()) {
            Feed feed = iter.next();
            if (feed.getURL().equals(url)) {
              if (feed.channels.contains(c.getName())) {
                feed.channels.remove(feed.channels.indexOf(c.getName()));
                if (feed.channels.isEmpty()) {
                  iter.remove();
                  modified = true;
                }
                callback.append("Removed");
              } else callback.append("Feed isn't on channel's list");
              return;
            }
          }
          callback.append("Feed isn't on channel's list");
        } finally {
          if (modified) startUpdater();
        }
      }
    }
コード例 #4
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();
    }
  }