示例#1
0
文件: IRC.cpp 项目: Chase-san/AnnaBot
void IRC::handle_msg(const string& chan, const string& nick, const string& login, const string& host, const string& omsg) {
    string msg = omsg;
    if(chan.find_first_of("#&+!") == 0) {
        //Channel Message
        onMessage(chan, nick, login, host, msg);
    } else {
        //Private Messages
        if(msg.find("\x001") == 0 && msg.rfind("\x001") == msg.length() - 1) {
            //CTCP
            msg = msg.substr(1, msg.length() - 2);
            if(msg.compare("TIME") == 0) {
                onTime(nick,login,host,chan);
            } else if(msg.compare("VERSION") == 0) {
                onVersion(nick,login,host,chan);
            } else if(msg.substr(0, 4).compare("PING") == 0) {
                onPing(nick,login,host,chan,msg.substr(5));
            } else if(msg.compare("FINGER") == 0) {
                onFinger(nick,login,host,chan);
            } else if(msg.substr(0, 6).compare("ACTION") == 0) {
                onAction(nick,login,host,chan,msg.substr(7));
            }

            return;
        }
        onPrivateMessage(nick, login, host, msg);
    }
}
示例#2
0
void MessageManager::on(UserConnectionListener::PrivateMessage, UserConnection* uc, const ChatMessage& message) noexcept {
    onPrivateMessage(message, uc);
}
示例#3
0
bool CPPModule::onEvent(IrcConnection* connection, const std::string& senderID, const std::string& eventName, const std::string& json, const std::string& optString) {
	JSONNode n;
	if(!json.empty()) {
		n = libjson::parse(json);
	}

	if(senderID=="IRCCONNECTION") {
		//Create a IrcModuleConnection instance
		IrcModuleConnection ircModuleConnection(mID, mModuleManager, connection);


		//Call onConnect if its the called event
		if(eventName=="onConnect") {
			return onConnect(ircModuleConnection);
		}


		//Convert the IRC Message
		IrcMessage message;
		message.ircLine = n["ircLine"].as_string();
		message.prefix = n["prefix"].as_string();
		message.hasDetailedPrefix = n["hasDetailedPrefix"].as_bool();

		if(message.hasDetailedPrefix) {
			message.msgPrefix.nick_or_server = n["msgPrefix"]["nick_or_server"].as_string();
			message.msgPrefix.user = n["msgPrefix"]["user"].as_string();
			message.msgPrefix.host = n["msgPrefix"]["host"].as_string();
		}

		message.command = n["command"].as_string();
		message.isNumeric = n["isNumeric"].as_bool();
		message.target = n["target"].as_string();
		message.params = n["params"].as_string();


		//Call all other event handlers
		if(eventName=="onMessage") {
			return onMessage(ircModuleConnection, message);
		}
		else if(eventName=="onJoin") {
			return onJoin(ircModuleConnection, message);
		}
		else if(eventName=="onPart") {
			return onPart(ircModuleConnection, message);
		}
		else if(eventName=="onKick") {
			return onKick(ircModuleConnection, message, optString);
		}
		else if(eventName=="onQuit") {
			return onQuit(ircModuleConnection, message);
		}
		else if(eventName=="onKill") {
			return onKill(ircModuleConnection, message, optString);
		}
		else if(eventName=="onPrivateMessage") {
			return onPrivateMessage(ircModuleConnection, message);
		}
		else if(eventName=="onChannelMessage") {
			return onChannelMessage(ircModuleConnection, message);
		}
		else if(eventName=="onNotice") {
			return onNotice(ircModuleConnection, message);
		}
		else if(eventName=="onInvite") {
			return onInvite(ircModuleConnection, message);
		}
		else if(eventName=="onTopicChanged") {
			return onTopicChanged(ircModuleConnection, message);
		}
		else if(eventName=="onNickChanged") {
			return onNickChanged(ircModuleConnection, message);
		}
	}

	return true;
}