用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

5 months ago
/****************************************************************************
**
** 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 <QDebug>
#include <QDateTime>
#include <QtNetwork>
#include <QEventLoop>
#include <baiduweather.h>
#include <baidutranslate.h>
Robot::Robot(){
http=new QNetworkAccessManager(this);
connect(http,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
}
QString Robot::name(){
return QString("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>ٿ<EFBFBD>");
}
ReplyMsg Robot::listenandsay(const MsgSender msgSender, const QString &message){
ReplyMsg replyMsg;
if(message.at(0)!='#'){
return replyMsg;
}
if(msgSender.groupTXUIN.isEmpty()){
replyMsg.recTXUIN=msgSender.friendTXUIN;
}else{
replyMsg.recTXUIN=msgSender.groupTXUIN;
}
QString tmpstr;
if(message.indexOf("#help")==0){
replyMsg.content="<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>ٿƣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD>#time\n#<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n#translate <EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}else if(message.indexOf("#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")==0||message.indexOf("#time")==0){
replyMsg.content=QString("%1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>\n%2")
.arg(msgSender.friendName)
.arg(QDateTime::currentDateTime().toString("yyyy<EFBFBD><EFBFBD>MM<EFBFBD><EFBFBD>dd<EFBFBD><EFBFBD> hh<EFBFBD><EFBFBD>mm<EFBFBD><EFBFBD>ss<EFBFBD><EFBFBD>"));
}else if(message.indexOf("#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")==0){
tmpstr=message.mid(3).trimmed();
if(tmpstr.isEmpty()){
replyMsg.content="<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}else{
replyMsg.content=BaiduWeather::getWeather(tmpstr);
}
}else if(message.indexOf("#translate")==0||message.indexOf("#fy")==0||message.indexOf("#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")==0){
tmpstr=message.mid(message.indexOf(' ')).trimmed();
if(tmpstr.isEmpty()){
replyMsg.content="<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ұ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲô<EFBFBD><EFBFBD>";
}else{
replyMsg.content=Baidutranslate::translate(tmpstr);
}
}
return replyMsg;
}
QString Robot::getWeather(){
QEventLoop q;
connect(this, SIGNAL(OnEventLoopQuit()), &q, SLOT(quit())); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
weather.clear();
http->get(QNetworkRequest(QUrl(
QString("http://cgi.appx.qq.com/cgi/qqweb/weather/wth/weather.do?retype=1&t=%1")
.arg(QDateTime::currentMSecsSinceEpoch()))));
q.exec();
return weather;
}
void Robot::replyFinished(QNetworkReply *reply){
weather=QString::fromUtf8(reply->readAll());
reply->deleteLater();
emit OnEventLoopQuit();
return;
}