Adding an IRC bot to a script

Discussion in 'Java' started by contex, Sep 27, 2010.

  1. contex

    contex New Member

    Joined:
    Sep 27, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey.

    So I'm trying to add an IRC bot to this mod for Minecraft.
    The mod is called Hey0, named after the creator, he also released the source code for it.
    However I'm trying to add a java IRC bot called PIRC Bot.
    This is basicly what I'm trying to do:
    PIRC bot has 2 files, 1 called MyBotMain.java:

    Code:
    import org.jibble.pircbot.*;
    
    public class MyBotMain {
        
        public static void main(String[] args) throws Exception {
            
            // Now start our bot up.
            MyBot bot = new MyBot();
            
            // Enable debugging output.
            bot.setVerbose(true);
            
            // Connect to the IRC server.
            bot.connect("IRCSERVERt");
    
            // Join the #pircbot channel.
    		bot.joinChannel("#minecraft");
            
        }
        
    }
    
    and one called MyBot.java:

    Code:
    import org.jibble.pircbot.*;
    
    public class MyBot extends PircBot {
        
        public MyBot() {
            this.setName("Minecraft[IRCBOT]");
    		sendMessage("NickServ", "identify rapeface");
    
        }
        
        public void onMessage(String channel, String sender,
                           String login, String hostname, String message) {
    
    if(message.startsWith("!say")){
    int length = message.length();
      if(length>4) {
    String filterThis[] = {"!say"};
    
    for(int iFilt = 0; iFilt<filterThis.length; iFilt++) {
    int nWordLength = filterThis[iFilt].length();
    int nFoundPos = message.indexOf(filterThis[iFilt]);
    while (nFoundPos != -1){
    message = message.substring(0,nFoundPos)+ " " +message.substring(nFoundPos+nWordLength);
    nFoundPos = message.indexOf(filterThis[iFilt]);
    }
    }
    System.out.println("after: " + message);
    	
          		String messagetosend = "test";
                sendMessage(channel,sender + message);
        }
    	}
    	else{
        }
            }
        }
    
    I'm to add so that I can connect to IRC when the server launches, here is the Main class of Hey0's mod:

    Code:
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.URL;
    import java.nio.channels.Channels;
    import java.nio.channels.ReadableByteChannel;
    import org.jibble.pircbot.*;
    
    public class Main {
    
    
        public static void main(String[] args) throws IOException {
    	
    
            if (!new File("minecraft_server.jar").exists()) {
                System.out.println("minecraft_server.jar not found, downloading...");
    
                URL url = new URL("(Had to remove the url due to forum restriction)");
                ReadableByteChannel rbc = Channels.newChannel(url.openStream());
                FileOutputStream fos = new FileOutputStream("minecraft_server.jar");
                fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    
                System.out.println("Finished downloading, starting server");
            }
    
            if (checkForUpdate()) {
                System.out.println("Update found.");
                //derp.
            }
    
            net.minecraft.server.MinecraftServer.main(args);
        }
    
        public static boolean checkForUpdate() {
    	
            return false;
        }
    }
    
    
    So my quesiton is, how do I add the "MyBotMain.java" into "Main.java", I tried this:

    Code:
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.URL;
    import java.nio.channels.Channels;
    import java.nio.channels.ReadableByteChannel;
    import org.jibble.pircbot.*;
    
    public class Main {
    
    public void MyBotMain() throws Exception {
            // Now start our bot up.
            MyBot bot = new MyBot();
            
            // Enable debugging output.
            bot.setVerbose(true);
            
            // Connect to the IRC server.
            bot.connect("irc.crrpg.net");
    
            // Join the #pircbot channel.
    		bot.joinChannel("#minecraft.op miningisawsome");
    }
    
    
        public static void main(String[] args) throws Exception {
    	
    	
            if (!new File("minecraft_server.jar").exists()) {
                System.out.println("minecraft_server.jar not found, downloading...");
    
                URL url = new URL("(Had to remove the url due to forum restriction)");
                ReadableByteChannel rbc = Channels.newChannel(url.openStream());
                FileOutputStream fos = new FileOutputStream("minecraft_server.jar");
                fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    
                System.out.println("Finished downloading, starting server");
            }
    
            if (checkForUpdate()) {
                System.out.println("Update found.");
                //derp.
            }
    
            net.minecraft.server.MinecraftServer.main(args);
        }
    
        public static boolean checkForUpdate() {
    	
            return false;
        }
    }
    
    
    And it compiled without problems, but when I launch the server, the bot does not connect to the IRC server.

    Could anyone but me in the right direction, I would appricate it, thanks!

    - Contex
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice