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