sauerCHAOS

QuadroBot

Feb 26th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. // Reader.java
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.io.IOException;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7.  
  8. public class Reader implements Runnable {
  9.    
  10.     public static int firstEmptyNode = 3333;
  11.    
  12.     public static String getNodeTitle(int node) {
  13.         try {
  14.             BufferedReader in = new BufferedReader(
  15.                     new InputStreamReader(
  16.                             new URL("http://www.quadropolis.us/node/" + node).openStream()
  17.                             )
  18.                     );
  19.             String line;
  20.             while((line = in.readLine()) != null) {
  21.                 //String line = in.readLine();
  22.                 if(line.startsWith("<title>") && line.endsWith(" | Quadropolis</title>"))
  23.                     return line.replace(" | Quadropolis</title>", "").replace("<title>", "");
  24.             }
  25.         }
  26.         catch (MalformedURLException e) { return null; }
  27.         catch (IOException e) { return null; }
  28.         return null;
  29.     }
  30.    
  31.     public void run() {
  32.         while(true) {
  33.             if (getNodeTitle(firstEmptyNode) == null) continue;
  34.             else {
  35.                 //nodeTitle = getNodeTitle(node);
  36.                 //System.out.println(nodeTitle);
  37.                 firstEmptyNode++;
  38.             }
  39.             //System.out.println(firstEmptyNode);
  40.         }
  41.     }
  42.    
  43.     public static void main(String[] args) {
  44.         for(int i = 3333 ; i < 3334 ; i++) System.out.println(Reader.getNodeTitle(i));
  45.         //new Reader().run();
  46.         //System.out.println(firstEmptyNode);
  47.         //new Bot().initiateNode();
  48.         //System.out.println(Bot.node);
  49.        
  50.     }
  51.    
  52. }
  53.  
  54. //--
  55. // Bot.java
  56. import org.jibble.pircbot.*;
  57.  
  58. public class Bot extends PircBot implements Runnable {
  59.    
  60.     public static int node = 3333;
  61.    
  62.     public Bot() {
  63.         this.setName("QuadroBot");
  64.         this.setLogin("qbot");
  65.     }
  66.    
  67.     public void initiateNode() {
  68.         while(Reader.getNodeTitle(node) != null) {
  69.             //System.out.println(Reader.getNodeTitle(node));
  70.             node++;
  71.         }
  72.     }
  73.    
  74.     public void onMessage(String channel, String sender, String login, String hostname, String message) {
  75.        
  76.         if ((message.startsWith("-join")) && sender.equals("Chaos")) {
  77.             joinChannel(message.substring(6,message.length()));
  78.         }
  79.        
  80.         if ((message.startsWith("-part")) && sender.equals("Chaos")) {
  81.             partChannel(message.substring(6,message.length()));
  82.         }
  83.        
  84.         if ((message.startsWith("-nick")) && sender.equals("Chaos")) {
  85.             changeNick(message.substring(6,message.length()));
  86.         }  
  87.        
  88.     }
  89.    
  90.     public void run() {
  91.         while (true) {
  92.             if (Reader.getNodeTitle(node) != null) {
  93.                 sendMessage("#sauer-scripts",
  94.                         Colors.BOLD + Reader.getNodeTitle(node)
  95.                     );
  96.                 initiateNode();
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102. // ---
  103. // BotMain.java
  104. public class BotMain {  
  105.     public static void main(String[] args) throws Exception {
  106.         Bot bot = new Bot();
  107.         bot.setVerbose(true);
  108.         bot.connect("irc.gamesurge.net");
  109.         bot.joinChannel("#sauer-scripts");
  110.        
  111.         //bot.initiateNode();
  112.         new Thread(new Reader()).start();
  113.         new Thread(bot).start();
  114.        
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment