Added the ability to list the current rates.
This commit is contained in:
parent
365bc27e7d
commit
8b44a73d4d
1 changed files with 29 additions and 5 deletions
|
@ -49,10 +49,7 @@ import java.net.URL;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,6 +73,11 @@ public class CurrencyConverter implements Runnable
|
||||||
*/
|
*/
|
||||||
private static final Map EXCHANGE_RATES = new TreeMap();
|
private static final Map EXCHANGE_RATES = new TreeMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rates keyword.
|
||||||
|
*/
|
||||||
|
private static final String RATES_KEYWORD = "rates";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last exchange rates table publication date.
|
* The last exchange rates table publication date.
|
||||||
*/
|
*/
|
||||||
|
@ -176,7 +178,7 @@ public class CurrencyConverter implements Runnable
|
||||||
{
|
{
|
||||||
final double amt = Double.parseDouble(cmds[0].replaceAll(",", ""));
|
final double amt = Double.parseDouble(cmds[0].replaceAll(",", ""));
|
||||||
final double from = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[1].toUpperCase()));
|
final double from = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[1].toUpperCase()));
|
||||||
double to = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[3].toUpperCase()));
|
final double to = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[3].toUpperCase()));
|
||||||
|
|
||||||
_bot.sendNotice(_bot.getChannel(),
|
_bot.sendNotice(_bot.getChannel(),
|
||||||
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
|
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
|
||||||
|
@ -192,6 +194,28 @@ public class CurrencyConverter implements Runnable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_query.equals(RATES_KEYWORD))
|
||||||
|
{
|
||||||
|
_bot.sendNotice(_sender, "Last Update: " + s_date);
|
||||||
|
|
||||||
|
final Iterator it = EXCHANGE_RATES.keySet().iterator();
|
||||||
|
String rate;
|
||||||
|
|
||||||
|
final StringBuffer buff = new StringBuffer(0);
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
rate = (String) it.next();
|
||||||
|
if (buff.length() > 0)
|
||||||
|
{
|
||||||
|
buff.append(", ");
|
||||||
|
}
|
||||||
|
buff.append(rate).append(": ").append(EXCHANGE_RATES.get(rate));
|
||||||
|
}
|
||||||
|
|
||||||
|
_bot.sendNotice(_sender, buff.toString());
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_bot.helpResponse(_sender, Mobibot.CURRENCY_CMD + ' ' + _query);
|
_bot.helpResponse(_sender, Mobibot.CURRENCY_CMD + ' ' + _query);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue