Changeset 406:435b224550e5
- Timestamp:
- 02/01/2010 12:47:19 PM (2 years ago)
- Author:
- Sidgyck <sidgyck@…>
- Branch:
- default
- Message:
-
[FIX]: !net currency is work again. Some additional logic added.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r362
|
r406
|
|
| 43 | 43 | void CurrencyRequest::exec() |
| 44 | 44 | { |
| 45 | | |
| 46 | 45 | if ( myDest.endsWith("list") ) |
| 47 | 46 | { |
| … |
… |
|
| 58 | 57 | QString to = myDest.section(' ', 2, 2); |
| 59 | 58 | |
| 60 | | if (myDest.isEmpty() && amount.isEmpty() && from.isEmpty() && to.isEmpty()) |
| | 59 | if( from.toUpper() == "RUB" && to.isEmpty() ) { |
| | 60 | to = "USD"; |
| | 61 | } else if( to.isEmpty() ) { |
| | 62 | to = "RUB"; |
| | 63 | } |
| | 64 | |
| | 65 | if (myDest.isEmpty() || amount.isEmpty() || from.isEmpty()) |
| 61 | 66 | { |
| 62 | 67 | plugin()->reply(stanza(),"Usage: net currency <amount> <from> <to>"); |
| … |
… |
|
| 64 | 69 | return; |
| 65 | 70 | } |
| 66 | | |
| 67 | | int pn=(nres-1)/10; |
| 68 | | nres=(nres-1)%10+1; |
| 69 | 71 | |
| 70 | 72 | QString url=QString("http://www.xe.com/ucc/convert.cgi?Amount=%1&From=%2&To=%3").arg(amount).arg(from.toUpper()).arg(to.toUpper()); |
| … |
… |
|
| 79 | 81 | if (err || http->lastResponse().statusCode()!=200) |
| 80 | 82 | { |
| 81 | | plugin()->reply(stanza(),"Failed to fetch XE.com: "+http->lastResponse().reasonPhrase()); |
| | 83 | plugin()->reply(stanza(),"Failed to fetch from XE.com: "+http->lastResponse().reasonPhrase()); |
| 82 | 84 | deleteLater(); |
| 83 | 85 | return; |
| 84 | 86 | } |
| 85 | 87 | QString buf=http->readAll(); |
| 86 | | QRegExp exp("<h2 class=\"XE\">(.*)<!--"); |
| 87 | | exp.setMinimal(TRUE); |
| 88 | | QString str; |
| 89 | | int ps=0; |
| 90 | 88 | |
| 91 | | QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed(); |
| 92 | | QString to = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\">(.*)<!--")).trimmed(); |
| | 89 | QString from = removeHtml(getValue(buf,"align=\"right\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed(); |
| | 90 | QString to = removeHtml(getValue(buf,"align=\"left\" class=\"XEenlarge\"><h2 class=\"XE\" style=\"color:#333\">(.*)<!--")).trimmed(); |
| | 91 | |
| | 92 | QString curr1 = myDest.section(' ', 1, 1); |
| | 93 | QString curr2 = myDest.section(' ', 2, 2); |
| | 94 | QString msg = "unknown currency: %1"; |
| 93 | 95 | |
| 94 | | if( to.isEmpty() || from.isEmpty() ) { |
| 95 | | plugin()->reply( stanza(), |
| 96 | | QString("no such currency: %1 or %2") |
| 97 | | .arg( myDest.section(' ', 1, 1).toUpper()) |
| 98 | | .arg( myDest.section(' ', 2, 2).toUpper()) ); |
| | 96 | if( from.isEmpty() || to.isEmpty() ) { |
| | 97 | if( !curr2.isEmpty() && from == to) { |
| | 98 | msg.append(" or ").append(curr2); |
| | 99 | } |
| | 100 | plugin()->reply( stanza(), msg.arg(curr1)); |
| 99 | 101 | } else { |
| 100 | | plugin()->reply(stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " ")); |
| | 102 | plugin()->reply( stanza(), QString("%1 = %2").arg(from).arg(to).simplified().replace(",", " ")); |
| 101 | 103 | } |
| | 104 | |
| 102 | 105 | deleteLater(); |
| 103 | 106 | } |
| … |
… |
|
| 106 | 109 | { |
| 107 | 110 | if (err || http->lastResponse().statusCode()!=200) { |
| 108 | | plugin()->reply(stanza(),"Failed to fetch list XE.com: "+http->lastResponse().reasonPhrase()); |
| | 111 | plugin()->reply(stanza(),"Failed to fetch list from XE.com: "+http->lastResponse().reasonPhrase()); |
| 109 | 112 | deleteLater(); |
| 110 | 113 | return; |