Changed Quote module to Joke, using the Internet Chuck Norris Database.

This commit is contained in:
Erik C. Thauvin 2015-08-29 12:54:58 -07:00
parent 80921e2aea
commit b7e6cbe8ca
4 changed files with 138 additions and 198 deletions

View file

@ -127,6 +127,11 @@ public class Commands
*/
public static final String INFO_CMD = "info";
/**
* The joke command.
*/
public static final String JOKE_CMD = "joke";
/**
* The link command.
*/
@ -167,11 +172,6 @@ public class Commands
*/
public static final String PROPS_ARG = "properties";
/**
* The quote command.
*/
public static final String QUOTE_CMD = "quote";
/**
* The recap command.
*/

View file

@ -42,20 +42,20 @@ import java.net.URL;
import java.net.URLConnection;
/**
* Processes the {@link Commands#QUOTE_CMD} command.
* Processes the {@link Commands#JOKE_CMD} command.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2014-04-20
* @since 1.0
*/
public class Quote implements Runnable
public class Joke implements Runnable
{
/**
* The I Heart Quotes URL.
*/
private static final String QUOTE_URL =
"http://www.iheartquotes.com/api/v1/random?format=json&max_lines=1&source=esr+humorix_misc+humorix_stories+joel_on_software+macintosh+math+mav_flame+osp_rules+paul_graham+prog_style+subversion";
private static final String JOKE_URL =
"http://api.icndb.com/jokes/random";
/**
* The bot's instance.
@ -68,25 +68,25 @@ public class Quote implements Runnable
private final String sender;
/**
* Creates a new {@link StockQuote} instance.
* Creates a new {@link Joke} instance.
*
* @param bot The bot's instance.
* @param sender The nick of the person who sent the message.
*/
public Quote(Mobibot bot, String sender)
public Joke(Mobibot bot, String sender)
{
this.bot = bot;
this.sender = sender;
}
/**
* Returns a random quote from <a href="http://iheartquotes.com/">I Heart Quote</a>
* Returns a random joke from <a href="http://www.icndb.com/">The Internet Chuck Norris Database</a>
*/
public final void run()
{
try
{
final URL url = new URL(QUOTE_URL);
final URL url = new URL(JOKE_URL);
final URLConnection conn = url.openConnection();
final StringBuilder sb = new StringBuilder();
@ -100,13 +100,13 @@ public class Quote implements Runnable
final JSONObject json = new JSONObject(sb.toString());
bot.send(bot.getChannel(), Colors.CYAN + json.getString("quote") + Colors.CYAN);
bot.send(bot.getChannel(), Colors.CYAN + json.getJSONObject("value").get("joke") + Colors.CYAN);
reader.close();
}
catch (Exception e)
{
bot.getLogger().warn("Unable to retrieve random quote.", e);
bot.getLogger().warn("Unable to retrieve random joke.", e);
bot.send(sender, "An error has occurred: " + e.getMessage());
}
}

View file

@ -1126,10 +1126,10 @@ public class Mobibot extends PircBot
send(sender, "For a listing of the supported countries:");
send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.TIME_CMD));
}
else if (lcTopic.endsWith(Commands.QUOTE_CMD))
else if (lcTopic.endsWith(Commands.JOKE_CMD))
{
send(sender, "To retrieve a random quote:");
send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.QUOTE_CMD));
send(sender, "To retrieve a random joke:");
send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.JOKE_CMD));
}
else if (lcTopic.endsWith(Commands.STOCK_CMD))
{
@ -1212,7 +1212,9 @@ public class Mobibot extends PircBot
if (lcTopic.endsWith(Commands.CURRENCY_CMD))
{
send(sender, "For a listing of currency rates:");
send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.CURRENCY_CMD) + ' ' + Commands.CURRENCY_RATES_KEYWORD);
send(sender,
DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.CURRENCY_CMD) + ' '
+ Commands.CURRENCY_RATES_KEYWORD);
send(sender, "For a listing of supported currencies:");
send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.CURRENCY_CMD));
}
@ -1251,10 +1253,10 @@ public class Mobibot extends PircBot
cmds.add(Commands.GOOGLE_CMD);
cmds.add(Commands.IGNORE_CMD);
cmds.add(Commands.INFO_CMD);
cmds.add(Commands.JOKE_CMD);
cmds.add(Commands.LOOKUP_CMD);
cmds.add(channel.substring(1));
cmds.add(Commands.HELP_POSTING_KEYWORD);
cmds.add(Commands.QUOTE_CMD);
cmds.add(Commands.RECAP_CMD);
cmds.add(Commands.STOCK_CMD);
cmds.add(Commands.HELP_TAGS_KEYWORD);
@ -1795,10 +1797,10 @@ public class Mobibot extends PircBot
{
stockResponse(sender, args);
}
// mobibot: quote
else if (cmd.startsWith(Commands.QUOTE_CMD))
// mobibot: joke
else if (cmd.startsWith(Commands.JOKE_CMD))
{
new Thread(new Quote(this, sender)).start();
new Thread(new Joke(this, sender)).start();
}
// mobibot: calc
else if (cmd.startsWith(Commands.CALC_CMD))