Currently writing an IRC bot for fun and I have some trouble setting up the bot to listen to my commands. ( Works for !quit but not for !join or !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.");
}
}
I'm calling it like so:
client.HookIRCCommand("PRIVMSG", &onPrivMsg);
How would I get the channel name (#ChannelISpecify) from the text message line?
Example: If I'd type "!join #funnyposts" in IRC it would join the channel #funnyposts. Appriciate any kind of help.
Figured it out. Now filters for different commands and acts accordingly.
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);
}