Code clean/reformat.

Updated copyright.
This commit is contained in:
Erik C. Thauvin 2015-01-30 01:28:26 -08:00
parent d02377a491
commit 0255fa537f
26 changed files with 1298 additions and 1443 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="K:\java\mobibot" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.6" relativePaths="false" type="JAVA_MODULE" version="4"> <module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.6" relativePaths="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
@ -31,5 +31,4 @@
<orderEntry type="library" exported="" name="Gradle: exp4j-0.3.11" level="project" /> <orderEntry type="library" exported="" name="Gradle: exp4j-0.3.11" level="project" />
<orderEntry type="library" exported="" name="Gradle: utils-1.07.00" level="project" /> <orderEntry type="library" exported="" name="Gradle: utils-1.07.00" level="project" />
</component> </component>
</module> </module>

View file

@ -72,20 +72,24 @@
</component> </component>
<component name="CopyrightManager" default="Mobibot"> <component name="CopyrightManager" default="Mobibot">
<copyright> <copyright>
<option name="notice" value="@(#)&amp;#36;file.fileName&#10;&#10;Copyright (c) 2004-&amp;#36;today.year, Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are&#10;met:&#10;&#10;Redistributions of source code must retain the above copyright notice,&#10;this list of conditions and the following disclaimer.&#10;&#10;Redistributions in binary form must reproduce the above copyright notice,&#10;this list of conditions and the following disclaimer in the documentation&#10;and/or other materials provided with the distribution.&#10;&#10;Neither the name of the author nor the names of its contributors may be&#10;used to endorse or promote products derived from this software without&#10;specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS&#10;IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&#10;THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&#10;PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&#10;CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&#10;EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&#10;PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&#10;PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&#10;LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&#10;NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&#10;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." /> <option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright (c) 2004-&amp;#36;today.year, Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are&#10;met:&#10;&#10;Redistributions of source code must retain the above copyright notice,&#10;this list of conditions and the following disclaimer.&#10;&#10;Redistributions in binary form must reproduce the above copyright notice,&#10;this list of conditions and the following disclaimer in the documentation&#10;and/or other materials provided with the distribution.&#10;&#10;Neither the name of the author nor the names of its contributors may be&#10;used to endorse or promote products derived from this software without&#10;specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS&#10;IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&#10;THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&#10;PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&#10;CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&#10;EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&#10;PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&#10;PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&#10;LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&#10;NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&#10;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." />
<option name="keyword" value="Copyright" /> <option name="keyword" value="Copyright" />
<option name="allowReplaceKeyword" value="Erik C. Thauvin" /> <option name="allowReplaceKeyword" value="Erik C. Thauvin" />
<option name="myName" value="Mobibot" /> <option name="myName" value="Mobibot" />
<option name="myLocal" value="true" /> <option name="myLocal" value="true" />
</copyright> </copyright>
<module2copyright> <module2copyright>
<element module="All" copyright="Mobibot" /> <element module="Source" copyright="Mobibot" />
</module2copyright> </module2copyright>
<LanguageOptions name="__TEMPLATE__">
<option name="addBlankAfter" value="false" />
</LanguageOptions>
</component> </component>
<component name="DependenciesAnalyzeManager"> <component name="DependenciesAnalyzeManager">
<option name="myForwardDirection" value="false" /> <option name="myForwardDirection" value="false" />
</component> </component>
<component name="DependencyValidationManager"> <component name="DependencyValidationManager">
<scope name="Source" pattern="file:src/main/java/net/thauvin/erik/mobibot/*&amp;&amp;!file:src/main/java/net/thauvin/erik/mobibot/SwingWorker.java&amp;&amp;!file:src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java" />
<option name="SKIP_IMPORT_STATEMENTS" value="false" /> <option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component> </component>
<component name="EclipseCompilerSettings"> <component name="EclipseCompilerSettings">
@ -120,7 +124,7 @@
<option name="gradleHome" value="C:/gradle" /> <option name="gradleHome" value="C:/gradle" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="K:\java\mobibot" /> <option value="$PROJECT_DIR$" />
</set> </set>
</option> </option>
</GradleProjectSettings> </GradleProjectSettings>
@ -651,7 +655,7 @@
<module fileurl="file://$PROJECT_DIR$/mobibot.iml" filepath="$PROJECT_DIR$/mobibot.iml" /> <module fileurl="file://$PROJECT_DIR$/mobibot.iml" filepath="$PROJECT_DIR$/mobibot.iml" />
</modules> </modules>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.7.x" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.8.x" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="ResourceManagerContainer"> <component name="ResourceManagerContainer">
@ -840,5 +844,4 @@
</SOURCES> </SOURCES>
</library> </library>
</component> </component>
</project> </project>

File diff suppressed because it is too large Load diff

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
/** /**
@ -43,6 +42,16 @@ package net.thauvin.erik.mobibot;
*/ */
public class Commands 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. * The currency command.
*/ */
@ -54,35 +63,15 @@ public class Commands
public static final String CURRENCY_RATES_KEYWORD = "rates"; 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. * Debug command line argument.
*/ */
public static final String DEBUG_ARG = "debug"; 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. * The debug command.
*/ */
@ -93,35 +82,20 @@ public class Commands
*/ */
public static final String DICE_CMD = "dice"; public static final String DICE_CMD = "dice";
/**
* The say command.
*/
public static final String SAY_CMD = "say";
/** /**
* The die command. * The die command.
*/ */
public static final String DIE_CMD = "die"; 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"; public static final String HELP_ARG = "help";
/**
* The ignore command.
*/
public static final String IGNORE_CMD = "ignore";
/**
* The ignore <code>me</code> keyword.
*/
public static final String IGNORE_ME_KEYWORD = "me";
/** /**
* The help command. * The help command.
@ -139,29 +113,19 @@ public class Commands
public static final String HELP_TAGS_KEYWORD = "tags"; 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 <code>me</code> 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"; public static final String INFO_CMD = "info";
/**
* The me command.
*/
public static final String ME_CMD = "me";
/**
* The nick command.
*/
public static final String NICK_CMD = "nick";
/** /**
* The link command. * The link command.
@ -173,6 +137,21 @@ public class Commands
*/ */
public static final String LOOKUP_CMD = "lookup"; 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. * The ping command.
*/ */
@ -183,6 +162,11 @@ public class Commands
*/ */
public static final String PONG_CMD = "pong"; public static final String PONG_CMD = "pong";
/**
* Properties command line argument.
*/
public static final String PROPS_ARG = "properties";
/** /**
* The quote command. * The quote command.
*/ */
@ -193,15 +177,20 @@ public class Commands
*/ */
public static final String RECAP_CMD = "recap"; public static final String RECAP_CMD = "recap";
/**
* The say command.
*/
public static final String SAY_CMD = "say";
/** /**
* The stock command. * The stock command.
*/ */
public static final String STOCK_CMD = "stock"; 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. * The tell command.
@ -214,14 +203,14 @@ public class Commands
public static final String TELL_DEL_CMD = "del"; 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. * The users command.
@ -229,9 +218,9 @@ public class Commands
public static final String USERS_CMD = "users"; 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. * The version command.
@ -243,10 +232,20 @@ public class Commands
*/ */
public static final String VIEW_CMD = "view"; 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. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private Commands() private Commands()
throws UnsupportedOperationException throws UnsupportedOperationException

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.jdom.Document; import org.jdom.Document;
@ -54,21 +53,26 @@ import java.util.*;
*/ */
public class CurrencyConverter implements Runnable 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. * The exchange rates.
*/ */
private static final Map<String, String> EXCHANGE_RATES = new TreeMap<String, String>(); private static final Map<String, String> EXCHANGE_RATES = new TreeMap<String, String>();
/**
* The exchange rates table URL.
*/
private static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
/** /**
* The bot. * The bot.
*/ */
private final Mobibot bot; private final Mobibot bot;
/**
* The last exchange rates table publication date.
*/
private String pubDate = "";
/** /**
* The actual currency query. * The actual currency query.
*/ */
@ -79,11 +83,6 @@ public class CurrencyConverter implements Runnable
*/ */
private String sender; private String sender;
/**
* The last exchange rates table publication date.
*/
private String pubDate = "";
/** /**
* Creates a new {@link CurrencyConverter} instance. * Creates a new {@link CurrencyConverter} instance.
* *
@ -165,8 +164,7 @@ public class CurrencyConverter implements Runnable
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' + NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
cmds[1].toUpperCase() + " = " + cmds[1].toUpperCase() + " = " +
NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from) NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from)
.substring(1) + ' ' + cmds[3].toUpperCase() .substring(1) + ' ' + cmds[3].toUpperCase());
);
} }
catch (NullPointerException ignored) catch (NullPointerException ignored)
{ {

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import del.icio.us.Delicious; import del.icio.us.Delicious;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -47,7 +47,7 @@ public class Dice
/** /**
* Disables the default constructor. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private Dice() private Dice()
throws UnsupportedOperationException throws UnsupportedOperationException
@ -71,8 +71,7 @@ public class Dice
bot.send(bot.getChannel(), bot.send(bot.getChannel(),
sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils 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; i = r.nextInt(6) + 1;
y = r.nextInt(6) + 1; y = r.nextInt(6) + 1;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -75,7 +75,7 @@ public class EntriesMgr
/** /**
* Disables the default constructor. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private EntriesMgr() private EntriesMgr()
throws UnsupportedOperationException throws UnsupportedOperationException
@ -83,6 +83,55 @@ public class EntriesMgr
throw new UnsupportedOperationException("Illegal constructor call."); 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<String> 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. * Loads the current entries.
* *
@ -167,55 +216,6 @@ public class EntriesMgr
return today; 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<String> 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. * Saves the entries.
* *
@ -260,8 +260,7 @@ public class EntriesMgr
buff = new StringBuffer( buff = new StringBuffer(
"Posted by <b>" + entry.getNick() + "</b> on <a href=\"irc://" + bot.getIrcServer() + '/' "Posted by <b>" + entry.getNick() + "</b> on <a href=\"irc://" + bot.getIrcServer() + '/'
+ entry.getChannel() + "\"><b>" + entry.getChannel() + "</b></a>" + entry.getChannel() + "\"><b>" + entry.getChannel() + "</b></a>");
);
if (entry.getCommentsCount() > 0) if (entry.getCommentsCount() > 0)
{ {

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import java.io.Serializable; import java.io.Serializable;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import com.sun.syndication.feed.synd.SyndCategoryImpl; import com.sun.syndication.feed.synd.SyndCategoryImpl;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntry;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.json.JSONArray; import org.json.JSONArray;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.apache.commons.net.WhoisClient; import org.apache.commons.net.WhoisClient;
@ -59,7 +58,7 @@ public class Lookup
/** /**
* Disables the default constructor. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private Lookup() private Lookup()
throws UnsupportedOperationException throws UnsupportedOperationException

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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; 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. * The default {@link Commands#TELL_CMD) message max queue size.
*/ */
private static final int DEFAULT_TELL_MAX_SIZE = 50; 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). * The double tab indent (8 spaces).
*/ */
@ -280,6 +270,16 @@ public class Mobibot extends PircBot
*/ */
private String identNick = ""; 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. * Today's date.
*/ */
@ -1301,8 +1301,7 @@ public class Mobibot extends PircBot
send(sender, send(sender,
DOUBLE_INDENT + Utils DOUBLE_INDENT + Utils
.bold(Commands.CYCLE_CMD + " " + Commands.ME_CMD + " " + Commands.MSG_CMD + " " .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, send(sender,
"Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " + entries.size() "Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " + entries.size()
+ (isTellEnabled() && isOp(sender) ? ", Messages: " + tellMessages.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) private void recap(String sender, String message, boolean isAction)
{ {
recap.add(Utils.UTC_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ") recap.add(Utils.UTC_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ")
+ message + message);
);
if (recap.size() > MAX_RECAP) if (recap.size() > MAX_RECAP)
{ {
@ -2321,8 +2318,7 @@ public class Mobibot extends PircBot
{ {
send(nickname, send(nickname,
Utils.bold("You") + " wanted me to remind you: " + Colors.REVERSE + message Utils.bold("You") + " wanted me to remind you: " + Colors.REVERSE + message
.getMessage() + Colors.REVERSE, true .getMessage() + Colors.REVERSE, true);
);
message.setIsReceived(); message.setIsReceived();
message.setIsNotified(); message.setIsNotified();
@ -2335,8 +2331,7 @@ public class Mobibot extends PircBot
send(nickname, send(nickname,
message.getSender() + " wanted me to tell you: " + Colors.REVERSE + message message.getSender() + " wanted me to tell you: " + Colors.REVERSE + message
.getMessage() + Colors.REVERSE, .getMessage() + Colors.REVERSE,
true true);
);
message.setIsReceived(); message.setIsReceived();
@ -2350,8 +2345,7 @@ public class Mobibot extends PircBot
"Your message " + Colors.REVERSE + "[ID " + message.getId() + ']' + Colors.REVERSE "Your message " + Colors.REVERSE + "[ID " + message.getId() + ']' + Colors.REVERSE
+ " was sent to " + Utils.bold(message.getRecipient()) + " on " + Utils.UTC_SDF + " was sent to " + Utils.bold(message.getRecipient()) + " on " + Utils.UTC_SDF
.format(message.getReceived()), .format(message.getReceived()),
true true);
);
message.setIsNotified(); message.setIsNotified();
@ -2471,8 +2465,7 @@ public class Mobibot extends PircBot
send(sender, send(sender,
Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [ID: " Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [ID: "
+ message.getId() + ", " + (message.isReceived() ? "DELIVERED" : "QUEUED") + ']', + message.getId() + ", " + (message.isReceived() ? "DELIVERED" : "QUEUED") + ']',
true true);
);
} }
} }
else else
@ -2500,8 +2493,7 @@ public class Mobibot extends PircBot
Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [" Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " ["
+ Utils.UTC_SDF.format(message.getReceived()) + ", ID: " + message.getId() + Utils.UTC_SDF.format(message.getReceived()) + ", ID: " + message.getId()
+ ", DELIVERED]", + ", DELIVERED]",
true true);
);
} }
else else
@ -2509,8 +2501,7 @@ public class Mobibot extends PircBot
send(sender, send(sender,
Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " [" Utils.bold(message.getSender()) + " --> " + Utils.bold(message.getRecipient()) + " ["
+ Utils.UTC_SDF.format(message.getQueued()) + ", ID: " + message.getId() + ", QUEUED]", + Utils.UTC_SDF.format(message.getQueued()) + ", ID: " + message.getId() + ", QUEUED]",
true true);
);
} }
send(sender, DOUBLE_INDENT + message.getMessage(), true); send(sender, DOUBLE_INDENT + message.getMessage(), true);
@ -2527,8 +2518,7 @@ public class Mobibot extends PircBot
send(sender, send(sender,
DOUBLE_INDENT + Utils DOUBLE_INDENT + Utils
.bold(getNick() + ": " + Commands.TELL_CMD + ' ' + Commands.TELL_DEL_CMD + " <id|" .bold(getNick() + ": " + Commands.TELL_CMD + ' ' + Commands.TELL_DEL_CMD + " <id|"
+ Commands.TELL_ALL_CMD + '>') + Commands.TELL_ALL_CMD + '>'));
);
send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days."); send(sender, "Messages are kept for " + Utils.bold(tellMaxDays) + " days.");
} }
} }
@ -2789,8 +2779,7 @@ public class Mobibot extends PircBot
send(sender, send(sender,
"To view more, try: " + Utils "To view more, try: " + Utils
.bold(getNick() + ": " + Commands.VIEW_CMD + ' ' + (i + 1) + ' ' + lcArgs), .bold(getNick() + ": " + Commands.VIEW_CMD + ' ' + (i + 1) + ' ' + lcArgs),
isPrivate isPrivate);
);
break; break;
} }

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.jibble.pircbot.Colors; import org.jibble.pircbot.Colors;

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -82,6 +82,16 @@ public class ReleaseInfo
return buildDate; 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"). * Get project (set during build process to "mobibot").
* *
@ -102,14 +112,4 @@ public class ReleaseInfo
return version; return version;
} }
/**
* Get buildNumber (set during build process to 0).
*
* @return int buildNumber
*/
public static int getBuildNumber()
{
return 0;
}
} }

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import com.Ostermiller.util.CSVParser; import com.Ostermiller.util.CSVParser;

View file

@ -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 * 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:
* <p> * <p/>
* http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html * 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 * Note that the API changed slightly in the 3rd version:
* it. * You must now invoke start() on the SwingWorker after creating it.
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
public abstract class SwingWorker public abstract class SwingWorker
{ {
private Object value; // see getValue(), setValue()
private ThreadVar threadVar; private ThreadVar threadVar;
private Object value; // see getValue(), setValue()
/** /**
* Start a thread that will call the <code>construct</code> method and then exit. * Start a thread that will call the <code>construct</code> method and then exit.
*/ */
@ -67,19 +67,6 @@ public abstract class SwingWorker
*/ */
public abstract Object construct(); 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 <code>construct</code> method. Returns null if either the constructing thread or * Return the value created by the <code>construct</code> method. Returns null if either the constructing thread or
* the current thread was interrupted before a value was produced. * the current thread was interrupted before a value was produced.
@ -127,6 +114,19 @@ public abstract class SwingWorker
value = x; 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. * Start the worker thread.
*/ */
@ -151,14 +151,14 @@ public abstract class SwingWorker
thread = t; thread = t;
} }
synchronized Thread get()
{
return thread;
}
synchronized void clear() synchronized void clear()
{ {
thread = null; thread = null;
} }
synchronized Thread get()
{
return thread;
}
} }
} }

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import java.io.Serializable; import java.io.Serializable;
@ -47,23 +46,24 @@ import java.util.Date;
*/ */
public class TellMessage implements Serializable public class TellMessage implements Serializable
{ {
@SuppressWarnings({"UnusedDeclaration"})
private static final long serialVersionUID = 1L; 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 id;
private final String message;
final private Date queued; final private Date queued;
private Date received; private final String recipient;
private final String sender;
private boolean isNotified;
private boolean isReceived; private boolean isReceived;
private boolean isNotified; private Date received;
/** /**
* Create a new message. * Create a new message.

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
@ -54,7 +53,7 @@ public class TellMessagesMgr
/** /**
* Disables the default constructor. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private TellMessagesMgr() private TellMessagesMgr()
throws UnsupportedOperationException throws UnsupportedOperationException
@ -62,6 +61,35 @@ public class TellMessagesMgr
throw new UnsupportedOperationException("Illegal constructor call."); 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 <code>True</code> if the queue was cleaned.
*/
public static boolean cleanTellMessages(List<TellMessage> 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. * Loads the messages.
* *
@ -79,7 +107,6 @@ public class TellMessagesMgr
try try
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Loading the messages."); logger.debug("Loading the messages.");
@ -140,27 +167,4 @@ public class TellMessagesMgr
logger.error("Unable to save messages queue.", e); 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<TellMessage> 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);
}
}
}
} }

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import twitter4j.Status; import twitter4j.Status;
@ -47,26 +46,6 @@ import twitter4j.conf.ConfigurationBuilder;
*/ */
public class Twitter implements Runnable 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. * The Twitter access token.
*/ */
@ -77,6 +56,26 @@ public class Twitter implements Runnable
*/ */
private final String accessTokenSecret; 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. * The nick of the person who sent the message.
*/ */
@ -122,8 +121,7 @@ public class Twitter implements Runnable
bot.send(sender, bot.send(sender,
"You message was posted to http://twitter.com/" + twitter.getScreenName() + "/statuses/" + status "You message was posted to http://twitter.com/" + twitter.getScreenName() + "/statuses/" + status
.getId() .getId());
);
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -9,15 +9,9 @@ import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
* The <code>TwitterOAuth</code> class. * The <code>TwitterOAuth</code> class. <p> Go to <a href="http://twitter.com/oauth_clients/new">http://twitter.com/oauth_clients/new</a>
* <p> * to register your bot. </p> Then execute: <p> <code>java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth
* Go to <a href="http://twitter.com/oauth_clients/new">http://twitter.com/oauth_clients/new</a> to register your bot. * &lt;consumerKey&gt; &lt;consumerSecret&gt;</code> </p> and follow the prompts/instructions.
* </p>
* Then execute:
* <p>
* <code>java -cp "mobibot.jar:lib/*" net.thauvin.erik.mobibot.TwitterOAuth &lt;consumerKey&gt; &lt;consumerSecret&gt;</code>
* </p>
* and follow the prompts/instructions.
* *
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a> * @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @author <a href="http://twitter4j.org/en/code-examples.html#oauth">http://twitter4j.org/en/code-examples.html#oauth</a> * @author <a href="http://twitter4j.org/en/code-examples.html#oauth">http://twitter4j.org/en/code-examples.html#oauth</a>

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import org.jibble.pircbot.Colors; import org.jibble.pircbot.Colors;
@ -58,20 +57,20 @@ public class Utils
*/ */
public static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMddHHmmss"); 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. * The ISO (YYYY-MM-DD) simple date format.
*/ */
static final SimpleDateFormat ISO_SDF = new SimpleDateFormat("yyyy-MM-dd"); 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. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private Utils() private Utils()
throws UnsupportedOperationException throws UnsupportedOperationException
@ -79,200 +78,6 @@ public class Utils
throw new UnsupportedOperationException("Illegal constructor call."); 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("&amp;", "&");
s = s.replaceAll("&lt;", "<");
s = s.replaceAll("&gt;", ">");
s = s.replaceAll("&quot;", "\"");
s = s.replaceAll("&apos;", "'");
s = s.replaceAll("&#39;", "'");
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 (<code>/</code>) 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. * Makes the given int bold.
* *
@ -285,16 +90,6 @@ public class Utils
return Colors.BOLD + i + Colors.BOLD; 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. * 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(",", ", ")); 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 (<code>/</code>) 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("&amp;", "&");
s = s.replaceAll("&lt;", "<");
s = s.replaceAll("&gt;", ">");
s = s.replaceAll("&quot;", "\"");
s = s.replaceAll("&apos;", "'");
s = s.replaceAll("&#39;", "'");
return s;
}
} }

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -58,7 +58,7 @@ public class War
/** /**
* Disables the default constructor. * Disables the default constructor.
* *
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. * @throws UnsupportedOperationException If the constructor is called.
*/ */
private War() private War()
throws UnsupportedOperationException throws UnsupportedOperationException

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.thauvin.erik.mobibot; package net.thauvin.erik.mobibot;
import net.sf.jweather.metar.Metar; import net.sf.jweather.metar.Metar;
@ -65,6 +64,11 @@ public class Weather implements Runnable
*/ */
private final Mobibot bot; private final Mobibot bot;
/**
* The private message flag.
*/
private final boolean isPrivate;
/** /**
* The nick of the person who sent the message. * The nick of the person who sent the message.
*/ */
@ -75,11 +79,6 @@ public class Weather implements Runnable
*/ */
private final String station; private final String station;
/**
* The private message flag.
*/
private final boolean isPrivate;
/** /**
* Creates a new {@link Weather} instance. * Creates a new {@link Weather} instance.
* *
@ -114,8 +113,7 @@ public class Weather implements Runnable
bot.send(sender, bot.send(sender,
"At: " + Utils.UTC_SDF.format(metar.getDate()) + " UTC (" + ( "At: " + Utils.UTC_SDF.format(metar.getDate()) + " UTC (" + (
((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L) + " minutes ago)", ((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L) + " minutes ago)",
isPrivate isPrivate);
);
result = metar.getWindSpeedInMPH(); result = metar.getWindSpeedInMPH();
@ -124,8 +122,7 @@ public class Weather implements Runnable
bot.send(sender, bot.send(sender,
"Wind Speed: " + result + " mph, " + metar.getWindSpeedInKnots() + " knots, " + metar "Wind Speed: " + result + " mph, " + metar.getWindSpeedInKnots() + " knots, " + metar
.getWindSpeedInMPS() + " m/s", .getWindSpeedInMPS() + " m/s",
isPrivate isPrivate);
);
} }
result = metar.getVisibility(); result = metar.getVisibility();
@ -135,8 +132,7 @@ public class Weather implements Runnable
bot.send(sender, bot.send(sender,
"Visibility: " + (metar.getVisibilityLessThan() ? "< " : "") + NUMBER_FORMAT.format(result) "Visibility: " + (metar.getVisibilityLessThan() ? "< " : "") + NUMBER_FORMAT.format(result)
+ " mi, " + metar.getVisibilityInKilometers() + " km", + " mi, " + metar.getVisibilityInKilometers() + " km",
isPrivate isPrivate);
);
} }
result = metar.getPressure(); result = metar.getPressure();

View file

@ -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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -48,16 +48,16 @@ import java.util.TreeMap;
*/ */
public class WorldTime public class WorldTime
{ {
/**
* The countries supported by the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command.
*/
private static final Map<String, String> COUNTRIES_MAP = new TreeMap<String, String>();
/** /**
* The beats (Internet Time) keyword. * The beats (Internet Time) keyword.
*/ */
private static final String BEATS_KEYWORD = ".beats"; 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<String, String> COUNTRIES_MAP = new TreeMap<String, String>();
/** /**
* The date/time format for the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command. * The date/time format for the {@link net.thauvin.erik.mobibot.Commands#TIME_CMD time} command.
*/ */