IRC Bot上的管理员用户

时间:2012-06-06 12:07:15

标签: c# irc

好吧所以我不熟悉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;

                }
            }
        }
    }

0 个答案:

没有答案