命令过滤

时间:2015-06-03 09:00:51

标签: c++ parsing command bots irc

目前正在编写一个有趣的IRC机器人,我在设置机器人听取我的命令时遇到了一些麻烦。 (适用于!退出但不适用于!加入或!离开)

void onPrivMsg(IRCMessage message, IRCClient* client)
{
    // received text
    std::string text = message.parameters.at(message.parameters.size() - 1);

    if (text[0] == '!')
    {
    if (text == "!Join #channel" || text == "!join #channel")
        client->SendIRC("JOIN #channel");
    if (text == "!Leave #channel" || text == "!leave #channel")
        client->SendIRC("PART #channel");
    if (text == "!Quit" || text == "!quit")
        client->SendIRC("QUIT");
    } else{
        client->SendIRC("PRIVMSG #channel :Wrong command.");
    }
}

我这样称呼它:

client.HookIRCCommand("PRIVMSG", &onPrivMsg);

如何从短信行获取频道名称(#ChannelISpecify)?

示例:如果我输入"!加入#funnyposts"在IRC中,它将加入频道#funnyposts。 提供任何帮助。

1 个答案:

答案 0 :(得分:0)

想出来。现在过滤不同的命令并采取相应的行动。

if (text[0] == '!')
{
    std::string commandApi = text.substr(0, text.find(" "));
    if (commandApi == "!Join" || commandApi == "!join"){
        if (commandApi[0] = '!'){
            commandApi[0] = '/';
        }
        std::string channel2 = text.substr(text.find("#"));
        client->SendIRC("PRIVMSG " + channel2 + " :Joining channel");
        client->SendIRC("JOIN " + channel2);
    }