diff --git a/mobibot.iml b/mobibot.iml index 66b7d51..bce15a1 100644 --- a/mobibot.iml +++ b/mobibot.iml @@ -1,5 +1,5 @@ - + @@ -31,5 +31,4 @@ - - + \ No newline at end of file diff --git a/mobibot.ipr b/mobibot.ipr index c5eb45b..fdac789 100644 --- a/mobibot.ipr +++ b/mobibot.ipr @@ -72,20 +72,24 @@ - - + + + + @@ -120,7 +124,7 @@ @@ -651,7 +655,7 @@ - + @@ -840,5 +844,4 @@ - - + \ No newline at end of file diff --git a/mobibot.iws b/mobibot.iws index 5a560ff..05024de 100644 --- a/mobibot.iws +++ b/mobibot.iws @@ -1,6 +1,7 @@ + @@ -33,14 +34,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -140,138 +167,108 @@ - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + - - - + + + + + - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -314,6 +311,34 @@ + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -809,6 +735,9 @@ + + true + @@ -816,9 +745,6 @@ - - - @@ -855,10 +781,10 @@ - @@ -1554,14 +1480,6 @@ - - - - - - @@ -1592,6 +1510,14 @@ + + + + + + @@ -1640,7 +1566,7 @@ @@ -1650,11 +1576,11 @@ @@ -1664,15 +1590,15 @@ @@ -1682,51 +1608,23 @@ - - - - - - - - - - - - - - - - @@ -1776,7 +1674,7 @@ - + @@ -1812,6 +1710,7 @@ + @@ -1841,65 +1740,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + @@ -1955,15 +1910,18 @@ - - @@ -2326,6 +2230,7 @@ 1267745358497 + - @@ -2418,110 +2345,110 @@ - - + + - - - - - - - - - - - - - - - + + - + - - - + + + + + + + + + + + + + + + + + + + - + + + + + - - - - - - - - - - - - - - - - + + + + + + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2592,8 +2519,17 @@ - + + + + + + + + + - @@ -2622,9 +2565,6 @@ - - - @@ -2684,24 +2624,7 @@ - - - - - - - - - - - - - - - - - @@ -2723,9 +2646,6 @@ - - - @@ -2753,27 +2673,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -2781,61 +2680,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2843,55 +2691,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2899,7 +2698,6 @@ - @@ -2907,23 +2705,6 @@ - - - - - - - - - - - - - - - - - @@ -2931,7 +2712,6 @@ - @@ -2939,15 +2719,6 @@ - - - - - - - - - @@ -2955,82 +2726,198 @@ + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + @@ -3131,7 +3018,7 @@ - 1.7.x + 1.8.x - - + \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/mobibot/Commands.java b/src/main/java/net/thauvin/erik/mobibot/Commands.java index 47dbedf..9d8b08c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Commands.java +++ b/src/main/java/net/thauvin/erik/mobibot/Commands.java @@ -1,7 +1,7 @@ /* - * @(#)Commands.java + * Commands.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; /** @@ -43,6 +42,16 @@ package net.thauvin.erik.mobibot; */ public class Commands { + /** + * The add (back)log command. + */ + public static final String ADDLOG_CMD = "addlog"; + + /** + * The math command. + */ + public static final String CALC_CMD = "calc"; + /** * The currency command. */ @@ -54,35 +63,15 @@ public class Commands public static final String CURRENCY_RATES_KEYWORD = "rates"; /** - * The weather command. + * The cycle command. */ - public static final String WEATHER_CMD = "weather"; + public static final String CYCLE_CMD = "cycle"; /** * Debug command line argument. */ public static final String DEBUG_ARG = "debug"; - /** - * Help command line argument. - */ - public static final String HELP_ARG = "help"; - - /** - * Properties command line argument. - */ - public static final String PROPS_ARG = "properties"; - - /** - * Properties version line argument. - */ - public static final String VERSION_ARG = "version"; - - /** - * The add (back)log command. - */ - public static final String ADDLOG_CMD = "addlog"; - /** * The debug command. */ @@ -93,35 +82,20 @@ public class Commands */ public static final String DICE_CMD = "dice"; - /** - * The say command. - */ - public static final String SAY_CMD = "say"; - /** * The die command. */ public static final String DIE_CMD = "die"; /** - * The cycle command. + * The Google command. */ - public static final String CYCLE_CMD = "cycle"; + public static final String GOOGLE_CMD = "google"; /** - * The msg command. + * Help command line argument. */ - public static final String MSG_CMD = "msg"; - - /** - * The ignore command. - */ - public static final String IGNORE_CMD = "ignore"; - - /** - * The ignore me keyword. - */ - public static final String IGNORE_ME_KEYWORD = "me"; + public static final String HELP_ARG = "help"; /** * The help command. @@ -139,29 +113,19 @@ public class Commands public static final String HELP_TAGS_KEYWORD = "tags"; /** - * The Google command. + * The ignore command. */ - public static final String GOOGLE_CMD = "google"; + public static final String IGNORE_CMD = "ignore"; /** - * The Twitter command. + * The ignore me keyword. */ - public static final String TWITTER_CMD = "twitter"; + public static final String IGNORE_ME_KEYWORD = "me"; /** - * The math command. + * The info command. */ - public static final String CALC_CMD = "calc"; - - /** - * The me command. - */ - public static final String ME_CMD = "me"; - - /** - * The nick command. - */ - public static final String NICK_CMD = "nick"; + public static final String INFO_CMD = "info"; /** * The link command. @@ -173,6 +137,21 @@ public class Commands */ public static final String LOOKUP_CMD = "lookup"; + /** + * The me command. + */ + public static final String ME_CMD = "me"; + + /** + * The msg command. + */ + public static final String MSG_CMD = "msg"; + + /** + * The nick command. + */ + public static final String NICK_CMD = "nick"; + /** * The ping command. */ @@ -183,6 +162,11 @@ public class Commands */ public static final String PONG_CMD = "pong"; + /** + * Properties command line argument. + */ + public static final String PROPS_ARG = "properties"; + /** * The quote command. */ @@ -193,15 +177,20 @@ public class Commands */ public static final String RECAP_CMD = "recap"; + /** + * The say command. + */ + public static final String SAY_CMD = "say"; + /** * The stock command. */ public static final String STOCK_CMD = "stock"; /** - * The time command. + * The {@link #TELL_CMD} all command. */ - public static final String TIME_CMD = "time"; + public static final String TELL_ALL_CMD = "all"; /** * The tell command. @@ -214,14 +203,14 @@ public class Commands public static final String TELL_DEL_CMD = "del"; /** - * The {@link #TELL_CMD} all command. + * The time command. */ - public static final String TELL_ALL_CMD = "all"; + public static final String TIME_CMD = "time"; /** - * The war command. + * The Twitter command. */ - public static final String WAR_CMD = "war"; + public static final String TWITTER_CMD = "twitter"; /** * The users command. @@ -229,9 +218,9 @@ public class Commands public static final String USERS_CMD = "users"; /** - * The info command. + * Properties version line argument. */ - public static final String INFO_CMD = "info"; + public static final String VERSION_ARG = "version"; /** * The version command. @@ -243,10 +232,20 @@ public class Commands */ public static final String VIEW_CMD = "view"; + /** + * The war command. + */ + public static final String WAR_CMD = "war"; + + /** + * The weather command. + */ + public static final String WEATHER_CMD = "weather"; + /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private Commands() throws UnsupportedOperationException diff --git a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java index 4d18356..f5936c9 100644 --- a/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java +++ b/src/main/java/net/thauvin/erik/mobibot/CurrencyConverter.java @@ -1,7 +1,7 @@ /* - * @(#)CurrencyConverter.java + * CurrencyConverter.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.jdom.Document; @@ -54,21 +53,26 @@ import java.util.*; */ public class CurrencyConverter implements Runnable { - /** - * The exchange rates table URL. - */ - private static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"; - /** * The exchange rates. */ private static final Map EXCHANGE_RATES = new TreeMap(); + /** + * The exchange rates table URL. + */ + private static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"; + /** * The bot. */ private final Mobibot bot; + /** + * The last exchange rates table publication date. + */ + private String pubDate = ""; + /** * The actual currency query. */ @@ -79,11 +83,6 @@ public class CurrencyConverter implements Runnable */ private String sender; - /** - * The last exchange rates table publication date. - */ - private String pubDate = ""; - /** * Creates a new {@link CurrencyConverter} instance. * @@ -165,8 +164,7 @@ public class CurrencyConverter implements Runnable NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' + cmds[1].toUpperCase() + " = " + NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from) - .substring(1) + ' ' + cmds[3].toUpperCase() - ); + .substring(1) + ' ' + cmds[3].toUpperCase()); } catch (NullPointerException ignored) { diff --git a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java b/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java index 36ef5ca..8dcce8b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java +++ b/src/main/java/net/thauvin/erik/mobibot/DeliciousPoster.java @@ -1,7 +1,7 @@ /* - * @(#)DeliciousPoster.java + * DeliciousPoster.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import del.icio.us.Delicious; diff --git a/src/main/java/net/thauvin/erik/mobibot/Dice.java b/src/main/java/net/thauvin/erik/mobibot/Dice.java index 7ffdc9f..7a324f4 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Dice.java +++ b/src/main/java/net/thauvin/erik/mobibot/Dice.java @@ -1,7 +1,7 @@ /* - * @(#)Dice.java + * Dice.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,7 +47,7 @@ public class Dice /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private Dice() throws UnsupportedOperationException @@ -71,8 +71,7 @@ public class Dice bot.send(bot.getChannel(), sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils - .bold(playerTotal) - ); + .bold(playerTotal)); i = r.nextInt(6) + 1; y = r.nextInt(6) + 1; diff --git a/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java b/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java index 91ac6db..e28ae8c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntriesMgr.java @@ -1,7 +1,7 @@ /* - * @(#)EntriesMgr.java + * EntriesMgr.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -75,7 +75,7 @@ public class EntriesMgr /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private EntriesMgr() throws UnsupportedOperationException @@ -83,6 +83,55 @@ public class EntriesMgr throw new UnsupportedOperationException("Illegal constructor call."); } + /** + * Loads the backlogs. + * + * @param file The file containing the backlogs. + * @param history The history list. + * + * @throws FileNotFoundException If the file was not found. + * @throws FeedException If an error occurred while reading the feed. + */ + public static void loadBacklogs(String file, List history) + throws FileNotFoundException, FeedException + { + history.clear(); + + final SyndFeedInput input = new SyndFeedInput(); + + InputStreamReader reader = null; + + try + { + reader = new InputStreamReader(new FileInputStream(new File(file))); + + final SyndFeed feed = input.build(reader); + + final List items = feed.getEntries(); + SyndEntry item; + + for (int i = items.size() - 1; i >= 0; i--) + { + item = (SyndEntryImpl) items.get(i); + history.add(item.getTitle()); + } + } + finally + { + if (reader != null) + { + try + { + reader.close(); + } + catch (IOException ignore) + { + ; // Do nothing + } + } + } + } + /** * Loads the current entries. * @@ -167,55 +216,6 @@ public class EntriesMgr return today; } - /** - * Loads the backlogs. - * - * @param file The file containing the backlogs. - * @param history The history list. - * - * @throws FileNotFoundException If the file was not found. - * @throws FeedException If an error occurred while reading the feed. - */ - public static void loadBacklogs(String file, List history) - throws FileNotFoundException, FeedException - { - history.clear(); - - final SyndFeedInput input = new SyndFeedInput(); - - InputStreamReader reader = null; - - try - { - reader = new InputStreamReader(new FileInputStream(new File(file))); - - final SyndFeed feed = input.build(reader); - - final List items = feed.getEntries(); - SyndEntry item; - - for (int i = items.size() - 1; i >= 0; i--) - { - item = (SyndEntryImpl) items.get(i); - history.add(item.getTitle()); - } - } - finally - { - if (reader != null) - { - try - { - reader.close(); - } - catch (IOException ignore) - { - ; // Do nothing - } - } - } - } - /** * Saves the entries. * @@ -260,8 +260,7 @@ public class EntriesMgr buff = new StringBuffer( "Posted by " + entry.getNick() + " on " + entry.getChannel() + "" - ); + + entry.getChannel() + "\">" + entry.getChannel() + ""); if (entry.getCommentsCount() > 0) { diff --git a/src/main/java/net/thauvin/erik/mobibot/EntryComment.java b/src/main/java/net/thauvin/erik/mobibot/EntryComment.java index d7b26d8..1fe3eae 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntryComment.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntryComment.java @@ -1,7 +1,7 @@ /* - * @(#)EntryComment.java + * EntryComment.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import java.io.Serializable; diff --git a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java index d734f6e..ceee3f3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/EntryLink.java +++ b/src/main/java/net/thauvin/erik/mobibot/EntryLink.java @@ -1,7 +1,7 @@ /* - * @(#)EntryLink.java + * EntryLink.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import com.sun.syndication.feed.synd.SyndCategoryImpl; diff --git a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java index ffc91e9..f12f88d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java +++ b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java @@ -1,7 +1,7 @@ /* - * @(#)FeedReader.java + * FeedReader.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import com.sun.syndication.feed.synd.SyndEntry; diff --git a/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java b/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java index 7a01981..4032836 100644 --- a/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java +++ b/src/main/java/net/thauvin/erik/mobibot/GoogleSearch.java @@ -1,7 +1,7 @@ /* - * @(#)GoogleSearch.java + * GoogleSearch.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.json.JSONArray; diff --git a/src/main/java/net/thauvin/erik/mobibot/Lookup.java b/src/main/java/net/thauvin/erik/mobibot/Lookup.java index c3a20b1..d42c2a3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Lookup.java +++ b/src/main/java/net/thauvin/erik/mobibot/Lookup.java @@ -1,7 +1,7 @@ /* - * @(#)Lookup.java + * Lookup.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.apache.commons.net.WhoisClient; @@ -59,7 +58,7 @@ public class Lookup /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private Lookup() throws UnsupportedOperationException diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index b779157..77308f3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -1,7 +1,7 @@ /* - * @(#)Mobibot.java + * Mobibot.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -83,21 +83,11 @@ public class Mobibot extends PircBot private static final int DEFAULT_TELL_MAX_DAYS = 7; - /** - * The number of days message are kept. - */ - private int tellMaxDays = DEFAULT_TELL_MAX_DAYS; - /** * The default {@link Commands#TELL_CMD) message max queue size. */ private static final int DEFAULT_TELL_MAX_SIZE = 50; - /** - * The maximum number of {@link Commands#TELL_CMD} messages allowed. - */ - private int tellMaxSize = DEFAULT_TELL_MAX_SIZE; - /** * The double tab indent (8 spaces). */ @@ -280,6 +270,16 @@ public class Mobibot extends PircBot */ private String identNick = ""; + /** + * The number of days message are kept. + */ + private int tellMaxDays = DEFAULT_TELL_MAX_DAYS; + + /** + * The maximum number of {@link Commands#TELL_CMD} messages allowed. + */ + private int tellMaxSize = DEFAULT_TELL_MAX_SIZE; + /** * Today's date. */ @@ -1301,8 +1301,7 @@ public class Mobibot extends PircBot send(sender, DOUBLE_INDENT + Utils .bold(Commands.CYCLE_CMD + " " + Commands.ME_CMD + " " + Commands.MSG_CMD + " " - + Commands.SAY_CMD + " " + Commands.VERSION_CMD) - ); + + Commands.SAY_CMD + " " + Commands.VERSION_CMD)); } } } @@ -1401,8 +1400,7 @@ public class Mobibot extends PircBot send(sender, "Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " + entries.size() + (isTellEnabled() && isOp(sender) ? ", Messages: " + tellMessages.size() : "") + ']', - isPrivate - ); + isPrivate); } /** @@ -2268,8 +2266,7 @@ public class Mobibot extends PircBot private void recap(String sender, String message, boolean isAction) { recap.add(Utils.UTC_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ") - + message - ); + + message); if (recap.size() > MAX_RECAP) { @@ -2321,8 +2318,7 @@ public class Mobibot extends PircBot { send(nickname, Utils.bold("You") + " wanted me to remind you: " + Colors.REVERSE + message - .getMessage() + Colors.REVERSE, true - ); + .getMessage() + Colors.REVERSE, true); message.setIsReceived(); message.setIsNotified(); @@ -2335,8 +2331,7 @@ public class Mobibot extends PircBot send(nickname, message.getSender() + " wanted me to tell you: " + Colors.REVERSE + message .getMessage() + Colors.REVERSE, - true - ); + true); message.setIsReceived(); @@ -2350,8 +2345,7 @@ public class Mobibot extends PircBot "Your message " + Colors.REVERSE + "[ID " + message.getId() + ']' + Colors.REVERSE + " was sent to " + Utils.bold(message.getRecipient()) + " on " + Utils.UTC_SDF .format(message.getReceived()), - true - ); + true); message.setIsNotified(); @@ -2471,8 +2465,7 @@ public class Mobibot extends PircBot send(sender, Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [ID: " + message.getId() + ", " + (message.isReceived() ? "DELIVERED" : "QUEUED") + ']', - true - ); + true); } } else @@ -2500,8 +2493,7 @@ public class Mobibot extends PircBot Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [" + Utils.UTC_SDF.format(message.getReceived()) + ", ID: " + message.getId() + ", DELIVERED]", - true - ); + true); } else @@ -2509,8 +2501,7 @@ public class Mobibot extends PircBot send(sender, Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [" + Utils.UTC_SDF.format(message.getQueued()) + ", ID: " + message.getId() + ", QUEUED]", - true - ); + true); } send(sender, DOUBLE_INDENT + message.getMessage(), true); @@ -2527,8 +2518,7 @@ public class Mobibot extends PircBot send(sender, DOUBLE_INDENT + Utils .bold(getNick() + ": " + Commands.TELL_CMD + ' ' + Commands.TELL_DEL_CMD + " ') - ); + + Commands.TELL_ALL_CMD + '>')); send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days."); } } @@ -2789,8 +2779,7 @@ public class Mobibot extends PircBot send(sender, "To view more, try: " + Utils .bold(getNick() + ": " + Commands.VIEW_CMD + ' ' + (i + 1) + ' ' + lcArgs), - isPrivate - ); + isPrivate); break; } diff --git a/src/main/java/net/thauvin/erik/mobibot/Quote.java b/src/main/java/net/thauvin/erik/mobibot/Quote.java index b626988..4838d48 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Quote.java +++ b/src/main/java/net/thauvin/erik/mobibot/Quote.java @@ -1,7 +1,7 @@ /* - * @(#)Quote.java + * Quote.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.jibble.pircbot.Colors; diff --git a/src/main/java/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/main/java/net/thauvin/erik/mobibot/ReleaseInfo.java index 7caf1ec..d17fb03 100644 --- a/src/main/java/net/thauvin/erik/mobibot/ReleaseInfo.java +++ b/src/main/java/net/thauvin/erik/mobibot/ReleaseInfo.java @@ -1,7 +1,7 @@ /* - * @(#)ReleaseInfo.java + * ReleaseInfo.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -82,6 +82,16 @@ public class ReleaseInfo return buildDate; } + /** + * Get buildNumber (set during build process to 0). + * + * @return int buildNumber + */ + public static int getBuildNumber() + { + return 0; + } + /** * Get project (set during build process to "mobibot"). * @@ -102,14 +112,4 @@ public class ReleaseInfo return version; } - /** - * Get buildNumber (set during build process to 0). - * - * @return int buildNumber - */ - public static int getBuildNumber() - { - return 0; - } - } diff --git a/src/main/java/net/thauvin/erik/mobibot/StockQuote.java b/src/main/java/net/thauvin/erik/mobibot/StockQuote.java index 50d57e6..a2bd7fa 100644 --- a/src/main/java/net/thauvin/erik/mobibot/StockQuote.java +++ b/src/main/java/net/thauvin/erik/mobibot/StockQuote.java @@ -1,7 +1,7 @@ /* - * @(#)StockQuote.java + * StockQuote.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import com.Ostermiller.util.CSVParser; diff --git a/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java b/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java index c99a9ab..e19c1d2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java +++ b/src/main/java/net/thauvin/erik/mobibot/SwingWorker.java @@ -4,20 +4,20 @@ 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: - *

+ * 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. + *

+ * Note that the API changed slightly in the 3rd version: + * You must now invoke start() on the SwingWorker after creating it. */ @SuppressWarnings("ALL") public abstract class SwingWorker { - private Object value; // see getValue(), setValue() - private ThreadVar threadVar; + private Object value; // see getValue(), setValue() + /** * Start a thread that will call the construct method and then exit. */ @@ -67,19 +67,6 @@ public abstract class SwingWorker */ public abstract Object construct(); - /** - * A new method that interrupts the worker thread. Call this method to force the worker to stop what it's doing. - */ - public void interrupt() - { - Thread t = threadVar.get(); - if (t != null) - { - t.interrupt(); - } - threadVar.clear(); - } - /** * Return the value created by the construct method. Returns null if either the constructing thread or * the current thread was interrupted before a value was produced. @@ -127,6 +114,19 @@ public abstract class SwingWorker value = x; } + /** + * A new method that interrupts the worker thread. Call this method to force the worker to stop what it's doing. + */ + public void interrupt() + { + Thread t = threadVar.get(); + if (t != null) + { + t.interrupt(); + } + threadVar.clear(); + } + /** * Start the worker thread. */ @@ -151,14 +151,14 @@ public abstract class SwingWorker thread = t; } - synchronized Thread get() - { - return thread; - } - synchronized void clear() { thread = null; } + + synchronized Thread get() + { + return thread; + } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/TellMessage.java b/src/main/java/net/thauvin/erik/mobibot/TellMessage.java index 77ebdf9..48b3cbd 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TellMessage.java +++ b/src/main/java/net/thauvin/erik/mobibot/TellMessage.java @@ -1,7 +1,7 @@ /* - * @(#)TellMessage.java + * TellMessage.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import java.io.Serializable; @@ -47,23 +46,24 @@ import java.util.Date; */ public class TellMessage implements Serializable { + @SuppressWarnings({"UnusedDeclaration"}) private static final long serialVersionUID = 1L; - private final String sender; - - private final String recipient; - - private final String message; - private final String id; + private final String message; + final private Date queued; - private Date received; + private final String recipient; + + private final String sender; + + private boolean isNotified; private boolean isReceived; - private boolean isNotified; + private Date received; /** * Create a new message. diff --git a/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java b/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java index 9e9b4aa..d6b9b2b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java +++ b/src/main/java/net/thauvin/erik/mobibot/TellMessagesMgr.java @@ -1,7 +1,7 @@ /* - * @(#)TellMessagesMgr.java + * TellMessagesMgr.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.apache.commons.logging.impl.Log4JLogger; @@ -54,7 +53,7 @@ public class TellMessagesMgr /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private TellMessagesMgr() throws UnsupportedOperationException @@ -62,6 +61,35 @@ public class TellMessagesMgr throw new UnsupportedOperationException("Illegal constructor call."); } + /** + * Cleans the messages queue + * + * @param tellMessages The messages list. + * @param tellMaxDays The maximum number of days to keep messages for. + * + * @return True if the queue was cleaned. + */ + public static boolean cleanTellMessages(List tellMessages, int tellMaxDays) + { + final Calendar maxDate = Calendar.getInstance(); + final Date today = new Date(); + boolean cleaned = false; + + for (final TellMessage message : tellMessages) + { + maxDate.setTime(message.getQueued()); + maxDate.add(Calendar.DATE, tellMaxDays); + + if (maxDate.getTime().before(today)) + { + tellMessages.remove(message); + cleaned = true; + } + } + + return cleaned; + } + /** * Loads the messages. * @@ -79,7 +107,6 @@ public class TellMessagesMgr try { - if (logger.isDebugEnabled()) { logger.debug("Loading the messages."); @@ -140,27 +167,4 @@ public class TellMessagesMgr logger.error("Unable to save messages queue.", e); } } - - /** - * 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) - { - final Calendar maxDate = Calendar.getInstance(); - final Date today = new Date(); - - for (final TellMessage message : tellMessages) - { - maxDate.setTime(message.getQueued()); - maxDate.add(Calendar.DATE, tellMaxDays); - - if (maxDate.getTime().before(today)) - { - tellMessages.remove(message); - } - } - } } \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/mobibot/Twitter.java b/src/main/java/net/thauvin/erik/mobibot/Twitter.java index 049a15f..63aa811 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Twitter.java +++ b/src/main/java/net/thauvin/erik/mobibot/Twitter.java @@ -1,7 +1,7 @@ /* - * @(#)Twitter.java + * Twitter.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import twitter4j.Status; @@ -47,26 +46,6 @@ import twitter4j.conf.ConfigurationBuilder; */ public class Twitter implements Runnable { - /** - * The bot. - */ - private final Mobibot bot; - - /** - * The Twitter consumer secret. - */ - private final String consumerSecret; - - /** - * The Twitter consumer key. - */ - private final String consumerKey; - - /** - * The Twitter message. - */ - private final String message; - /** * The Twitter access token. */ @@ -77,6 +56,26 @@ public class Twitter implements Runnable */ private final String accessTokenSecret; + /** + * The bot. + */ + private final Mobibot bot; + + /** + * The Twitter consumer key. + */ + private final String consumerKey; + + /** + * The Twitter consumer secret. + */ + private final String consumerSecret; + + /** + * The Twitter message. + */ + private final String message; + /** * The nick of the person who sent the message. */ @@ -122,8 +121,7 @@ public class Twitter implements Runnable bot.send(sender, "You message was posted to http://twitter.com/" + twitter.getScreenName() + "/statuses/" + status - .getId() - ); + .getId()); } catch (Exception e) { diff --git a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java index 3fa40a7..04fcf26 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java +++ b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java @@ -9,15 +9,9 @@ import java.io.BufferedReader; 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 <consumerKey> <consumerSecret> - *

- * and follow the prompts/instructions. + * 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 + * <consumerKey> <consumerSecret>

and follow the prompts/instructions. * * @author Erik C. Thauvin * @author http://twitter4j.org/en/code-examples.html#oauth diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index 8e65826..8eb4862 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -1,7 +1,7 @@ /* - * @(#)Utils.java + * Utils.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import org.jibble.pircbot.Colors; @@ -58,20 +57,20 @@ public class Utils */ public static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMddHHmmss"); - /** - * The UTC (yyyy-MM-dd HH:mm) simple date format. - */ - static final SimpleDateFormat UTC_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - /** * The ISO (YYYY-MM-DD) simple date format. */ static final SimpleDateFormat ISO_SDF = new SimpleDateFormat("yyyy-MM-dd"); + /** + * The UTC (yyyy-MM-dd HH:mm) simple date format. + */ + static final SimpleDateFormat UTC_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private Utils() throws UnsupportedOperationException @@ -79,200 +78,6 @@ public class Utils throw new UnsupportedOperationException("Illegal constructor call."); } - /** - * Converts XML/XHTML entities to plain text. - * - * @param str The string to unescape. - * - * @return The unescaped string. - */ - public static String unescapeXml(String str) - { - String s = str.replaceAll("&", "&"); - s = s.replaceAll("<", "<"); - s = s.replaceAll(">", ">"); - s = s.replaceAll(""", "\""); - s = s.replaceAll("'", "'"); - s = s.replaceAll("'", "'"); - - return s; - } - - /** - * Copies a file. - * - * @param in The source file. - * @param out The destination file. - * - * @throws java.io.IOException If the file could not be copied. - */ - @SuppressWarnings("UnusedDeclaration") - public static void copyFile(File in, File out) - throws IOException - { - FileChannel inChannel = null; - FileChannel outChannel = null; - FileInputStream input = null; - FileOutputStream output = null; - - try - { - input = new FileInputStream(in); - output = new FileOutputStream(out); - - inChannel = input.getChannel(); - outChannel = output.getChannel(); - - inChannel.transferTo(0L, inChannel.size(), outChannel); - } - finally - { - try - { - if (inChannel != null) - { - inChannel.close(); - } - - if (input != null) - { - input.close(); - } - } - catch (Exception ignore) - { - ; // Do nothing - } - - try - { - if (outChannel != null) - { - outChannel.close(); - } - - if (output != null) - { - output.close(); - } - } - catch (Exception ignore) - { - ; // Do nothing - } - } - } - - /** - * Returns the current Internet (beat) Time. - * - * @return The Internet Time string. - */ - public static String internetTime() - { - final Calendar gc = Calendar.getInstance(); - - final int offset = (gc.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); - int hh = gc.get(Calendar.HOUR_OF_DAY); - final int mm = gc.get(Calendar.MINUTE); - final int ss = gc.get(Calendar.SECOND); - - hh -= offset; // GMT - hh += 1; // BMT - - long beats = Math.round(Math.floor((double) ((((hh * 3600) + (mm * 60) + ss) * 1000) / 86400))); - - if (beats >= 1000) - { - beats -= (long) 1000; - } - else if (beats < 0) - { - beats += (long) 1000; - } - - if (beats < 10) - { - return ("@00" + String.valueOf(beats)); - } - else if (beats < 100) - { - return ("@0" + String.valueOf(beats)); - } - - return ('@' + String.valueOf(beats)); - } - - /** - * Returns a property as an int. - * - * @param property The port property value. - * @param def The default property value. - * - * @return The port or default value if invalid. - */ - public static int getIntProperty(String property, int def) - { - int prop; - - try - { - prop = Integer.parseInt(property); - } - catch (NumberFormatException ignore) - { - prop = def; - } - - return prop; - } - - /** - * Ensures that the given location (File/URL) has a trailing slash (/) to indicate a directory. - * - * @param location The File or URL location. - * @param isUrl Set to true if the location is a URL - * - * @return The location ending with a slash. - */ - public static String ensureDir(String location, boolean isUrl) - { - if (isUrl) - { - if (location.charAt(location.length() - 1) == '/') - { - return location; - } - else - { - return location + '/'; - } - } - else - { - if (location.charAt(location.length() - 1) == File.separatorChar) - { - return location; - } - else - { - return location + File.separatorChar; - } - } - } - - /** - * Returns true if the given string is valid. - * - * @param s The string to validate. - * - * @return true if the string is non-empty and not null, false otherwise. - */ - public static boolean isValidString(String s) - { - return (s != null) && (s.trim().length() > 0); - } - /** * Makes the given int bold. * @@ -285,16 +90,6 @@ public class Utils return Colors.BOLD + i + Colors.BOLD; } - /** - * Returns today's date. - * - * @return Today's date in {@link #ISO_SDF ISO} format. - */ - public static String today() - { - return ISO_SDF.format(Calendar.getInstance().getTime()); - } - /** * Builds an entry's comment for display on the channel. * @@ -385,4 +180,208 @@ public class Utils { return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getDeliciousTags().replaceAll(",", ", ")); } + + /** + * Copies a file. + * + * @param in The source file. + * @param out The destination file. + * + * @throws java.io.IOException If the file could not be copied. + */ + @SuppressWarnings("UnusedDeclaration") + public static void copyFile(File in, File out) + throws IOException + { + FileChannel inChannel = null; + FileChannel outChannel = null; + FileInputStream input = null; + FileOutputStream output = null; + + try + { + input = new FileInputStream(in); + output = new FileOutputStream(out); + + inChannel = input.getChannel(); + outChannel = output.getChannel(); + + inChannel.transferTo(0L, inChannel.size(), outChannel); + } + finally + { + try + { + if (inChannel != null) + { + inChannel.close(); + } + + if (input != null) + { + input.close(); + } + } + catch (Exception ignore) + { + ; // Do nothing + } + + try + { + if (outChannel != null) + { + outChannel.close(); + } + + if (output != null) + { + output.close(); + } + } + catch (Exception ignore) + { + ; // Do nothing + } + } + } + + /** + * Ensures that the given location (File/URL) has a trailing slash (/) to indicate a directory. + * + * @param location The File or URL location. + * @param isUrl Set to true if the location is a URL + * + * @return The location ending with a slash. + */ + public static String ensureDir(String location, boolean isUrl) + { + if (isUrl) + { + if (location.charAt(location.length() - 1) == '/') + { + return location; + } + else + { + return location + '/'; + } + } + else + { + if (location.charAt(location.length() - 1) == File.separatorChar) + { + return location; + } + else + { + return location + File.separatorChar; + } + } + } + + /** + * Returns a property as an int. + * + * @param property The port property value. + * @param def The default property value. + * + * @return The port or default value if invalid. + */ + public static int getIntProperty(String property, int def) + { + int prop; + + try + { + prop = Integer.parseInt(property); + } + catch (NumberFormatException ignore) + { + prop = def; + } + + return prop; + } + + /** + * Returns the current Internet (beat) Time. + * + * @return The Internet Time string. + */ + public static String internetTime() + { + final Calendar gc = Calendar.getInstance(); + + final int offset = (gc.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); + int hh = gc.get(Calendar.HOUR_OF_DAY); + final int mm = gc.get(Calendar.MINUTE); + final int ss = gc.get(Calendar.SECOND); + + hh -= offset; // GMT + hh += 1; // BMT + + long beats = Math.round(Math.floor((double) ((((hh * 3600) + (mm * 60) + ss) * 1000) / 86400))); + + if (beats >= 1000) + { + beats -= (long) 1000; + } + else if (beats < 0) + { + beats += (long) 1000; + } + + if (beats < 10) + { + return ("@00" + String.valueOf(beats)); + } + else if (beats < 100) + { + return ("@0" + String.valueOf(beats)); + } + + return ('@' + String.valueOf(beats)); + } + + /** + * Returns true if the given string is valid. + * + * @param s The string to validate. + * + * @return true if the string is non-empty and not null, false otherwise. + */ + public static boolean isValidString(String s) + { + return (s != null) && (s.trim().length() > 0); + } + + /** + * Returns today's date. + * + * @return Today's date in {@link #ISO_SDF ISO} format. + */ + public static String today() + { + return ISO_SDF.format(Calendar.getInstance().getTime()); + } + + /** + * Converts XML/XHTML entities to plain text. + * + * @param str The string to unescape. + * + * @return The unescaped string. + */ + public static String unescapeXml(String str) + { + String s = str.replaceAll("&", "&"); + s = s.replaceAll("<", "<"); + s = s.replaceAll(">", ">"); + s = s.replaceAll(""", "\""); + s = s.replaceAll("'", "'"); + s = s.replaceAll("'", "'"); + + return s; + } } \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/mobibot/War.java b/src/main/java/net/thauvin/erik/mobibot/War.java index ec2ba9f..7a2d6c4 100644 --- a/src/main/java/net/thauvin/erik/mobibot/War.java +++ b/src/main/java/net/thauvin/erik/mobibot/War.java @@ -1,7 +1,7 @@ /* - * @(#)War.java + * War.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -58,7 +58,7 @@ public class War /** * Disables the default constructor. * - * @throws UnsupportedOperationException if an error occurred. if the constructor is called. + * @throws UnsupportedOperationException If the constructor is called. */ private War() throws UnsupportedOperationException diff --git a/src/main/java/net/thauvin/erik/mobibot/Weather.java b/src/main/java/net/thauvin/erik/mobibot/Weather.java index 105e770..a232cee 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Weather.java +++ b/src/main/java/net/thauvin/erik/mobibot/Weather.java @@ -1,7 +1,7 @@ /* - * @(#)Weather.java + * Weather.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package net.thauvin.erik.mobibot; import net.sf.jweather.metar.Metar; @@ -65,6 +64,11 @@ public class Weather implements Runnable */ private final Mobibot bot; + /** + * The private message flag. + */ + private final boolean isPrivate; + /** * The nick of the person who sent the message. */ @@ -75,11 +79,6 @@ public class Weather implements Runnable */ private final String station; - /** - * The private message flag. - */ - private final boolean isPrivate; - /** * Creates a new {@link Weather} instance. * @@ -114,8 +113,7 @@ public class Weather implements Runnable bot.send(sender, "At: " + Utils.UTC_SDF.format(metar.getDate()) + " UTC (" + ( ((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L) + " minutes ago)", - isPrivate - ); + isPrivate); result = metar.getWindSpeedInMPH(); @@ -124,8 +122,7 @@ public class Weather implements Runnable bot.send(sender, "Wind Speed: " + result + " mph, " + metar.getWindSpeedInKnots() + " knots, " + metar .getWindSpeedInMPS() + " m/s", - isPrivate - ); + isPrivate); } result = metar.getVisibility(); @@ -135,8 +132,7 @@ public class Weather implements Runnable bot.send(sender, "Visibility: " + (metar.getVisibilityLessThan() ? "< " : "") + NUMBER_FORMAT.format(result) + " mi, " + metar.getVisibilityInKilometers() + " km", - isPrivate - ); + isPrivate); } result = metar.getPressure(); diff --git a/src/main/java/net/thauvin/erik/mobibot/WorldTime.java b/src/main/java/net/thauvin/erik/mobibot/WorldTime.java index 26eccfe..228987c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/WorldTime.java +++ b/src/main/java/net/thauvin/erik/mobibot/WorldTime.java @@ -1,7 +1,7 @@ /* - * @(#)Time.java + * WorldTime.java * - * Copyright (c) 2004-2014, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2004-2015, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,16 +48,16 @@ import java.util.TreeMap; */ public class WorldTime { - /** - * The countries supported by the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command. - */ - private static final Map COUNTRIES_MAP = new TreeMap(); - /** * The beats (Internet Time) keyword. */ private static final String BEATS_KEYWORD = ".beats"; + /** + * The countries supported by the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command. + */ + private static final Map COUNTRIES_MAP = new TreeMap(); + /** * The date/time format for the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command. */