命令过滤
Command filtering
目前正在编写一个 IRC 机器人来取乐,我在设置机器人来听取我的命令时遇到了一些问题。 (适用于 !quit 但不适用于 !join 或 !leave)
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)?
示例:如果我在 IRC 中键入“!join #funnyposts”,它将加入频道#funnyposts。
感谢任何形式的帮助。
想通了。现在过滤不同的命令并相应地采取行动。
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);
}
目前正在编写一个 IRC 机器人来取乐,我在设置机器人来听取我的命令时遇到了一些问题。 (适用于 !quit 但不适用于 !join 或 !leave)
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)?
示例:如果我在 IRC 中键入“!join #funnyposts”,它将加入频道#funnyposts。 感谢任何形式的帮助。
想通了。现在过滤不同的命令并相应地采取行动。
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);
}