Added user-agent to jsoup posted link title query.
More code & comments cleanup.
This commit is contained in:
parent
85ed19f259
commit
b720927061
21 changed files with 544 additions and 604 deletions
|
@ -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/'))
|
||||
|
|
862
mobibot.iws
862
mobibot.iws
File diff suppressed because it is too large
Load diff
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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)
|
||||
|
|
|
@ -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<EntryLink> entries, List<String> history, boolean isDayBackup)
|
||||
|
|
|
@ -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<EntryComment> comments = new ArrayList<EntryComment>(0);
|
||||
private final List<EntryComment> comments = new CopyOnWriteArrayList<EntryComment>();
|
||||
|
||||
// The tags/categories
|
||||
private final List<SyndCategoryImpl> tags = new ArrayList<SyndCategoryImpl>(0);
|
||||
private final List<SyndCategoryImpl> tags = new CopyOnWriteArrayList<SyndCategoryImpl>();
|
||||
|
||||
// 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<SyndCategoryImpl> tags)
|
||||
final void setTags(List<SyndCategoryImpl> 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())
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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 <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @created 2014-04-26
|
||||
|
|
|
@ -176,7 +176,7 @@ public class Mobibot extends PircBot
|
|||
private final List<String> recap = new ArrayList<String>(0);
|
||||
|
||||
/**
|
||||
* The {@link Commands#TELL_CMD} messages queue.
|
||||
* Processes the {@link Commands#TELL_CMD} messages queue.
|
||||
*/
|
||||
private final List<TellMessage> tellMessages = new CopyOnWriteArrayList<TellMessage>();
|
||||
|
||||
|
@ -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:<comment>
|
||||
// L1.1:<command>
|
||||
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 + " <id|"
|
||||
+ Commands.TELL_ALL_CMD + '>')
|
||||
);
|
||||
send(sender, "Messages are kept for around " + Utils.bold(tellMaxDays) + " days.");
|
||||
send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.net.URL;
|
|||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* Retrieve quote from <a href="iheartquotes.com">I Heart Quotes</a>
|
||||
* Processes the {@link Commands#QUOTE_CMD} command.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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 <a href="http://iheartquotes.com/">I Heart Quote</a>
|
||||
*/
|
||||
public final void run()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
* <p/>
|
||||
* <p>
|
||||
* http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
|
||||
* <p/>
|
||||
* </p>
|
||||
* 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 <code>get</code> 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)
|
||||
{
|
||||
|
|
|
@ -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 <code>true</code> if the message is queued.
|
||||
*/
|
||||
public Date getQueued()
|
||||
{
|
||||
return queued;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state of the received flag.
|
||||
*
|
||||
* @return <code>true</code> 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 <code>true</code> 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 <code>true</code> if the id matches.
|
||||
*/
|
||||
public boolean isMatchId(String id)
|
||||
{
|
||||
return this.id.equals(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the notification flag state.
|
||||
*
|
||||
* @return <code>true</code> if the sender has been notified.
|
||||
*/
|
||||
public boolean isNotified()
|
||||
{
|
||||
return this.isNotified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the received flag state.
|
||||
*
|
||||
* @return <code>true</code> 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();
|
||||
|
|
|
@ -80,6 +80,11 @@ public class TellMessagesMgr
|
|||
try
|
||||
{
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Loading the messages.");
|
||||
}
|
||||
|
||||
return ((List<TellMessage>) 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<TellMessage> tellMessages, int tellMaxDays)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ import twitter4j.TwitterFactory;
|
|||
import twitter4j.conf.ConfigurationBuilder;
|
||||
|
||||
/**
|
||||
* Inserts presence information into Twitter.
|
||||
* Processes the {@link Commands#TWITTER_CMD} command.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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
|
||||
|
|
|
@ -10,12 +10,13 @@ import java.io.InputStreamReader;
|
|||
|
||||
/**
|
||||
* The <code>TwitterOAuth</code> class.
|
||||
* <p/>
|
||||
* <p>
|
||||
* Go to <a href="http://twitter.com/oauth_clients/new">http://twitter.com/oauth_clients/new</a> to register your bot.
|
||||
* </p>
|
||||
* Then execute:
|
||||
* <p/>
|
||||
* <code>java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret></code>
|
||||
* <p/>
|
||||
* <p>
|
||||
* <code>java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret></code>
|
||||
* </p>
|
||||
* and follow the prompts/instructions.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
|
|
|
@ -36,7 +36,7 @@ package net.thauvin.erik.mobibot;
|
|||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* The <code>War</code> class.
|
||||
* Processes the {@link Commands#WAR_CMD} command.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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)
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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 <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue