Code cleanup.

This commit is contained in:
Erik C. Thauvin 2019-04-09 02:30:01 -07:00
parent 3def574940
commit 844507ea9e
3 changed files with 9 additions and 20 deletions

View file

@ -60,20 +60,14 @@ import java.util.TreeMap;
* @since 1.0
*/
public final class CurrencyConverter extends AbstractModule {
/**
* The rates keyword.
*/
// The rates keyword.
static final String CURRENCY_RATES_KEYWORD = "rates";
// The currency command.
private static final String CURRENCY_CMD = "currency";
// The exchange rates.
private static final Map<String, String> EXCHANGE_RATES = new TreeMap<>();
// The exchange rates table URL.
private static final String EXCHANGE_TABLE_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
// The last exchange rates table publication date.
private static String pubDate = "";
@ -203,7 +197,7 @@ public final class CurrencyConverter extends AbstractModule {
try {
final Message msg = convertCurrency(query);
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());
} catch (ModuleException e) {

View file

@ -32,9 +32,9 @@
package net.thauvin.erik.mobibot.modules;
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.PublicMessage;
import org.jibble.pircbot.Colors;
import org.json.JSONObject;
import java.io.BufferedReader;
@ -51,14 +51,11 @@ import java.nio.charset.StandardCharsets;
* @since 1.0
*/
public final class Joke extends AbstractModule {
/**
* The joke command.
*/
public static final String JOKE_CMD = "joke";
// The ICNDB URL.
private static final String JOKE_URL =
"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.
@ -87,6 +84,7 @@ public final class Joke extends AbstractModule {
final JSONObject json = new JSONObject(sb.toString());
//noinspection RegExpRedundantEscape
return new PublicMessage(
json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'")
.replaceAll("\\\"", "\""));
@ -118,7 +116,7 @@ public final class Joke extends AbstractModule {
*/
private void run(final Mobibot bot, final String sender) {
try {
bot.send(bot.getChannel(), Colors.CYAN + randomJoke().getMessage() + Colors.NORMAL);
bot.send(bot.getChannel(), Utils.cyan(randomJoke().getMessage()));
} catch (ModuleException e) {
bot.getLogger().warn(e.getDebugMessage(), e);
bot.send(sender, e.getMessage());

View file

@ -44,16 +44,13 @@ import twitter4j.conf.ConfigurationBuilder;
* @since 1.0
*/
public final class Twitter extends ThreadedModule {
/**
* The twitter command.
*/
public static final String TWITTER_CMD = "twitter";
// The property keys.
private static final String CONSUMER_KEY_PROP = "twitter-consumerKey";
private static final String CONSUMER_SECRET_PROP = "twitter-consumerSecret";
private static final String TOKEN_PROP = "twitter-token";
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.