自制Java IRC bot

时间:2015-10-24 02:01:38

标签: java bots

我正在构建一个Java IRC bot(是的,我知道有一些框架存在,我碰巧想要自己编写代码)并且在运行代码时遇到错误。没有任何印刷错误,只是...空虚。我已经尝试过使用IDE和CMD,但我什么都没得到......任何错误都可以找到?

    import java.io.*;
    import java.net.*;

    public class MonstaBotV2 {
        public static void main(String[] args) throws Exception {
            String server = "irc.quakenet.org";
            String nick = "^MonstaBot^";
            String login = "monstabot";
            String channel = "#MBTest";

            Socket socket = new Socket(server, 6667);
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(socket.getOutputStream()));
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(socket.getInputStream()));

            writer.write("NICK " + nick + " \r\n");
            writer.write("USER " + login + " 8 * : MonstaBot \r\n");
            writer.flush();

            String line;
            while ((line = reader.readLine()) != null) {
                if (line.indexOf("004") >= 0) {
                    break;
                }
                else if (line.indexOf("433") >= 0) {
                    System.out.println("Nickname is already in use.");
                    return;
                }
            }
            writer.write("JOIN " + channel + "\r\n");
            writer.flush();

            while ((line = reader.readLine( )) != null) {
                if (line.toLowerCase( ).startsWith("PING ")) {
                    writer.write("PONG " + line.substring(5) + "\r\n");
                    writer.flush();
                }
                else {
                   System.out.println(line);
                }
            }
        }
    }

哦是的,如果我将服务器更改为“irc.freenode.net”而不是“irc.quakenet.org”,它就连接到Freenode就好了。关于这可能是什么的任何线索?我是否需要改变连接到Quakenet的东西?

0 个答案:

没有答案