/**************************************************************************** ** ** Copyright (C) 2013 Jeffrey Lee. ** All rights reserved. ** Contact: vipjeffreylee@gmail.com ** Please keep the author contact information. ** 2013-10-10 ** ****************************************************************************/ #include "robot.h" #include #include #include #include #include #include #include Robot::Robot(){ QTime time; time= QTime::currentTime(); qsrand(time.msec()+time.second()*1000); qDebug()<<"rebot start"<close(); //delete db; } bool Robot::loaddb(){ QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(QString(".%1db%1robotjoke.db3").arg(QDir::separator())); if(db.open()){ qDebug()<<"数据库打开成功!"<-1){ replyMsg.content="我爱讲笑话:\n #joke、#笑话;#addjoke 增加笑话"; }else if(message.indexOf("#joke")>-1||message.indexOf("#笑话")>-1){ if(jokelist.isEmpty()){ replyMsg.content="对不起,我现在没收集到任何笑话,请用#addjoke命令添加笑话。"; }else{ replyMsg.content=jokelist.at(qrand()%(jokelist.length())); } }else if(message.left(8)=="#addjoke"){ jokelist<-1){ replyMsg.content= QString("%1 你太客气了!随时为你效劳。").arg(msgSender.friendName); } return replyMsg; }