public void substarterEnd(String prefix, String userName, String input) { System.out.println("ending give"); if (substarter.end(winNum)) { g_start.setEnabled(true); g_end.setEnabled(false); String winner = substarter.returnWinner(winNum); input = "Congrats to the new sub winner: " + winner + "!"; prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; registeredUserList.setText(winner + "\n"); } else { g_start.setEnabled(true); g_end.setEnabled(false); prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; input = "No one entered giveaway, ending giveaway."; } sock.outputToChannel(input, channelName); try { toChatScreen(prefix + input, false); } catch (IOException | BadLocationException ex) { Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex); } }
public void substarterBegin(String prefix, String userName, String input) { if (substarter.start(winNum)) { System.out.println("Starting give"); g_start.setEnabled(false); g_end.setEnabled(true); registeredUserList.setText(""); prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; input = "Substarter giveaway is starting, make sure to register at http://substarter.com/my-account to participate. Type !substarter for a chance to win a free sub!"; sock.outputToChannel(input, channelName); } else { input = "<font color='red'>[WARNING]: Giveaway already started, perhaps in another chat window.</font>"; } try { toChatScreen(prefix + input, false); } catch (IOException | BadLocationException ex) { Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex); } }
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"); } }