Ejemplo 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.");
  }
Ejemplo n.º 2
0
 public void onMessage(MessageEvent event) throws IOException {
   if (event.getMessage().equals("!news")) {
     String news = event.getMessage().replace("!news", "");
     File file = new File("test.txt");
     FileUtils.writeStringToFile(file, news);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void onCommand(MessageEvent evt, String... params) {
   String server = evt.getBot().getConfiguration().getServerHostname();
   if (params.length == 0) {
     String out = "";
     System.out.println(server);
     for (Command c : Command.commands) {
       boolean isUserAdmin = false;
       if (UserPermissions.isLevel(evt.getUser().getNick(), DataUser.ADMIN, server)) {
         isUserAdmin = true;
       }
       if ((c.adminCommand && isUserAdmin) || (!c.adminCommand)) {
         out += c.aliases[0] + ", ";
       }
     }
     out = out.substring(0, out.length() - 2) + ".";
     notice(evt, "Topics: " + out);
     sendUsage(evt);
     return;
   }
   if (params.length == 1) {
     String topic = params[0];
     for (Command c : Command.commands) {
       boolean isUserAdmin = false;
       if (UserPermissions.isLevel(evt.getUser().getNick(), DataUser.ADMIN, server)) {
         isUserAdmin = true;
       }
       if ((c.adminCommand && isUserAdmin) || (!c.adminCommand)) {
         if (topic.equalsIgnoreCase(c.aliases[0])) {
           notice(evt, topic + ": " + c.help());
         }
       }
     }
   }
 }
Ejemplo n.º 4
0
  @Override
  public void onMessage(MessageEvent event) throws Exception {
    if (!event.getMessage().startsWith(COMMAND_PREFIX)) return;

    String message = event.getMessage();
    String username = event.getUser().getNick();
    logger.info("Received command message '{}' from '{}'", message, username);

    String command = message.split("\\s+")[0].toLowerCase();

    if (command.equals(TIME_COMMAND)) {
      logger.info("Recognized command '{}'", command);
      if (commandThrottler.throttleCommand(command)) {
        logger.info("Throttled command '{}'", command);
      } else {
        logger.info("Responding to command '{}'", command);
        event.getChannel().send().message(getTimeString());
        logger.info("Tracking usage of command '{}'", command);
        commandThrottler.trackCommandUsage(command);
      }
    } else if (command.equals(VERSION_COMMAND)) {
      logger.info("Recognized command '{}'", command);
      if (commandThrottler.throttleCommand(command)) {
        logger.info("Throttled command '{}'", command);
      } else {
        logger.info("Responding to command '{}'", command);
        event.getChannel().send().action(getVersionString());
        logger.info("Tracking usage of command '{}'", command);
        commandThrottler.trackCommandUsage(command);
      }
    } else {
      logger.info("Unrecognized command '{}'", command);
    }
  }
Ejemplo n.º 5
0
 @Override
 public boolean execute(MessageEvent event) throws Exception {
   if (event.getUser() == null) {
     return false;
   }
   if (PermissionManager.hasExec(event.getUser().getNick())) {
     String[] args = event.getMessage().split(" ");
     if (args.length == 2 && args[1].length() == 1) {
       String oldtrigger = config.getTrigger();
       config.setTrigger(args[1]);
       if (config.useDatabase)
         Main.database
             .prepareStatement(
                 "UPDATE `Bot` SET `Bot_Trigger` = '"
                     + config.getTrigger()
                     + "' WHERE `Bot`.`Nick` = '"
                     + event.getBot().getUserBot().getNick()
                     + "';")
             .execute();
       MessageUtils.sendUserNotice(
           event, "Bot prefix was set to " + config.getTrigger() + " from " + oldtrigger);
       return true;
     } else {
       return false;
     }
   } else {
     event.respond("You need to be Exec to change prefix!");
   }
   return false;
 }
Ejemplo n.º 6
0
  // Channel commands
  public void onMessage(MessageEvent event) throws Exception {
    String message = event.getMessage();
    String[] seperated;
    if (event.getMessage().contains(" ")) seperated = event.getMessage().split(" ");
    else seperated = new String[] {event.getMessage()};

    // If it's a command, let's execute it!
    if (commandMap.containsKey(seperated[0])) {
      String commandString = seperated[0];
      Method method = commandMap.get(commandString);
      ChannelCommand command = method.getAnnotation(ChannelCommand.class);

      // Build args
      String[] args = buildArgs(seperated);

      // Execute command. (null represents object to invoke on, since method is static no object)
      // Check permissions
      if (hasPermission(command.permissionLevel(), event.getUser(), event.getChannel())) {
        if (args.length < command.minArgs()) {
          event.respond("Not enough arguements! Usage: " + command.usage());
        } else if (args.length > command.maxArgs()) {
          event.respond("Too many arguements! Usage: " + command.usage());
        } else {
          // Okay, everything's all good, lets run the command!
          method.invoke(null, event, args);
        }
      } else {
        event.respond("You do not have permission to execute this command!");
      }
    }
  }
Ejemplo n.º 7
0
 public void onMessage(MessageEvent event) {
   if (event.getMessage().toLowerCase().contains("!shirt")
       && !event.getUser().getNick().equals(Constants.NICK)) {
     event
         .getChannel()
         .send()
         .message(
             "Check out http://shirt.raysfi.re/ for your chance to get an exclusive, limited-edition raysfire"
                 + " zip-up hoodie!");
   }
 }
Ejemplo n.º 8
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);
   }
 }
Ejemplo n.º 9
0
 @Override
 public void onMessage(MessageEvent<Cardinal> event) throws Exception {
   CommandSender sender =
       new CommandSender(event.getChannel(), event.getUser(), event.getBot().getUserBot());
   String message = event.getMessage();
   if (Cardinal.logToFile) Cardinal.SYSO(message);
   if (message.startsWith(CMD_PREFIX)) {
     String args[] = message.substring(CMD_PREFIX.length()).split(" ");
     if (commands.containsKey(args[0])) {
       commands.get(args[0]).run(sender, shrinkArgs(args));
     }
   }
 }
Ejemplo n.º 10
0
  public void handleMessage(MessageEvent<JircBotX> event) throws Exception {
    if (event.getMessage().toLowerCase().startsWith("!temp")) {
      // Retrieve the current Hive13 temperature
      double dSpaceTemp = getTemperatureFromRSS();

      // Retrieve the current local temperature
      double dLocalTemp = WUndergroundAPI.getTemperature();

      // Send a message to the channel w/ the current Hive13 & Local
      // temperature.
      event.getChannel().sendMessage("Hackerspace: " + dSpaceTemp + " -- Outdoors: " + dLocalTemp);
    }
  }
Ejemplo n.º 11
0
 public void displayTrendingList(String[][] topWords, int count, MessageEvent<MyPircBotX> event) {
   String response = "Trending Words (24 Hours): ";
   // for (Entry<String, Integer> entry : topWords.entrySet()) {
   for (int i = 0; i < count; i++) {
     String block = (topWords[i][0] + ":" + topWords[i][1] + " ");
     response = response + block;
   }
   event.respond(response);
 }
Ejemplo n.º 12
0
 public Timestamp getPeriodsAgo(
     int timeQuantity, String timePeriod, MessageEvent<MyPircBotX> event) {
   String search = stripTimePeriod(timePeriod);
   switch (search) {
     case "hour":
       return new Timestamp(event.getTimestamp() - (HOUR * timeQuantity));
     case "day":
       return new Timestamp(event.getTimestamp() - (DAY * timeQuantity));
     case "week":
       return new Timestamp(event.getTimestamp() - (WEEK * timeQuantity));
     case "month":
       return new Timestamp(event.getTimestamp() - (MONTH * timeQuantity));
     case "year":
       return new Timestamp(event.getTimestamp() - (YEAR * timeQuantity));
     default:
       return null;
   }
 }
Ejemplo n.º 13
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.pircbotx.hooks.ListenerAdapter#onMessage(org.pircbotx.hooks.events
   * .MessageEvent)
   */
  @Override
  public void onMessage(MessageEvent<Bot> event) throws Exception {
    super.onMessage(event);

    String[] splitMessage = event.getMessage().split(" ");
    for (String s : splitMessage) {
      if (Util.hasLink(s)) {

        String title = Util.parseLink(s);

        if (title.equals("")) continue;

        passMessage(
            event.getBot(),
            event.getChannel(),
            event.getUser(),
            event.getUser().getNick() + "'s URL: " + title);
      }
    }
  }
Ejemplo n.º 14
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()));
  }
Ejemplo n.º 15
0
  public void onMessage(MessageEvent event) throws Exception {
    if (event.getMessage().split(" ").length > 1) {

      if (event.getMessage().equals(".join")) {
        event.respond("Please specify a channel to join.");
      }

      String channelarg = event.getMessage().split(" ")[1];
      if (event.getMessage().startsWith(".join ") && event.getMessage().contains(channelarg)) {

        String admin = "";
        for (int i = 0; i < Config.admins.length; i++) {
          admin += Config.admins[i];
        }

        if (admin.contains(event.getUser().getNick())) {
          CyBot.bot.sendRawLineNow("join" + " " + channelarg);

          event.respond("Attempted to join channel " + channelarg);
        }
      }
    }
  }
Ejemplo n.º 16
0
 @Override
 public boolean execute(MessageEvent event) {
   String[] args = event.getMessage().split(" ");
   Channel target = event.getBot().getUserChannelDao().getChannel(args[1]);
   if (target.isInviteOnly()) {
     event
         .getBot()
         .sendRaw()
         .rawLineNow(
             "KNOCK "
                 + target.getName()
                 + " :Asked to join this channel by user "
                 + event.getUser().getNick()
                 + " in channel "
                 + event.getChannel().getName());
   }
   event.getBot().sendIRC().joinChannel(target.getName());
   return true;
 }
Ejemplo n.º 17
0
  @Override
  public void execute(MessageEvent event, String[] args) {
    User sender = event.getUser();
    Channel channel = event.getChannel();

    if (args.length > 0) {
      StringBuilder command = new StringBuilder();
      boolean verbose = args[0].equals("-v");

      for (int i = verbose ? 1 : 0; i < args.length; i++) {
        command.append(args[i]).append(" ");
      }

      try {
        Process proc = runtime.exec(command.toString());
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
        // Prevent spam on long results
        int count = 0;
        String line;

        while ((line = stdInput.readLine()) != null) {
          if (!verbose && count >= 3) {
            channel.send().message("Max output reached. Use -v to show full output.");
            break;
          }

          if (!line.isEmpty()) {
            channel.send().message(line);
            count++;
          }
        }

        stdInput.close();

        while ((line = stdError.readLine()) != null) {
          if (!verbose && count >= 3) {
            channel.send().message("Max output reached. Use -v to show full output.");
            break;
          }

          if (!line.isEmpty()) {
            channel.send().message(line);
            count++;
          }
        }

        stdError.close();
        proc.destroy();
      } catch (IOException ex) {
        foxbot.getLogger().error("Error occurred while executing system command", ex);
      }

      return;
    }

    sender
        .send()
        .notice(
            String.format(
                "Wrong number of args! Use %ssystem [-v] <command>",
                foxbot.getConfig().getCommandPrefix()));
  }
Ejemplo n.º 18
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();
    }
  }
Ejemplo n.º 19
0
  @Override
  public void execute(final MessageEvent event, final String[] args) {
    User sender = event.getUser();

    if (args.length == 2) {
      String user = args[0];
      String password = RandomStringUtils.randomAlphanumeric(6);
      String bindhost = args[1];

      // ---------------
      // Basic user info
      // ---------------

      foxbot.sendMessage("*controlpanel", String.format("adduser %s %s", user, password));
      foxbot.sendMessage("*controlpanel", String.format("set nick %s %s", user, user + "|bnc"));
      foxbot.sendMessage("*controlpanel", String.format("set altnick %s %s", user, user + "_"));
      foxbot.sendMessage(
          "*controlpanel", String.format("set ident %s %s", user, user.toLowerCase()));
      foxbot.sendMessage("*controlpanel", String.format("set bindhost %s %s", user, bindhost));
      foxbot.sendMessage("*controlpanel", String.format("set quitmsg %s Leaving", user));
      foxbot.sendMessage("*controlpanel", String.format("set buffercount %s 1000", user));
      foxbot.sendMessage("*controlpanel", String.format("set denysetbindhost %s true", user));
      foxbot.sendMessage("*controlpanel", String.format("set prependtimestamp %s true", user));

      // -----------
      // Add servers
      // -----------

      foxbot.sendMessage("*controlpanel", String.format("addnetwork %s Esper", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper irc.esper.net +6697", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper availo.esper.net +6697", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper portlane.esper.net +6697", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper chaos.esper.net +6697", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper nova.esper.net +6697", user));
      foxbot.sendMessage(
          "*controlpanel", String.format("addserver %s Esper optical.esper.net +6697", user));

      // ------------
      // Load modules
      // ------------

      foxbot.sendMessage("*controlpanel", String.format("loadmodule %s ctcpflood", user));
      foxbot.sendMessage("*controlpanel", String.format("loadmodule %s chansaver", user));
      foxbot.sendMessage("*controlpanel", String.format("loadmodule %s controlpanel", user));

      // ---------------------------------------
      // Send ZNC information to the adding user
      // ---------------------------------------

      foxbot.sendNotice(
          sender,
          String.format(
              "User added! Send this info to the user - Username: %s - Password: %s",
              user, password));

      // -----------
      // Add channel
      // -----------

      // Give the account chance to connect
      try {
        Thread.sleep(10000);
      } catch (InterruptedException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
      }
      foxbot.sendMessage(
          "*send_raw",
          String.format("server %s Esper JOIN %s", user, event.getChannel().getName()));
      return;
    }
    foxbot.sendNotice(
        sender,
        String.format(
            "Wrong number of args! Use %szncadduser <name> <bindhost>",
            foxbot.getConfig().getCommandPrefix()));
  }
Ejemplo n.º 20
0
 public void onMessage(MessageEvent event) throws Exception {
   String messageString = event.getMessage();
   String user = event.getUser().getNick();
   Date time = new Date();
   switch (messageString.toLowerCase()) {
     case "!derp":
       event.respond("says derp");
       log.writeLog(user + " sent the \"derp\" command on " + time);
       break;
     case "!time":
       event.getBot().sendNotice(event.getUser(), "Current bot server time is: " + time);
       log.writeLog(user + " sent the \"time\" command on " + time);
       break;
     case "!owner":
       event.getBot().sendNotice(event.getUser(), "The Owner of this bot is MonsterTKE");
       log.writeLog(user + " sent the \"time\" command on " + time);
       break;
     case "!help": // This is the simple no argument help command...
       event
           .getBot()
           .sendNotice(
               event.getUser(),
               "Commands are !help, !derp, !time, !owner, !password and !twitter");
       event.getBot().sendNotice(event.getUser(), "Get further help with !help (command)");
       log.writeLog(user + " sent the \"help\" command on " + time);
       break;
     case "!twitter":
       event.getBot().sendNotice(event.getUser(), "somethin somethin");
       log.writeLog(user + " sent the \"twitter\" command on " + time);
       break;
     default:
       // ToDO
       break;
   }
 }
Ejemplo n.º 21
0
 public Timestamp getDaysAgo(MessageEvent<MyPircBotX> event, int i) {
   return new Timestamp(event.getTimestamp() - (DAY * i));
 }
Ejemplo n.º 22
0
 public Timestamp getNow(MessageEvent<MyPircBotX> event) {
   return new Timestamp(event.getTimestamp());
 }
Ejemplo n.º 23
0
  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);
      }
    }
  }
Ejemplo n.º 24
0
  @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()));
  }
Ejemplo n.º 25
0
  @Override
  public boolean execute(MessageEvent event) throws Exception {
    String[] args = event.getMessage().split(" ");
    if (args.length == 2) {
      if (args[1].equalsIgnoreCase("again")) {
        MessageUtils.sendUserNotice(event, "Removing old login!");
        Main.Login.remove(event.getUser().getNick());
        Main.NotLoggedIn.remove(event.getUser().getNick());
        MessageUtils.sendUserNotice(event, "Logging in...");
        String account = Utils.getAccount(event.getUser(), event);
        Main.Login.put(event.getUser().getNick(), account);
        MessageUtils.sendUserNotice(event, "Logged in!");
        return true;
      }
      if (args[1].equalsIgnoreCase("info")) {
        MessageUtils.sendUserNotice(
            event, "You are logged in as: " + Main.Login.get(event.getUser().getNick()));
        MessageUtils.sendUserNotice(
            event,
            "You are in group: "
                + Group(
                    Main.Login.get(event.getUser().getNick()),
                    event.getChannel().getName().toLowerCase()));
        return true;
      }
    }

    if (Main.Login.containsKey(event.getUser().getNick())
        && !Main.NotLoggedIn.contains(event.getUser().getNick())) {
      MessageUtils.sendUserNotice(
          event,
          "You are already logged in! If you want to update login, use \""
              + config.getTrigger()
              + "login again\"");
      return true;
    }
    String account = Utils.getAccount(event.getUser(), event);
    Main.Login.put(event.getUser().getNick(), account);
    Main.NotLoggedIn.remove(event.getUser().getNick());
    MessageUtils.sendUserNotice(event, "You are now Logged in!");
    return true;
  }
Ejemplo n.º 26
0
 public Timestamp getHoursFromNow(MessageEvent<MyPircBotX> event, int hours) {
   return new Timestamp(event.getTimestamp() + (hours * HOUR));
 }