Messages are now sent when people join, change nick or talk on the channel.
Updated licenses. More code cleanup.
This commit is contained in:
parent
e31a22af11
commit
85ed19f259
21 changed files with 1867 additions and 1262 deletions
|
@ -94,23 +94,6 @@ public class CurrencyConverter implements Runnable
|
|||
this.bot = bot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query.
|
||||
*
|
||||
* @param sender The nick of the person who sent the message.
|
||||
* @param query The currency query.
|
||||
*/
|
||||
public void setQuery(String sender, String query)
|
||||
{
|
||||
this.query = query;
|
||||
this.sender = sender;
|
||||
|
||||
if (!pubDate.equals(Utils.today()))
|
||||
{
|
||||
EXCHANGE_RATES.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Converts specified currencies.
|
||||
public final void run()
|
||||
{
|
||||
|
@ -225,4 +208,21 @@ public class CurrencyConverter implements Runnable
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query.
|
||||
*
|
||||
* @param sender The nick of the person who sent the message.
|
||||
* @param query The currency query.
|
||||
*/
|
||||
public void setQuery(String sender, String query)
|
||||
{
|
||||
this.query = query;
|
||||
this.sender = sender;
|
||||
|
||||
if (!pubDate.equals(Utils.today()))
|
||||
{
|
||||
EXCHANGE_RATES.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ public class EntryComment implements Serializable
|
|||
{
|
||||
/**
|
||||
* The serial version UID.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
static final long serialVersionUID = 6957415292233553224L;
|
||||
|
||||
|
@ -77,9 +75,8 @@ public class EntryComment implements Serializable
|
|||
|
||||
/**
|
||||
* Creates a new comment.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
protected EntryComment()
|
||||
{
|
||||
; // Required for serialization.
|
||||
|
@ -99,9 +96,8 @@ public class EntryComment implements Serializable
|
|||
* Sets the comment.
|
||||
*
|
||||
* @param comment The actual comment.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public final void setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
|
@ -111,9 +107,8 @@ public class EntryComment implements Serializable
|
|||
* Returns the comment's creation date.
|
||||
*
|
||||
* @return The date.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public final Date getDate()
|
||||
{
|
||||
return date;
|
||||
|
|
|
@ -53,8 +53,6 @@ public class EntryLink implements Serializable
|
|||
{
|
||||
/**
|
||||
* The serial version UID.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
static final long serialVersionUID = 3676245542270899086L;
|
||||
|
||||
|
@ -179,16 +177,6 @@ public class EntryLink implements Serializable
|
|||
setTags(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EntryLink object.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
protected EntryLink()
|
||||
{
|
||||
; // Required for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new comment.
|
||||
*
|
||||
|
@ -231,9 +219,8 @@ public class EntryLink implements Serializable
|
|||
* Sets the channel.
|
||||
*
|
||||
* @param channel The channel.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public final synchronized void setChannel(String channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
|
@ -333,9 +320,8 @@ public class EntryLink implements Serializable
|
|||
* Set the comment's author login.
|
||||
*
|
||||
* @param login The new login.
|
||||
*
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public final synchronized void setLogin(String login)
|
||||
{
|
||||
this.login = login;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,9 +10,8 @@ import javax.swing.*;
|
|||
* <p/>
|
||||
* Note that the API changed slightly in the 3rd version: You must now invoke start() on the SwingWorker after creating
|
||||
* it.
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public abstract class SwingWorker
|
||||
{
|
||||
private Object value; // see getValue(), setValue()
|
||||
|
|
|
@ -83,14 +83,9 @@ public class TellMessage implements Serializable
|
|||
|
||||
}
|
||||
|
||||
public String getSender()
|
||||
public String getId()
|
||||
{
|
||||
return sender;
|
||||
}
|
||||
|
||||
public String getRecipient()
|
||||
{
|
||||
return recipient;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
|
@ -108,30 +103,19 @@ public class TellMessage implements Serializable
|
|||
return received;
|
||||
}
|
||||
|
||||
public void setReceived()
|
||||
public String getRecipient()
|
||||
{
|
||||
this.received = Calendar.getInstance().getTime();
|
||||
this.isReceived = true;
|
||||
return recipient;
|
||||
}
|
||||
|
||||
public boolean isNotified()
|
||||
public String getSender()
|
||||
{
|
||||
return this.isNotified;
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setNotified()
|
||||
public boolean isMatch(String nick)
|
||||
{
|
||||
this.isNotified = true;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean isReceived()
|
||||
{
|
||||
return this.isReceived;
|
||||
return (sender.equalsIgnoreCase(nick) || recipient.equalsIgnoreCase(nick));
|
||||
}
|
||||
|
||||
public boolean isMatchId(String id)
|
||||
|
@ -139,8 +123,24 @@ public class TellMessage implements Serializable
|
|||
return this.id.equals(id);
|
||||
}
|
||||
|
||||
public boolean isMatch(String nick)
|
||||
public boolean isNotified()
|
||||
{
|
||||
return (sender.equalsIgnoreCase(nick) || recipient.equalsIgnoreCase(nick));
|
||||
return this.isNotified;
|
||||
}
|
||||
|
||||
public boolean isReceived()
|
||||
{
|
||||
return this.isReceived;
|
||||
}
|
||||
|
||||
public void setIsNotified()
|
||||
{
|
||||
this.isNotified = true;
|
||||
}
|
||||
|
||||
public void setIsReceived()
|
||||
{
|
||||
this.received = Calendar.getInstance().getTime();
|
||||
this.isReceived = true;
|
||||
}
|
||||
}
|
|
@ -139,17 +139,14 @@ public class TellMessagesMgr
|
|||
final Calendar maxDate = Calendar.getInstance();
|
||||
final Date today = new Date();
|
||||
|
||||
synchronized (tellMessages)
|
||||
for (final TellMessage message : tellMessages)
|
||||
{
|
||||
for (final TellMessage message : tellMessages)
|
||||
{
|
||||
maxDate.setTime(message.getQueued());
|
||||
maxDate.add(Calendar.DATE, tellMaxDays);
|
||||
maxDate.setTime(message.getQueued());
|
||||
maxDate.add(Calendar.DATE, tellMaxDays);
|
||||
|
||||
if (maxDate.getTime().before(today))
|
||||
{
|
||||
tellMessages.remove(message);
|
||||
}
|
||||
if (maxDate.getTime().before(today))
|
||||
{
|
||||
tellMessages.remove(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,8 +105,8 @@ public class Utils
|
|||
* @param out The destination file.
|
||||
*
|
||||
* @throws java.io.IOException If the file could not be copied.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static void copyFile(File in, File out)
|
||||
throws IOException
|
||||
{
|
||||
|
@ -295,6 +295,72 @@ public class Utils
|
|||
return ISO_SDF.format(Calendar.getInstance().getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an entry's comment for display on the channel.
|
||||
*
|
||||
* @param entryIndex The entry's index.
|
||||
* @param commentIndex The comment's index.
|
||||
* @param comment The {@link net.thauvin.erik.mobibot.EntryComment comment} object.
|
||||
*
|
||||
* @return The entry's comment.
|
||||
*/
|
||||
static String buildComment(int entryIndex, int commentIndex, EntryComment comment)
|
||||
{
|
||||
return (Commands.LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] "
|
||||
+ comment.getComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an entry's link for display on the channel.
|
||||
*
|
||||
* @param index The entry's index.
|
||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
||||
*
|
||||
* @return The entry's link.
|
||||
*
|
||||
* @see #buildLink(int, net.thauvin.erik.mobibot.EntryLink, boolean)
|
||||
*/
|
||||
static String buildLink(int index, EntryLink entry)
|
||||
{
|
||||
return buildLink(index, entry, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an entry's link for display on the channel.
|
||||
*
|
||||
* @param index The entry's index.
|
||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
||||
* @param isView Set to true to display the number of comments.
|
||||
*
|
||||
* @return The entry's link.
|
||||
*/
|
||||
static String buildLink(int index, EntryLink entry, boolean isView)
|
||||
{
|
||||
final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": ");
|
||||
|
||||
buff.append('[').append(entry.getNick()).append(']');
|
||||
|
||||
if (isView && entry.hasComments())
|
||||
{
|
||||
buff.append("[+").append(entry.getCommentsCount()).append(']');
|
||||
}
|
||||
|
||||
buff.append(' ');
|
||||
|
||||
if (Mobibot.NO_TITLE.equals(entry.getTitle()))
|
||||
{
|
||||
buff.append(bold(entry.getTitle()));
|
||||
}
|
||||
else
|
||||
{
|
||||
buff.append(entry.getTitle());
|
||||
}
|
||||
|
||||
buff.append(" ( ").append(entry.getLink()).append(" )");
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string bold.
|
||||
*
|
||||
|
@ -306,4 +372,17 @@ public class Utils
|
|||
{
|
||||
return Colors.BOLD + s + Colors.BOLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an entry's tags/categories for display on the channel.
|
||||
*
|
||||
* @param entryIndex The entry's index.
|
||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
||||
*
|
||||
* @return The entry's tags.
|
||||
*/
|
||||
static String buildTags(int entryIndex, EntryLink entry)
|
||||
{
|
||||
return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getDeliciousTags().replaceAll(",", ", "));
|
||||
}
|
||||
}
|
|
@ -40,7 +40,6 @@ import net.sf.jweather.metar.WeatherCondition;
|
|||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Fetches the weather data from a specific station ID.
|
||||
|
@ -160,25 +159,17 @@ public class Weather implements Runnable
|
|||
|
||||
if (metar.getWeatherConditions() != null)
|
||||
{
|
||||
final Iterator it = metar.getWeatherConditions().iterator();
|
||||
|
||||
//noinspection WhileLoopReplaceableByForEach
|
||||
while (it.hasNext())
|
||||
for (final Object weatherCondition : metar.getWeatherConditions())
|
||||
{
|
||||
final WeatherCondition weatherCondition = (WeatherCondition) it.next();
|
||||
bot.send(sender, weatherCondition.getNaturalLanguageString(), isPrivate);
|
||||
bot.send(sender, ((WeatherCondition) weatherCondition).getNaturalLanguageString(), isPrivate);
|
||||
}
|
||||
}
|
||||
|
||||
if (metar.getSkyConditions() != null)
|
||||
{
|
||||
final Iterator it = metar.getSkyConditions().iterator();
|
||||
|
||||
//noinspection WhileLoopReplaceableByForEach
|
||||
while (it.hasNext())
|
||||
for (final Object skyCondition : metar.getSkyConditions())
|
||||
{
|
||||
final SkyCondition skyCondition = (SkyCondition) it.next();
|
||||
bot.send(sender, skyCondition.getNaturalLanguageString(), isPrivate);
|
||||
bot.send(sender, ((SkyCondition) skyCondition).getNaturalLanguageString(), isPrivate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue