From b720927061f6fe1636ba5959e14fa67104c4943e Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 30 Apr 2014 02:36:59 -0700 Subject: [PATCH] Added user-agent to jsoup posted link title query. More code & comments cleanup. --- build.gradle | 4 + mobibot.iws | 862 +++++++----------- .../erik/mobibot/CurrencyConverter.java | 12 +- .../thauvin/erik/mobibot/DeliciousPoster.java | 2 +- .../java/net/thauvin/erik/mobibot/Dice.java | 6 +- .../net/thauvin/erik/mobibot/EntriesMgr.java | 3 + .../net/thauvin/erik/mobibot/EntryLink.java | 52 +- .../net/thauvin/erik/mobibot/FeedReader.java | 4 +- .../thauvin/erik/mobibot/GoogleSearch.java | 8 +- .../java/net/thauvin/erik/mobibot/Lookup.java | 2 +- .../net/thauvin/erik/mobibot/Mobibot.java | 54 +- .../java/net/thauvin/erik/mobibot/Quote.java | 10 +- .../net/thauvin/erik/mobibot/StockQuote.java | 8 +- .../net/thauvin/erik/mobibot/SwingWorker.java | 10 +- .../net/thauvin/erik/mobibot/TellMessage.java | 60 ++ .../thauvin/erik/mobibot/TellMessagesMgr.java | 14 +- .../net/thauvin/erik/mobibot/Twitter.java | 9 +- .../thauvin/erik/mobibot/TwitterOAuth.java | 9 +- .../java/net/thauvin/erik/mobibot/War.java | 4 +- .../net/thauvin/erik/mobibot/Weather.java | 8 +- .../net/thauvin/erik/mobibot/WorldTime.java | 7 +- 21 files changed, 544 insertions(+), 604 deletions(-) diff --git a/build.gradle b/build.gradle index 5904064..587ce85 100644 --- a/build.gradle +++ b/build.gradle @@ -67,6 +67,10 @@ compileJava { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } +javadoc { + options.tags = ['created'] +} + jar { manifest.attributes('Main-Class': mainClassName, 'Class-Path': '. ./lib/' + configurations.compile.collect { it.getName() }.join(' ./lib/')) diff --git a/mobibot.iws b/mobibot.iws index 7492a3c..abcd1f6 100644 --- a/mobibot.iws +++ b/mobibot.iws @@ -33,26 +33,26 @@ - - + + + - - - + + + - - + + - - + + + + - - - @@ -124,8 +124,8 @@ @@ -159,112 +159,31 @@ - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -273,44 +192,39 @@ - - + + - - + + - - - - - - - - - - - - - - - + + - - + + - - - - - + + + + + + + + + + + + + @@ -318,8 +232,28 @@ - - + + + + + + + + + + + + + + + + + + + + + + @@ -703,7 +637,7 @@ - + + + - - - @@ -2498,14 +2397,13 @@ - + - - + @@ -2514,23 +2412,24 @@ - + + - + + - - + @@ -2544,22 +2443,22 @@ - + + - - - + - + - + + @@ -2578,28 +2477,28 @@ - - + + - + - - - + + + - + - + @@ -2689,6 +2588,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2776,27 +2706,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -2804,13 +2713,6 @@ - - - - - - - @@ -2842,13 +2744,6 @@ - - - - - - - @@ -2863,13 +2758,6 @@ - - - - - - - @@ -2884,117 +2772,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3002,17 +2783,6 @@ - - - - - - - - - - - @@ -3021,37 +2791,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3060,81 +2799,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java index 607a007..4d18356 100644 --- a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java +++ b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java @@ -46,7 +46,7 @@ import java.text.NumberFormat; import java.util.*; /** - * Converts various currencies. + * Processes the {@link Commands#CURRENCY_CMD} command. * * @author Erik C. Thauvin * @created Feb 11, 2004 @@ -85,16 +85,18 @@ public class CurrencyConverter implements Runnable private String pubDate = ""; /** - * Creates a new CurrencyConverter object. + * Creates a new {@link CurrencyConverter} instance. * - * @param bot The bot. + * @param bot The bot's instance. */ public CurrencyConverter(Mobibot bot) { this.bot = bot; } - // Converts specified currencies. + /** + * Converts the specified currencies. + */ public final void run() { if (Utils.isValidString(sender) && Utils.isValidString(query)) @@ -215,7 +217,7 @@ public class CurrencyConverter implements Runnable * @param sender The nick of the person who sent the message. * @param query The currency query. */ - public void setQuery(String sender, String query) + public synchronized void setQuery(String sender, String query) { this.query = query; this.sender = sender; diff --git a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java b/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java index 8f60136..36ef5ca 100644 --- a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java +++ b/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java @@ -51,7 +51,7 @@ public class DeliciousPoster private final String ircServer; /** - * Creates a new DeliciousPoster instance. + * Creates a new {@link DeliciousPoster} instance. * * @param username The del.icio.us username. * @param password The del.icio.us password. diff --git a/src/main/java/net/thauvin/erik/mobibot/Dice.java b/src/main/java/net/thauvin/erik/mobibot/Dice.java index f5f63d2..7ffdc9f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Dice.java +++ b/src/main/java/net/thauvin/erik/mobibot/Dice.java @@ -36,7 +36,7 @@ package net.thauvin.erik.mobibot; import java.util.Random; /** - * The {@link net.thauvin.erik.mobibot.Commands#DICE_CMD} command + * Processes the {@link Commands#DICE_CMD} command. * * @author Erik C. Thauvin * @created 2014-04-28 @@ -56,9 +56,9 @@ public class Dice } /** - * Rolls the dice + * Rolls the dice. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The sender's nickname. */ public static void roll(Mobibot bot, String sender) diff --git a/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java b/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java index a3add76..e1d00af 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java @@ -214,6 +214,9 @@ public class EntriesMgr /** * Saves the entries. * + * @param bot The bot object. + * @param entries The entries array. + * @param history The history array. * @param isDayBackup Set the true if the daily backup file should also be created. */ public static void saveEntries(Mobibot bot, List entries, List history, boolean isDayBackup) diff --git a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java index 89992d9..d734f6e 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java @@ -37,10 +37,10 @@ package net.thauvin.erik.mobibot; import com.sun.syndication.feed.synd.SyndCategoryImpl; import java.io.Serializable; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * The class used to store link entries. @@ -57,10 +57,10 @@ public class EntryLink implements Serializable static final long serialVersionUID = 3676245542270899086L; // The link's comments - private final List comments = new ArrayList(0); + private final List comments = new CopyOnWriteArrayList(); // The tags/categories - private final List tags = new ArrayList(0); + private final List tags = new CopyOnWriteArrayList(); // The channel private String channel = ""; @@ -106,7 +106,7 @@ public class EntryLink implements Serializable * * @param tags The space-delimited tags. */ - public final synchronized void setTags(String tags) + public final void setTags(String tags) { if (tags != null) { @@ -185,7 +185,7 @@ public class EntryLink implements Serializable * * @return The total number of comments for this entry. */ - public final synchronized int addComment(String comment, String nick) + public final int addComment(String comment, String nick) { comments.add(new EntryComment(comment, nick)); @@ -197,7 +197,7 @@ public class EntryLink implements Serializable * * @param index The index of the comment to delete. */ - public final synchronized void deleteComment(int index) + public final void deleteComment(int index) { if (index < comments.size()) { @@ -210,7 +210,7 @@ public class EntryLink implements Serializable * * @return The channel */ - public final synchronized String getChannel() + public final String getChannel() { return channel; } @@ -221,7 +221,7 @@ public class EntryLink implements Serializable * @param channel The channel. */ @SuppressWarnings("UnusedDeclaration") - public final synchronized void setChannel(String channel) + public final void setChannel(String channel) { this.channel = channel; } @@ -233,7 +233,7 @@ public class EntryLink implements Serializable * * @return The specific comment. */ - public final synchronized EntryComment getComment(int index) + public final EntryComment getComment(int index) { return (comments.get(index)); } @@ -243,7 +243,7 @@ public class EntryLink implements Serializable * * @return The comments. */ - public final synchronized EntryComment[] getComments() + public final EntryComment[] getComments() { return (comments.toArray(new EntryComment[comments.size()])); } @@ -253,7 +253,7 @@ public class EntryLink implements Serializable * * @return The count of comments. */ - public final synchronized int getCommentsCount() + public final int getCommentsCount() { return comments.size(); } @@ -263,7 +263,7 @@ public class EntryLink implements Serializable * * @return The date. */ - public final synchronized Date getDate() + public final Date getDate() { return date; } @@ -273,7 +273,7 @@ public class EntryLink implements Serializable * * @return The tags as a comma-delimited string. */ - public final synchronized String getDeliciousTags() + public final String getDeliciousTags() { final StringBuilder tags = new StringBuilder(nick); @@ -291,7 +291,7 @@ public class EntryLink implements Serializable * * @return The link. */ - public final synchronized String getLink() + public final String getLink() { return link; } @@ -301,7 +301,7 @@ public class EntryLink implements Serializable * * @param link The new link. */ - public final synchronized void setLink(String link) + public final void setLink(String link) { this.link = link; } @@ -311,7 +311,7 @@ public class EntryLink implements Serializable * * @return The login; */ - public final synchronized String getLogin() + public final String getLogin() { return login; } @@ -322,7 +322,7 @@ public class EntryLink implements Serializable * @param login The new login. */ @SuppressWarnings("UnusedDeclaration") - public final synchronized void setLogin(String login) + public final void setLogin(String login) { this.login = login; } @@ -332,7 +332,7 @@ public class EntryLink implements Serializable * * @return The nickname. */ - public final synchronized String getNick() + public final String getNick() { return nick; } @@ -342,7 +342,7 @@ public class EntryLink implements Serializable * * @param nick The new nickname. */ - public final synchronized void setNick(String nick) + public final void setNick(String nick) { this.nick = nick; } @@ -352,7 +352,7 @@ public class EntryLink implements Serializable * * @return The tags. */ - public final synchronized List getTags() + public final List getTags() { return tags; } @@ -362,7 +362,7 @@ public class EntryLink implements Serializable * * @param tags The tags. */ - final synchronized void setTags(List tags) + final void setTags(List tags) { this.tags.addAll(tags); } @@ -372,7 +372,7 @@ public class EntryLink implements Serializable * * @return The title. */ - public final synchronized String getTitle() + public final String getTitle() { return title; } @@ -382,7 +382,7 @@ public class EntryLink implements Serializable * * @param title The new title. */ - public final synchronized void setTitle(String title) + public final void setTitle(String title) { this.title = title; } @@ -392,7 +392,7 @@ public class EntryLink implements Serializable * * @return true if there are comments, false otherwise. */ - public final synchronized boolean hasComments() + public final boolean hasComments() { return (!comments.isEmpty()); } @@ -402,7 +402,7 @@ public class EntryLink implements Serializable * * @return true if there are tags, false otherwise. */ - public final synchronized boolean hasTags() + public final boolean hasTags() { return (!tags.isEmpty()); } @@ -414,7 +414,7 @@ public class EntryLink implements Serializable * @param comment The actual comment. * @param nick The nickname of the author of the comment. */ - public final synchronized void setComment(int index, String comment, String nick) + public final void setComment(int index, String comment, String nick) { if (index < comments.size()) { diff --git a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java index adbcdda..ffc91e9 100644 --- a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java +++ b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java @@ -79,9 +79,9 @@ public class FeedReader implements Runnable private final String url; /** - * Creates a new FeedReader object. + * Creates a new {@link FeedReader} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. * @param url The URL to fetch. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java b/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java index 190a232..7a01981 100644 --- a/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java +++ b/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java @@ -44,7 +44,7 @@ import java.net.URLConnection; import java.net.URLEncoder; /** - * Performs a Google search or spell checking query. + * Processes the {@link Commands#GOOGLE_CMD} command. * * @author Erik C. Thauvin * @created Feb 7, 2004 @@ -73,9 +73,9 @@ public class GoogleSearch implements Runnable private final String sender; /** - * Creates a new GoogleSearch object. + * Creates a new {@link GoogleSearch} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. * @param query The Google query */ @@ -87,7 +87,7 @@ public class GoogleSearch implements Runnable } /** - * Main processing method. + * Searches Google. */ public final void run() { diff --git a/src/main/java/net/thauvin/erik/mobibot/Lookup.java b/src/main/java/net/thauvin/erik/mobibot/Lookup.java index 43884ec..c3a20b1 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Lookup.java +++ b/src/main/java/net/thauvin/erik/mobibot/Lookup.java @@ -41,7 +41,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; /** - * Performs a DNS lookup query. + * Processes the {@link Commands#LOOKUP_CMD} command. * * @author Erik C. Thauvin * @created 2014-04-26 diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index 8cdb5d7..f566027 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -176,7 +176,7 @@ public class Mobibot extends PircBot private final List recap = new ArrayList(0); /** - * The {@link Commands#TELL_CMD} messages queue. + * Processes the {@link Commands#TELL_CMD} messages queue. */ private final List tellMessages = new CopyOnWriteArrayList(); @@ -311,7 +311,7 @@ public class Mobibot extends PircBot private String weblogUrl = ""; /** - * Creates a new Mobibot object. + * Creates a new {@link Mobibot} instance. * * @param server The server. * @param port The port. @@ -346,6 +346,11 @@ public class Mobibot extends PircBot { today = EntriesMgr.loadEntries(this.logsDir + EntriesMgr.CURRENT_XML, this.channel, entries); + if (logger.isDebugEnabled()) + { + logger.debug("Last feed: " + today); + } + if (!Utils.today().equals(today)) { entries.clear(); @@ -787,6 +792,11 @@ public class Mobibot extends PircBot */ private void cleanTellMessages() { + if (logger.isDebugEnabled()) + { + logger.debug("Cleaning the messages."); + } + TellMessagesMgr.cleanTellMessages(tellMessages, tellMaxDays); } @@ -876,13 +886,16 @@ public class Mobibot extends PircBot { EntryLink entry; - for (int i = 0; i < entries.size(); i++) + synchronized (entries) { - entry = entries.get(i); - - if (link.equals(entry.getLink())) + for (int i = 0; i < entries.size(); i++) { - return i; + entry = entries.get(i); + + if (link.equals(entry.getLink())) + { + return i; + } } } @@ -896,7 +909,7 @@ public class Mobibot extends PircBot */ public final String getBacklogsUrl() { - return backLogsUrl; + return this.backLogsUrl; } /** @@ -914,9 +927,9 @@ public class Mobibot extends PircBot * * @return The feed info cache. */ - public final synchronized FeedFetcherCache getFeedInfoCache() + public final FeedFetcherCache getFeedInfoCache() { - return feedInfoCache; + return this.feedInfoCache; } /** @@ -926,7 +939,7 @@ public class Mobibot extends PircBot */ public final String getIrcServer() { - return ircServer; + return this.ircServer; } /** @@ -936,7 +949,7 @@ public class Mobibot extends PircBot */ public final String getLogsDir() { - return logsDir; + return this.logsDir; } /** @@ -973,9 +986,9 @@ public class Mobibot extends PircBot * * @return Today's date. */ - public synchronized String getToday() + public String getToday() { - return today; + return this.today; } /** @@ -985,7 +998,7 @@ public class Mobibot extends PircBot */ public final String getWeblogUrl() { - return weblogUrl; + return this.weblogUrl; } /** @@ -1198,7 +1211,7 @@ public class Mobibot extends PircBot send(sender, "To view queued and sent messages:"); send(sender, DOUBLE_INDENT + Utils.bold(getNick() + ": " + Commands.TELL_CMD + ' ' + Commands.VIEW_CMD)); - send(sender, "Messages are kept for around " + Utils.bold(tellMaxDays) + " days."); + send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days."); } else { @@ -1362,6 +1375,7 @@ public class Mobibot extends PircBot timeInSeconds -= (hours * 3600L); final long minutes = timeInSeconds / 60L; + send(sender, "Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " + entries.size() + (isTellEnabled() && isOp(sender) ? ", Messages: " + tellMessages.size() : "") + ']', @@ -1565,7 +1579,7 @@ public class Mobibot extends PircBot if (dupIndex == -1) { - if (!Utils.today().equals(getToday())) + if (!Utils.today().equals(today)) { isBackup = true; saveEntries(true); @@ -1600,7 +1614,7 @@ public class Mobibot extends PircBot { try { - final Document html = Jsoup.connect(link).get(); + final Document html = Jsoup.connect(link).userAgent("Mozilla").get(); final String htmlTitle = html.title(); if (Utils.isValidString(htmlTitle)) @@ -1968,7 +1982,7 @@ public class Mobibot extends PircBot } } } - // L1.1: + // L1.1: else if (message.matches(Commands.LINK_CMD + "[0-9]+\\.[0-9]+:.*")) { isCommand = true; @@ -2503,7 +2517,7 @@ public class Mobibot extends PircBot .bold(getNick() + ": " + Commands.TELL_CMD + ' ' + Commands.TELL_DEL_CMD + " ') ); - send(sender, "Messages are kept for around " + Utils.bold(tellMaxDays) + " days."); + send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days."); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/Quote.java b/src/main/java/net/thauvin/erik/mobibot/Quote.java index 721a384..b626988 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Quote.java +++ b/src/main/java/net/thauvin/erik/mobibot/Quote.java @@ -43,7 +43,7 @@ import java.net.URL; import java.net.URLConnection; /** - * Retrieve quote from I Heart Quotes + * Processes the {@link Commands#QUOTE_CMD} command. * * @author Erik C. Thauvin * @created 2014-04-20 @@ -59,7 +59,7 @@ public class Quote implements Runnable "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"; /** - * The bot. + * The bot's instance. */ private final Mobibot bot; @@ -69,9 +69,9 @@ public class Quote implements Runnable private final String sender; /** - * Creates a new StockQuote object. + * Creates a new {@link StockQuote} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. */ public Quote(Mobibot bot, String sender) @@ -81,7 +81,7 @@ public class Quote implements Runnable } /** - * Returns a random quote. + * Returns a random quote from I Heart Quote */ public final void run() { diff --git a/src/main/java/net/thauvin/erik/mobibot/StockQuote.java b/src/main/java/net/thauvin/erik/mobibot/StockQuote.java index 492c1f5..50d57e6 100644 --- a/src/main/java/net/thauvin/erik/mobibot/StockQuote.java +++ b/src/main/java/net/thauvin/erik/mobibot/StockQuote.java @@ -41,7 +41,7 @@ import org.apache.commons.httpclient.methods.GetMethod; import java.io.IOException; /** - * Retrieves a stock quote from Yahoo!. + * Processes the {@link Commands#STOCK_CMD} command. * * @author Erik C. Thauvin * @created Feb 7, 2004 @@ -70,9 +70,9 @@ public class StockQuote implements Runnable private final String symbol; /** - * Creates a new StockQuote object. + * Creates a new {@link StockQuote} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. * @param symbol The stock symbol. */ @@ -84,7 +84,7 @@ public class StockQuote implements Runnable } /** - * Returns the specified stock quote. + * Returns the specified stock quote from Yahoo! */ public final void run() { diff --git a/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java b/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java index 53307b9..c99a9ab 100644 --- a/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java +++ b/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java @@ -5,9 +5,9 @@ import javax.swing.*; /** * This is the 3rd version of SwingWorker (also known as SwingWorker 3), an abstract class that you subclass to perform * GUI-related work in a dedicated thread. For instructions on and examples of using this class, see: - *

+ *

* http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html - *

+ *

* Note that the API changed slightly in the 3rd version: You must now invoke start() on the SwingWorker after creating * it. */ @@ -62,6 +62,8 @@ public abstract class SwingWorker /** * Compute the value to be returned by the get method. + * + * @return The computed value. */ public abstract Object construct(); @@ -107,6 +109,8 @@ public abstract class SwingWorker /** * Get the value produced by the worker thread, or null if it hasn't been constructed yet. + * + * @return The value. */ protected synchronized Object getValue() { @@ -115,6 +119,8 @@ public abstract class SwingWorker /** * Set the value produced by worker thread + * + * @param x The object. */ private synchronized void setValue(Object x) { diff --git a/src/main/java/net/thauvin/erik/mobibot/TellMessage.java b/src/main/java/net/thauvin/erik/mobibot/TellMessage.java index 030b825..ceb9de2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TellMessage.java +++ b/src/main/java/net/thauvin/erik/mobibot/TellMessage.java @@ -83,61 +83,121 @@ public class TellMessage implements Serializable } + /** + * Returns the message id. + * + * @return The message id. + */ public String getId() { return this.id; } + /** + * Returns the message text. + * + * @return The text of the message. + */ public String getMessage() { return message; } + /** + * Returns the state of the queue flag. + * + * @return true if the message is queued. + */ public Date getQueued() { return queued; } + /** + * Returns the state of the received flag. + * + * @return true if the message has been received. + */ public Date getReceived() { return received; } + /** + * Returns the message's recipient. + * + * @return The recipient of the message. + */ public String getRecipient() { return recipient; } + /** + * Returns the message's sender. + * + * @return The sender of the message. + */ public String getSender() { return sender; } + /** + * Matches the message sender or recipient. + * + * @param nick The nickname to match with. + * + * @return true if the nickname matches. + */ public boolean isMatch(String nick) { return (sender.equalsIgnoreCase(nick) || recipient.equalsIgnoreCase(nick)); } + /** + * Match the message ID. + * + * @param id The ID to match with. + * + * @return true if the id matches. + */ public boolean isMatchId(String id) { return this.id.equals(id); } + /** + * Returns the notification flag state. + * + * @return true if the sender has been notified. + */ public boolean isNotified() { return this.isNotified; } + /** + * Returns the received flag state. + * + * @return true if the message was received. + */ public boolean isReceived() { return this.isReceived; } + /** + * Sets the notified flag. + */ public void setIsNotified() { this.isNotified = true; } + /** + * Sets the received flag. + */ public void setIsReceived() { this.received = Calendar.getInstance().getTime(); diff --git a/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java b/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java index b0b9d43..bb261e5 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java +++ b/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java @@ -80,6 +80,11 @@ public class TellMessagesMgr try { + if (logger.isDebugEnabled()) + { + logger.debug("Loading the messages."); + } + return ((List) input.readObject()); } finally @@ -118,6 +123,10 @@ public class TellMessagesMgr try { + if (logger.isDebugEnabled()) + { + logger.debug("Saving the messages."); + } output.writeObject(messages); } finally @@ -132,7 +141,10 @@ public class TellMessagesMgr } /** - * Cleans the messages queue. + * Cleans the messages queue + * + * @param tellMessages The messages list. + * @param tellMaxDays The maximum number of days to keep messages for. */ public static void cleanTellMessages(List tellMessages, int tellMaxDays) { diff --git a/src/main/java/net/thauvin/erik/mobibot/Twitter.java b/src/main/java/net/thauvin/erik/mobibot/Twitter.java index 23fd404..049a15f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Twitter.java +++ b/src/main/java/net/thauvin/erik/mobibot/Twitter.java @@ -39,7 +39,7 @@ import twitter4j.TwitterFactory; import twitter4j.conf.ConfigurationBuilder; /** - * Inserts presence information into Twitter. + * Processes the {@link Commands#TWITTER_CMD} command. * * @author Erik C. Thauvin * @created Sept 10, 2008 @@ -83,9 +83,9 @@ public class Twitter implements Runnable private final String sender; /** - * Creates a new Twitter object. + * Creates a new {@link Twitter} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. * @param consumerKey The Twitter consumer key. * @param consumerSecret The Twitter consumer secret. @@ -105,6 +105,9 @@ public class Twitter implements Runnable this.sender = sender; } + /** + * Posts to twitter. + */ public final void run() { try diff --git a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java index 1bcb5ba..3fa40a7 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java +++ b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java @@ -10,12 +10,13 @@ import java.io.InputStreamReader; /** * The TwitterOAuth class. - *

+ *

* Go to http://twitter.com/oauth_clients/new to register your bot. + *

* Then execute: - *

- * java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth - *

+ *

+ * java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret> + *

* and follow the prompts/instructions. * * @author Erik C. Thauvin diff --git a/src/main/java/net/thauvin/erik/mobibot/War.java b/src/main/java/net/thauvin/erik/mobibot/War.java index 6430374..ec2ba9f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/War.java +++ b/src/main/java/net/thauvin/erik/mobibot/War.java @@ -36,7 +36,7 @@ package net.thauvin.erik.mobibot; import java.util.Random; /** - * The War class. + * Processes the {@link Commands#WAR_CMD} command. * * @author Erik C. Thauvin * @created 2014-04-28 @@ -69,7 +69,7 @@ public class War /** * Plays war. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The sender's nickname. */ public static void play(Mobibot bot, String sender) diff --git a/src/main/java/net/thauvin/erik/mobibot/Weather.java b/src/main/java/net/thauvin/erik/mobibot/Weather.java index af9eab7..105e770 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Weather.java +++ b/src/main/java/net/thauvin/erik/mobibot/Weather.java @@ -42,7 +42,7 @@ import java.text.DecimalFormat; import java.util.Date; /** - * Fetches the weather data from a specific station ID. + * Processes the {@link Commands#LOOKUP_CMD} command. * * @author Erik C. Thauvin * @created Feb 7, 2004 @@ -81,9 +81,9 @@ public class Weather implements Runnable private final boolean isPrivate; /** - * Creates a new Weather object. + * Creates a new {@link Weather} instance. * - * @param bot The bot. + * @param bot The bot's instance. * @param sender The nick of the person who sent the message. * @param station The station ID. * @param isPrivate Set to true is the response should be send as a private message. @@ -97,7 +97,7 @@ public class Weather implements Runnable } /** - * Main processing method. + * Fetches the weather data from a specific station ID. */ public final void run() { diff --git a/src/main/java/net/thauvin/erik/mobibot/WorldTime.java b/src/main/java/net/thauvin/erik/mobibot/WorldTime.java index e22514f..26eccfe 100644 --- a/src/main/java/net/thauvin/erik/mobibot/WorldTime.java +++ b/src/main/java/net/thauvin/erik/mobibot/WorldTime.java @@ -40,7 +40,7 @@ import java.util.TimeZone; import java.util.TreeMap; /** - * Processes the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD} command. + * The {@link Commands#TIME_CMD} command. * * @author Erik C. Thauvin * @created 2014-04-27 @@ -65,7 +65,7 @@ public class WorldTime new SimpleDateFormat("'The time is 'HH:mm' on 'EEEE, d MMMM yyyy' in '"); /** - * Creates a new time object. + * Creates a new {@link WorldTime} instance. */ public WorldTime() { @@ -140,8 +140,9 @@ public class WorldTime } /** - * Responds with the current time. + * Responds with the current time in the specified timezone/country. * + * @param bot The bot instance. * @param sender The nick of the person who sent the message. * @param args The time command arguments. * @param isPrivate Set to true is the response should be send as a private message.