Code cleanup.
This commit is contained in:
parent
3def574940
commit
844507ea9e
3 changed files with 9 additions and 20 deletions
|
@ -60,20 +60,14 @@ import java.util.TreeMap;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public final class CurrencyConverter extends AbstractModule {
|
public final class CurrencyConverter extends AbstractModule {
|
||||||
/**
|
// The rates keyword.
|
||||||
* The rates keyword.
|
|
||||||
*/
|
|
||||||
static final String CURRENCY_RATES_KEYWORD = "rates";
|
static final String CURRENCY_RATES_KEYWORD = "rates";
|
||||||
|
|
||||||
// The currency command.
|
// The currency command.
|
||||||
private static final String CURRENCY_CMD = "currency";
|
private static final String CURRENCY_CMD = "currency";
|
||||||
|
|
||||||
// The exchange rates.
|
// The exchange rates.
|
||||||
private static final Map<String, String> EXCHANGE_RATES = new TreeMap<>();
|
private static final Map<String, String> EXCHANGE_RATES = new TreeMap<>();
|
||||||
|
|
||||||
// The exchange rates table URL.
|
// The exchange rates table URL.
|
||||||
private static final String EXCHANGE_TABLE_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
|
private static final String EXCHANGE_TABLE_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
|
||||||
|
|
||||||
// The last exchange rates table publication date.
|
// The last exchange rates table publication date.
|
||||||
private static String pubDate = "";
|
private static String pubDate = "";
|
||||||
|
|
||||||
|
@ -203,7 +197,7 @@ public final class CurrencyConverter extends AbstractModule {
|
||||||
try {
|
try {
|
||||||
final Message msg = convertCurrency(query);
|
final Message msg = convertCurrency(query);
|
||||||
if (msg.isError()) {
|
if (msg.isError()) {
|
||||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, true);
|
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, false);
|
||||||
}
|
}
|
||||||
bot.send(msg.isNotice() ? sender : bot.getChannel(), msg.getMessage());
|
bot.send(msg.isNotice() ? sender : bot.getChannel(), msg.getMessage());
|
||||||
} catch (ModuleException e) {
|
} catch (ModuleException e) {
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
package net.thauvin.erik.mobibot.modules;
|
package net.thauvin.erik.mobibot.modules;
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot;
|
import net.thauvin.erik.mobibot.Mobibot;
|
||||||
|
import net.thauvin.erik.mobibot.Utils;
|
||||||
import net.thauvin.erik.mobibot.msg.Message;
|
import net.thauvin.erik.mobibot.msg.Message;
|
||||||
import net.thauvin.erik.mobibot.msg.PublicMessage;
|
import net.thauvin.erik.mobibot.msg.PublicMessage;
|
||||||
import org.jibble.pircbot.Colors;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -51,14 +51,11 @@ import java.nio.charset.StandardCharsets;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public final class Joke extends AbstractModule {
|
public final class Joke extends AbstractModule {
|
||||||
/**
|
|
||||||
* The joke command.
|
|
||||||
*/
|
|
||||||
public static final String JOKE_CMD = "joke";
|
|
||||||
|
|
||||||
// The ICNDB URL.
|
// The ICNDB URL.
|
||||||
private static final String JOKE_URL =
|
private static final String JOKE_URL =
|
||||||
"http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]";
|
"http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]";
|
||||||
|
// The joke command.
|
||||||
|
private static final String JOKE_CMD = "joke";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link Joke} instance.
|
* Creates a new {@link Joke} instance.
|
||||||
|
@ -87,6 +84,7 @@ public final class Joke extends AbstractModule {
|
||||||
|
|
||||||
final JSONObject json = new JSONObject(sb.toString());
|
final JSONObject json = new JSONObject(sb.toString());
|
||||||
|
|
||||||
|
//noinspection RegExpRedundantEscape
|
||||||
return new PublicMessage(
|
return new PublicMessage(
|
||||||
json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'")
|
json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'")
|
||||||
.replaceAll("\\\"", "\""));
|
.replaceAll("\\\"", "\""));
|
||||||
|
@ -118,7 +116,7 @@ public final class Joke extends AbstractModule {
|
||||||
*/
|
*/
|
||||||
private void run(final Mobibot bot, final String sender) {
|
private void run(final Mobibot bot, final String sender) {
|
||||||
try {
|
try {
|
||||||
bot.send(bot.getChannel(), Colors.CYAN + randomJoke().getMessage() + Colors.NORMAL);
|
bot.send(bot.getChannel(), Utils.cyan(randomJoke().getMessage()));
|
||||||
} catch (ModuleException e) {
|
} catch (ModuleException e) {
|
||||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||||
bot.send(sender, e.getMessage());
|
bot.send(sender, e.getMessage());
|
||||||
|
|
|
@ -44,16 +44,13 @@ import twitter4j.conf.ConfigurationBuilder;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public final class Twitter extends ThreadedModule {
|
public final class Twitter extends ThreadedModule {
|
||||||
/**
|
|
||||||
* The twitter command.
|
|
||||||
*/
|
|
||||||
public static final String TWITTER_CMD = "twitter";
|
|
||||||
|
|
||||||
// The property keys.
|
// The property keys.
|
||||||
private static final String CONSUMER_KEY_PROP = "twitter-consumerKey";
|
private static final String CONSUMER_KEY_PROP = "twitter-consumerKey";
|
||||||
private static final String CONSUMER_SECRET_PROP = "twitter-consumerSecret";
|
private static final String CONSUMER_SECRET_PROP = "twitter-consumerSecret";
|
||||||
private static final String TOKEN_PROP = "twitter-token";
|
private static final String TOKEN_PROP = "twitter-token";
|
||||||
private static final String TOKEN_SECRET_PROP = "twitter-tokenSecret";
|
private static final String TOKEN_SECRET_PROP = "twitter-tokenSecret";
|
||||||
|
// The twitter command.
|
||||||
|
private static final String TWITTER_CMD = "twitter";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link Twitter} instance.
|
* Creates a new {@link Twitter} instance.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue