00001 /* 00002 ######################################################################### 00003 # 00004 # This file is part of trustyRC. 00005 # 00006 # trustyRC, fully modular IRC robot 00007 # Copyright (C) 2006-2008 Nicoleau Fabien 00008 # 00009 # trustyRC is free software: you can redistribute it and/or modify 00010 # it under the terms of the GNU General Public License as published by 00011 # the Free Software Foundation, either version 3 of the License, or 00012 # (at your option) any later version. 00013 # 00014 # trustyRC is distributed in the hope that it will be useful, 00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 # GNU General Public License for more details. 00018 # 00019 # You should have received a copy of the GNU General Public License 00020 # along with trustyRC. If not, see <http://www.gnu.org/licenses/>. 00021 # 00022 ######################################################################### 00023 */ 00024 00029 #include "message.h" 00030 00031 00037 Message::Message(string message) 00038 { 00039 this->setMessage(message); 00040 } 00041 00046 Message::Message() 00047 { 00048 this->message= ""; 00049 this->split.clear(); 00050 } 00051 00055 Message::~Message() 00056 { 00057 00058 } 00059 00064 void Message::setMessage(string message) 00065 { 00066 this->message = message; 00067 this->split = Tools::stringToVector(message," ",0); 00068 string source = this->getSource() ; 00069 if ( source == "" ) 00070 { 00071 this->pv = true; 00072 } 00073 else 00074 { 00075 if ( source[0] != '#' ) 00076 this->pv = true; 00077 else 00078 this->pv = false; 00079 } 00080 time(&this->timestamp); 00081 } 00082 00087 unsigned int Message::nbParts() { 00088 return this->split.size() ; 00089 } 00090 00095 vector<string> Message::getSplit() 00096 { 00097 return this->split; 00098 } 00099 00104 string Message::getSender() 00105 { 00106 if(this->getPart(0).length() > 0 ) { 00107 return this->split[0].substr(1); 00108 } 00109 else { 00110 return ""; 00111 } 00112 } 00113 00118 string Message::getNickSender() 00119 { 00120 if(this->getPart(0).length() > 0 ) { 00121 return(this->message.substr(1,this->message.find("!")-1)); 00122 } 00123 else { 00124 return ""; 00125 } 00126 } 00127 00132 string Message::getHostSender() 00133 { 00134 if(this->getPart(0).length() > 0 ) { 00135 return(this->split[0].substr(this->message.find("@")+1)); 00136 } 00137 else { 00138 return ""; 00139 } 00140 } 00141 00146 string Message::getIdentSender() 00147 { 00148 if(this->getPart(0).length() > 0 ) { 00149 return(this->split[0].substr(this->message.find("!")+1,this->split[0].find("@")-this->message.find("!")-1)); 00150 } 00151 else { 00152 return ""; 00153 } 00154 } 00155 00160 bool Message::isPrivate() 00161 { 00162 return this->pv; 00163 } 00164 00169 bool Message::isPublic() 00170 { 00171 return !this->isPrivate(); 00172 } 00173 00180 string Message::getPart(unsigned int index) 00181 { 00182 if ( this->split.size() > index) 00183 { 00184 return this->split[index]; 00185 } 00186 else 00187 { 00188 return ""; 00189 } 00190 } 00191 00196 string Message::getSource() 00197 { 00198 return this->getPart(2); 00199 } 00200 00205 string Message::getMessage() 00206 { 00207 return this->message; 00208 } 00209 00214 time_t Message::getElapsedTime() 00215 { 00216 time_t now; 00217 time(&now); 00218 return (now - this->timestamp); 00219 }