Anonymous avatar Anonymous committed 435b224

[FIX]: !net currency is work again. Some additional logic added.

Comments (0)

Files changed (1)

src/plugins/net/currencyrequest.cpp

 
 void CurrencyRequest::exec()
 {
-
 	if ( myDest.endsWith("list") )
 	{
 		QString url=QString("http://www.xe.com/ucc/full/");
 	QString from 	 = myDest.section(' ', 1, 1);
 	QString to	 = myDest.section(' ', 2, 2);
 
-	if (myDest.isEmpty() && amount.isEmpty() && from.isEmpty() && to.isEmpty())
+	if( from.toUpper() == "RUB" && to.isEmpty() ) {
+		to = "USD";
+	} else if( to.isEmpty() ) {
+		to = "RUB";
+	} 
+	
+	if (myDest.isEmpty() || amount.isEmpty() || from.isEmpty())
 	{
 		plugin()->reply(stanza(),"Usage: net currency <amount> <from> <to>");
 		deleteLater();
 		return;
 	}
 
-	int pn=(nres-1)/10;
-	nres=(nres-1)%10+1;
-
 	QString url=QString("http://www.xe.com/ucc/convert.cgi?Amount=%1&From=%2&To=%3").arg(amount).arg(from.toUpper()).arg(to.toUpper());
 	QUrl qurl(url);
 	http=new QHttp(qurl.host());
 {
 	if (err || http->lastResponse().statusCode()!=200)
 	{
-		plugin()->reply(stanza(),"Failed to fetch XE.com: "+http->lastResponse().reasonPhrase());
+		plugin()->reply(stanza(),"Failed to fetch from XE.com: "+http->lastResponse().reasonPhrase());
 		deleteLater();
 		return;
 	}
 	QString buf=http->readAll();
-	QRegExp exp("<h2 class=\"XE\">(.*)<!--");
-	exp.setMinimal(TRUE);
-	QString str;
-	int ps=0;
 
-	QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed();
-	QString to   = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed();
+	QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed();
+	QString to   = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed();
+	
+	QString curr1 = myDest.section(' ', 1, 1);
+	QString curr2 = myDest.section(' ', 2, 2);
+	QString msg   = "unknown currency: %1";
 
-	if( to.isEmpty() || from.isEmpty() ) {
-		plugin()->reply( stanza(),
-					QString("no such currency: %1 or %2")
-					.arg( myDest.section(' ', 1, 1).toUpper())
-					.arg( myDest.section(' ', 2, 2).toUpper()) );
+	if( from.isEmpty() || to.isEmpty() ) {
+		if( !curr2.isEmpty() && from == to) {
+			 msg.append(" or ").append(curr2);
+		}
+		plugin()->reply( stanza(), msg.arg(curr1));
 	} else {
-		plugin()->reply(stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " "));
+		plugin()->reply( stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " "));
 	}
+
 	deleteLater();
 }
 
 void CurrencyRequest::httpListRequestFinished(int, bool err)
 {
 	if (err || http->lastResponse().statusCode()!=200) {
-		plugin()->reply(stanza(),"Failed to fetch list XE.com: "+http->lastResponse().reasonPhrase());
+		plugin()->reply(stanza(),"Failed to fetch list from XE.com: "+http->lastResponse().reasonPhrase());
 		deleteLater();
 		return;
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.