Esempio n. 1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    String prefix = "";
    String userName = settingsPane.returnSetting("IRC_nick");
    String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

    if (e.getSource() == g_start) {

      substarterBegin(prefix, userName, input);
    }

    if (e.getSource() == g_end) {
      substarterEnd(prefix, userName, input);
    }

    if (e.getSource() == sendButton) {

      if (!chatInput.getText().equals("")) {

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {
          sock.outputToChannel(chatInput.getText(), channelName);

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }

    if (e.getSource() == settings) {
      // makeNewWindow("Window " + frameCounter, JFrame.DISPOSE_ON_CLOSE, 800, 500, 2);
      settingsPane.showPane();
    }
  }
Esempio n. 2
0
  @Override
  public void keyReleased(KeyEvent e) {

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      String prefix = "";
      if (!chatInput.getText().equals("")) {
        String userName = settingsPane.returnSetting("IRC_nick");
        String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
          sock.outputToChannel(chatInput.getText(), channelName);
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }
  }
Esempio n. 3
0
  public static void main(String[] args) throws BadLocationException {
    // TODO code application logic here

    /// IRCBOT[] windows = new IRCBOT[3];

    /// String[] windowNames = new String[3];
    int chat = 0;
    substarter = new SubstarterGiveaway();

    // give_away = false;

    try {
      settingsPane.loadSettings();
    } catch (IOException ex) {
      Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
    }

    while (settingsPane.returnSetting("IRC_ip").equalsIgnoreCase("")) {
      if (settingsPane.isPaneOpen() == false) {
        settingsPane.showPane();
        settingsPane.setPaneStatus(true);
      }
    }

    JavaToMysql mysql =
        new JavaToMysql(
            settingsPane.returnSetting("MySQL_addr"),
            settingsPane.returnSetting("MySQL_port"),
            settingsPane.returnSetting("MySQL_userName"),
            settingsPane.returnSetting("MySQL_password"),
            settingsPane.returnSetting("MySQL_dbName"));

    Vector<IRCBOT> windows = new Vector<IRCBOT>(1);
    Vector<String> compUList = new Vector<String>(1);
    windowNames = new Vector<String>(1);

    boolean running = true;

    String server = settingsPane.getServerField();
    int port = Integer.parseInt(settingsPane.getPortField());
    String nick = settingsPane.getNickNameField();
    String oauth = settingsPane.getOAuth();
    String channel = settingsPane.getDefaultChanField();
    // String channel = JOptionPane.showInputDialog("Greetings " + nick + "!\nEnter channel: ");

    windowNames.addElement("Raw Data");
    windowNames.addElement("#" + nick);
    windowNames.addElement(channel);

    for (int x = 0; x < windowNames.size(); x++) {
      if (x == 0) windows.addElement(new IRCBOT(false, windowNames.get(x), chat));
      else windows.addElement(new IRCBOT(true, windowNames.get(x), chat));
      windows.lastElement().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      windows.get(x).setTitle("Substarter Client: " + windowNames.get(x));
      substarter.addGiveawayList();
      compUList.addElement("");
      chat++;
    }

    sock = new connection(server, port, nick, oauth, channel);
    sock.connect();

    IrcParser parse;

    while (running) {

      try {
        parse = new IrcParser(sock.rawFeedback());

        String parsed = parse.parsed();
        String code = parse.returnCode();
        String nickName = parse.returnUserInfo();
        String comment = parse.returnMisc();
        String channelParsed = parse.returnChannel();

        if (nickName.contains("!")) {
          int nickNameBegin = nickName.indexOf(":") + 1;
          int nickNameEnd = nickName.indexOf("!");

          nickName = nickName.substring(nickNameBegin, nickNameEnd);
        }

        if (!parsed.equals("null")) {

          System.out.println(parse.returnRawData());
          windows.get(0).toChatScreen(parse.parsed(), false);

          IRC_DeCoder irc = new IRC_DeCoder(sock, channel, nickName, code, comment);

          String o = irc.decode();

          if (irc.isUserListing()) {

            int windowNum = 0;
            for (int x = 0; x < windowNames.size(); x++) {
              if (windowNames.get(x).equals(channelParsed)) {
                windowNum = x;
                break;
              }
            }

            int placer = parse.returnMisc().indexOf(":");
            // System.out.println(parse.parsed());
            compUList.setElementAt(
                compUList.get(windowNum) + parse.returnMisc().substring(placer + 1) + " ",
                windowNum);
          } else if (irc.isUserListingEnd()) {
            int windowNum = 0;
            for (int x = 0; x < windowNames.size(); x++) {
              if (windowNames.get(x).equals(channelParsed)) {
                windowNum = x;
                break;
              }
            }

            UserList listPane = new UserList(compUList.get(windowNum));
            windows.get(windowNum).setUserList(listPane.returnUserList());
          } else if ((code.equals("JOIN")) && (!nickName.equals(nick))) {
            int windowNum = 0;
            for (int x = 0; x < windowNames.size(); x++) {
              if (windowNames.get(x).equals(channelParsed)) {
                windowNum = x;
                break;
              }
            }

            System.out.println("[" + channelParsed + "] [list+joined] " + compUList.get(windowNum));

            if (!compUList.get(windowNum).contains(nickName)) {
              compUList.setElementAt(compUList.get(windowNum) + nickName + " ", windowNum);
              UserList listPane = new UserList(compUList.get(windowNum));
              JScrollBar obj = windows.get(windowNum).userListScroll.getVerticalScrollBar();
              windows.get(windowNum).setUserList(listPane.returnUserList());
              windows.get(windowNum).userListScroll.setVerticalScrollBar(obj);
            }

            // compUList.setElementAt(compUList.get(windowNum) +
            // parse.returnMisc().substring(placer+1) + " ",windowNum);
          } else if (code.equals("PART")) {
            int windowNum = 0;
            for (int x = 0; x < windowNames.size(); x++) {
              if (windowNames.get(x).equals(channelParsed)) {
                windowNum = x;
                break;
              }
            }

            System.out.println("[" + channelParsed + "] [list+parted] " + compUList.get(windowNum));

            if (compUList.get(windowNum).contains(nickName)) {
              compUList.setElementAt(
                  compUList.get(windowNum).replace(nickName + " ", ""), windowNum);
              UserList listPane = new UserList(compUList.get(windowNum));
              JScrollBar obj = windows.get(windowNum).userListScroll.getVerticalScrollBar();
              windows.get(windowNum).setUserList(listPane.returnUserList());
              windows.get(windowNum).userListScroll.setVerticalScrollBar(obj);
            }
          } else if (!o.equals("")) {
            // String channelName = "";
            int dataBreak = 0;
            int windowNum = 0;

            // dataBreak = comment.indexOf(" :");
            // channelName = comment.substring(0, dataBreak);

            for (int x = 0; x < windowNames.size(); x++) {
              if (windowNames.get(x).equals(channelParsed)) {
                windowNum = x;
                break;
              }
            }
            if (windowNum != 0) {
              if ((o.toLowerCase().contains(nick.toLowerCase()))
                  && (!nickName.toLowerCase().contains(nick.toLowerCase()))) {
                windows.get(windowNum).toChatScreen(o, true);
              } else {
                windows.get(windowNum).toChatScreen(o, false);
              }

              if (code.equals("PRIVMSG")
                  && comment.contains("!substarter")
                  && substarter.isGiveawayActive(windowNum)) {
                if (!substarter.returnListString(windowNum).contains(nickName)) {
                  if (mysql.selectuser(nickName.toLowerCase())) {
                    /// regCompUList.setElementAt(regCompUList.get(windowNum) + nickName + " ",
                    // windowNum);

                    substarter.addUserToGiveaway(windowNum, nickName);

                    UserList listPane = new UserList(substarter.returnListString(windowNum));
                    windows.get(windowNum).setRegUserList(listPane.returnUserList());
                    sock.outputToChannel("Added " + nickName + "!", "#substarterbottest");
                  } else {
                    sock.outputToChannel(
                        nickName
                            + " Please register at http://substarter.com/my-account to participate in giveaway!  If you have registered, please make sure to create a funding page!",
                        windowNames.get(windowNum));
                  }
                }
              }

              if (!compUList.get(windowNum).contains(nickName)) {
                compUList.setElementAt(compUList.get(windowNum) + nickName + " ", windowNum);
                UserList listPane = new UserList(compUList.get(windowNum));
                windows.get(windowNum).setUserList(listPane.returnUserList());
              }
            }
          } else if (nickName.equals("PING")) {
            windows.get(0).toChatScreen("\r\n\r\n\r\nPONG\r\n\r\n", false);
            // sock.outputText("/NAMES\r\n");
          }

        } else running = false;
      } catch (IOException ex) {
        System.out.println("\n\n\n\nMain ERROR: " + ex + "\n\n\n\n\n\n");
        running = false;
      }
    }
    try {
      sock.closeSock();
    } catch (IOException ex) {
      System.out.println("\n\n\n\nsockClose ERROR: " + ex + "\n\n\n\n\n\n");
    }
  }