0

好的,所以我不熟悉 IRC 协议,但我已经阅读了相当多的内容以获得更好的理解,但我仍然不确定我将如何设置它,所以我的机器人只会遵循我的命令或阅读机器人“管理员” "来自文本文件。我想实现这一点,以阻止每个人让他退出和垃圾邮件。

如果您需要更具体的内容,请随时询问,我会更新帖子。

按照要求:

    public void sendData(string cmd, string param)
    {
        if (param == null)
        {
            sw.WriteLine(cmd);
            sw.Flush();
            Console.WriteLine(cmd);
        }
        else
        {
            sw.WriteLine(cmd + " " + param);
            sw.Flush();
            Console.WriteLine(cmd + " " + param);
        }
    }

    public void IRCWork()
    {
        string[] ex;
        string data;
        bool shouldRun = true;
        while (shouldRun)
        {
            data = sr.ReadLine();
            Console.WriteLine(data);
            char[] charSeparator = new char[] { ' ' };
            ex = data.Split(charSeparator, 5);

            if (ex[0] == "PING")
            {
                sendData("PONG", ex[1]);
            }

            if (ex.Length > 4) //is the command received long enough to be a bot command?
            {
                string command = ex[3]; //grab the command sent

                switch (command)
                {
                    case ":!join":
                        sendData("JOIN", ex[4]);
                        //if the command is !join send the "JOIN" command to the server with the parameters set by the user
                        break;
                    case ":!say":
                        sendData("PRIVMSG", ex[2] + " " + ex[4]);
                        //if the command is !say, send a message to the chan (ex[2]) followed by the actual message (ex[4]).
                        break;
                    case ":!quit":
                        sendData("QUIT", ex[4]);
                        //if the command is quit, send the QUIT command to the server with a quit message
                        shouldRun = false;
                        //turn shouldRun to false - the server will stop sending us data so trying to read it will not work and result in an error. This stops the loop from running and we will close off the connections properly
                        break;
                    case ":!part":
                        sendData("PART", ex[4]);
                        break;
                    case ":!query":
                        sendData("QUERY", ex[4] + ex[4]);
                        break;
                    case ":!useradd":
                        sendData("USERADD", ex[4]);
                        break;

                }
            }
        }
    }
4

0 回答 0