Advertisement
Guest User

Untitled

a guest
Jan 20th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.60 KB | None | 0 0
  1. import java.util.Arrays;
  2. import org.jibble.pircbot.*;
  3. import java.sql.*;
  4.  
  5. public class Ross extends PircBot {
  6.  
  7.     public Ross() {
  8.         this.setName("RICK_ROSS");
  9.         this.setVersion("v1.0");
  10.         this.setLogin("not_a_bot");
  11.         if (!main.password.equals("")) this.sendMessage(main.loginbot, "auth "+main.username+" "+main.password);
  12.     }
  13.  
  14.     public int checkOwner (String hostname) {
  15.         hostname = hostname.replace(".users.quakenet.org", "");
  16.         if (Arrays.asList(main.owner).contains(hostname)) return 1;
  17.         else return 0;
  18.     }
  19.  
  20.     public void noAccess (String channel) {
  21.         sendMessage(channel,"You do not have access.");
  22.     }
  23.  
  24.     public int checkLength (String[] words) {
  25.         if (words.length == 1) return 0;
  26.         else return 1;
  27.     }
  28.  
  29.     public void noParameters (String channel) {
  30.         sendMessage(channel, "Not enough parameters.");
  31.     }
  32.  
  33.     public String MySQL (String statement) throws SQLException, ClassNotFoundException {
  34.         Connection conn = null;
  35.         String url = "jdbc:mysql://";
  36.         Class.forName ("com.mysql.jdbc.Driver");
  37.         conn = DriverManager.getConnection (url,"","");
  38.         Statement stmt = conn.createStatement() ;
  39.         ResultSet rs = stmt.executeQuery(statement);
  40.         String result = "";
  41.         while (rs.next()) {
  42.             result = rs.getString(1);
  43.         }
  44.         rs.close();
  45.         stmt.close();
  46.         conn.close ();
  47.         return result;
  48.     }
  49.  
  50.     public void onMessage(String channel, String sender, String login, String hostname, String message) {
  51.         int value = checkOwner(hostname);
  52.         if (message.equalsIgnoreCase("!online")) {
  53.             String statement = "SELECT COUNT(*) from `char` where `online` = '1'";
  54.             try {
  55.                 String result = MySQL(statement);
  56.                 int check = Integer.parseInt(result);
  57.                 if (check >  0) sendMessage(channel,"It looks like the server is online.");
  58.                 else sendMessage(channel,"The server appears to be offline.");
  59.             } catch (ClassNotFoundException e) {
  60.                 e.printStackTrace();
  61.             } catch (SQLException e) {
  62.                 e.printStackTrace();
  63.             }
  64.         }
  65.         if (message.equalsIgnoreCase("!players")) {
  66.             String statement = "SELECT COUNT(*) from `char` where `online` = '1'";
  67.             try {
  68.                 String result = MySQL(statement);
  69.                 sendMessage(channel,"There are currently "+result+" players playing Oblivion Ragnarok Online.");
  70.             } catch (ClassNotFoundException e) {
  71.                 e.printStackTrace();
  72.             } catch (SQLException e) {
  73.                 e.printStackTrace();
  74.             }
  75.         }
  76.         if (message.equalsIgnoreCase("!owner")) {
  77.             String temp = "";
  78.             if (main.owner.length != 1) {
  79.                 for (int i = 0; i < main.owner.length; i++) {
  80.                     if (i == main.owner.length-1) temp = temp+"and "+main.owner[i]+" are the best.";
  81.                     else temp = temp+main.owner[i]+", ";
  82.                 }
  83.             }
  84.             else temp = main.owner[0]+" is the best.";
  85.             sendMessage(channel, temp);
  86.         }
  87.         if (message.equalsIgnoreCase("!time")) {
  88.             String time = new java.util.Date().toString();
  89.             sendMessage(channel, time);
  90.         }
  91.         if (message.startsWith("!topic")) {
  92.             if (value == 1) {
  93.                 String topic = message.replace("!topic ", "");
  94.                 String[] words = message.split(" ");
  95.                 int rvalue = checkLength(words);
  96.                 if (rvalue != 1) {
  97.                     noParameters(channel);
  98.                 }
  99.                 else setTopic(channel, topic);
  100.             }
  101.             else noAccess(channel);
  102.         }
  103.  
  104.         if (message.startsWith("!k")) {
  105.             if (value == 1) {
  106.                 String[] words = message.split(" ");
  107.                 int rvalue = checkLength(words);
  108.                 if (rvalue != 1) {
  109.                     noParameters(channel);
  110.                 }
  111.                 else kick(channel, words[1]);
  112.             }
  113.             else noAccess(channel);
  114.         }
  115.         if (message.startsWith("!m")) {
  116.             if (value == 1) {
  117.                 String[] words = message.split(" ");
  118.                 int rvalue = checkLength(words);
  119.                 if (rvalue != 1) {
  120.                     noParameters(channel);
  121.                 }
  122.                 else {
  123.                     if (words.length == 3) {
  124.                         if (words[1].equals("+b") || words[1].equals("b")) {
  125.                             setMode(channel, words[1]+" "+words[2]);
  126.                             kick(channel, words[2]);
  127.                         }
  128.                         else setMode(channel, words[1]+" "+words[2]);
  129.                     }
  130.                     else setMode(channel, words[1]);
  131.                 }
  132.             }
  133.             else noAccess(channel);
  134.         }
  135.  
  136.     }
  137.  
  138.     public void onConnect() {
  139.         joinChannel("#renegades");
  140.     }
  141. }
  142.  
  143. ////////////////////////////
  144. Here is my main class
  145. ////////////////////////////
  146.  
  147. import java.sql.Connection;
  148. import java.sql.DriverManager;
  149. import java.sql.SQLException;
  150.  
  151. import org.jibble.pircbot.*;
  152.  
  153. public class main extends PircBot {
  154.     public static String[] owner = {"awdawd", "aswdawd"};
  155.     public static String username = "";
  156.     public static String password = "";
  157.     public static String loginbot = "q@cserve.quakenet.org";
  158.  
  159.     public static void main(String[] args) throws Exception {
  160.         Ross bot = new Ross( );
  161.         bot.setVerbose(true);
  162.         bot.connect("irc.quakenet.org");
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement