Esempio n. 1
0
  @Override
  public void execute(final MessageEvent event, final String[] args) {
    User sender = event.getUser();
    Channel channel = event.getChannel();

    if (!System.getProperty("os.name").toLowerCase().contains("win")) {
      try {
        int unixTime =
            Integer.parseInt(
                new Scanner(new FileInputStream("/proc/uptime"))
                    .next()
                    .replaceAll("\\.[0-9]+", ""));
        int day = (int) TimeUnit.SECONDS.toDays(unixTime);
        long hours = TimeUnit.SECONDS.toHours(unixTime) - (day * 24);
        long minute =
            TimeUnit.SECONDS.toMinutes(unixTime) - (TimeUnit.SECONDS.toHours(unixTime) * 60);
        long seconds =
            TimeUnit.SECONDS.toSeconds(unixTime) - (TimeUnit.SECONDS.toMinutes(unixTime) * 60);

        channel
            .send()
            .message(
                Utils.colourise(
                    String.format(
                        "&2System uptime: &r%s days %s hours %s minutes %s seconds",
                        day, hours, minute, seconds)));
      } catch (FileNotFoundException ex) {
        sender.send().notice("File \"/proc/uptime\" not found. Are you sure you're using Linux?");
      }
      return;
    }
    sender.send().notice("This command is only supported on Unix based systems.");
  }
Esempio n. 2
0
  @Override
  public void execute(final MessageEvent event, final String[] args) {
    User sender = event.getUser();

    if (args.length == 1) {
      if (args[0].equalsIgnoreCase("list")) {
        List<String> tells = foxbot.getDatabase().getTells(sender.getNick(), true);

        if (!tells.isEmpty()) {
          for (String tell : tells) {
            foxbot.sendNotice(sender, Utils.colourise(tell));
          }
          return;
        }
        foxbot.sendNotice(sender, "No messages for you :<");
        return;
      }

      if (args[0].equalsIgnoreCase("clean")) {
        foxbot.getDatabase().cleanTells(sender.getNick());
        foxbot.sendNotice(sender, "Deleted all of your read messages.");
        return;
      }
    }

    if (args.length > 1) {
      String nick = args[0];

      StringBuilder message = new StringBuilder(args[1]);

      for (int arg = 2; arg < args.length; arg++) {
        message.append(" ").append(args[arg]);
      }

      foxbot.getDatabase().addTell(sender.getNick(), nick, message.toString());
      foxbot.sendNotice(sender, String.format("Tell added for %s", nick));
      return;
    }
    foxbot.sendNotice(
        sender,
        String.format(
            "Wrong number of args! Use %stell <nick> <message> or %stell list",
            foxbot.getConfig().getCommandPrefix(), foxbot.getConfig().getCommandPrefix()));
  }
  @Override
  public void execute(MessageEvent event, String[] args) {
    User sender = event.getUser();
    Channel channel = event.getChannel();

    if (args.length > 0) {
      String plugin = args[0].toLowerCase();
      String url =
          String.format(
              "http://api.bukget.org/3/search/plugin_name/like/%s%s",
              plugin, (args.length) == 1 ? "" : ("?size=" + args[1]));

      Connection conn =
          Jsoup.connect(url).timeout(500).followRedirects(true).ignoreContentType(true);
      String json;

      try {
        json = conn.get().text();
      } catch (IOException ex) {
        foxbot.log(ex);
        channel
            .send()
            .message(
                Utils.colourise(
                    String.format(
                        "(%s) &cAn error occurred while querying the Bukget API!",
                        Utils.munge(sender.getNick()))));
        return;
      }

      if (json.equals("[]")) {
        channel
            .send()
            .message(
                Utils.colourise(
                    String.format("(%s) &cNo results found!", Utils.munge(sender.getNick()))));
        return;
      }

      JSONArray jsonArray = new JSONArray(json);
      JSONObject found = null;

      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        String name = jsonObject.getString("plugin_name");

        if (name.equalsIgnoreCase(plugin)) {
          found = jsonObject;
          break;
        }
      }

      if (found == null) {
        found = jsonArray.getJSONObject(0);
      }

      String name = found.getString("plugin_name");
      String description = found.getString("description");
      String pluginUrl =
          String.format("http://dev.bukkit.org/bukkit-plugins/%s/", found.getString("slug"));

      if (description.isEmpty()) {
        description = "No description";
      }

      channel
          .send()
          .message(
              Utils.colourise(
                  String.format(
                      "(%s) &2Name:&r %s &2Description:&r %s &2URL:&r %s",
                      Utils.munge(sender.getNick()), name, description, pluginUrl)));
      return;
    }
    foxbot.sendNotice(
        sender,
        String.format(
            "Wrong number of args! Use %sbukkitsearch <plugin>",
            foxbot.getConfig().getCommandPrefix()));
  }