Added a basic Jaiku posting implementation.

This commit is contained in:
Erik C. Thauvin 2007-10-11 23:50:32 +00:00
parent 7dbc83ef1c
commit 8f6aab302d
9 changed files with 459 additions and 226 deletions

View file

@ -1,3 +1,3 @@
#ANT Task: ch.oscg.jreleaseinfo.BuildNumberHandler
#Wed Jul 18 23:09:10 PDT 2007
build.num.last=70
#Thu Oct 11 16:35:17 PDT 2007
build.num.last=72

Binary file not shown.

BIN
lib/xmlrpc-client-3.1.jar Normal file

Binary file not shown.

BIN
lib/xmlrpc-common-3.1.jar Normal file

Binary file not shown.

View file

@ -162,6 +162,33 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/xmlrpc-client-3.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/ws-commons-util-1.0.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/xmlrpc-common-3.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties />
</component>
</module>

View file

@ -18,7 +18,11 @@
</component>
<component name="ChangeListManager">
<list default="true" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/mobibot.iml" afterPath="$PROJECT_DIR$/mobibot.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/buildnum.properties" afterPath="$PROJECT_DIR$/buildnum.properties" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Mobibot.java" afterPath="$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Mobibot.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/mobibot.iws" afterPath="$PROJECT_DIR$/mobibot.iws" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/net/thauvin/erik/mobibot/ReleaseInfo.java" afterPath="$PROJECT_DIR$/src/net/thauvin/erik/mobibot/ReleaseInfo.java" />
</list>
</component>
<component name="ChangeListSynchronizer" />
@ -132,7 +136,16 @@
<component name="FavoritesManager">
<favorites_list name="mobibot" />
</component>
<component name="FavoritesProjectViewPane" />
<component name="FavoritesProjectViewPane">
<subPane subId="mobibot">
<PATH>
<PATH_ELEMENT>
<option name="myItemId" />
<option name="myItemType" value="com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor" />
</PATH_ELEMENT>
</PATH>
</subPane>
</component>
<component name="FavoritesViewImpl">
<favorites_list name="mobibot">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
@ -148,10 +161,19 @@
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="Mobibot.java" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="Mobibot.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Mobibot.java">
<provider selected="true" editor-type-id="text-editor">
<state line="1972" column="24" selection-start="47849" selection-end="47849" vertical-scroll-proportion="0.33333334">
<state line="715" column="56" selection-start="17568" selection-end="17568" vertical-scroll-proportion="0.3677483">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Jaiku.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Jaiku.java">
<provider selected="true" editor-type-id="text-editor">
<state line="83" column="25" selection-start="1610" selection-end="1610" vertical-scroll-proportion="0.6647287">
<folding />
</state>
</provider>
@ -160,16 +182,7 @@
<file leaf-file-name="GoogleSearch.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/GoogleSearch.java">
<provider selected="true" editor-type-id="text-editor">
<state line="54" column="13" selection-start="2041" selection-end="2041" vertical-scroll-proportion="0.25073746">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="FeedReader.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/FeedReader.java">
<provider selected="true" editor-type-id="text-editor">
<state line="59" column="13" selection-start="2216" selection-end="2216" vertical-scroll-proportion="0.24709302">
<state line="54" column="49" selection-start="2053" selection-end="2073" vertical-scroll-proportion="0.01671583">
<folding />
</state>
</provider>
@ -178,7 +191,7 @@
<file leaf-file-name="DeliciousPoster.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/DeliciousPoster.java">
<provider selected="true" editor-type-id="text-editor">
<state line="50" column="13" selection-start="1995" selection-end="1995" vertical-scroll-proportion="0.24709302">
<state line="50" column="13" selection-start="1995" selection-end="1995" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -187,7 +200,7 @@
<file leaf-file-name="CurrencyConverter.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/CurrencyConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state line="63" column="13" selection-start="2150" selection-end="2150" vertical-scroll-proportion="0.24709302">
<state line="63" column="13" selection-start="2150" selection-end="2150" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -196,7 +209,7 @@
<file leaf-file-name="StockQuote.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/StockQuote.java">
<provider selected="true" editor-type-id="text-editor">
<state line="52" column="13" selection-start="2029" selection-end="2029" vertical-scroll-proportion="0.23062016">
<state line="52" column="13" selection-start="2029" selection-end="2029" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -205,7 +218,7 @@
<file leaf-file-name="SwingWorker.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/SwingWorker.java">
<provider selected="true" editor-type-id="text-editor">
<state line="16" column="22" selection-start="536" selection-end="536" vertical-scroll-proportion="0.2635659">
<state line="16" column="22" selection-start="536" selection-end="536" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -214,7 +227,7 @@
<file leaf-file-name="Weather.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Weather.java">
<provider selected="true" editor-type-id="text-editor">
<state line="54" column="13" selection-start="2110" selection-end="2110" vertical-scroll-proportion="0.21414728">
<state line="54" column="13" selection-start="2110" selection-end="2110" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -223,7 +236,7 @@
<file leaf-file-name="EntryLink.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryLink.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2001" selection-end="2001" vertical-scroll-proportion="0.23062016">
<state line="53" column="13" selection-start="2001" selection-end="2001" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -232,7 +245,7 @@
<file leaf-file-name="EntryComment.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryComment.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2016" selection-end="2016" vertical-scroll-proportion="0.24709302">
<state line="53" column="13" selection-start="2016" selection-end="2016" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
@ -292,10 +305,6 @@
<option name="myItemId" value="mobibot" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PackageViewModuleNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="Libraries" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PackageViewLibrariesNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
@ -378,7 +387,7 @@
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<showStructure PackagesPane="false" Scope="false" ProjectPane="false" />
<showStructure Favorites="false" PackagesPane="false" Scope="false" ProjectPane="false" />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
@ -461,7 +470,7 @@
<option name="showLabels" value="true" />
</component>
<component name="RestoreUpdateTree" />
<component name="RunManager" selected="Application.Mobibot">
<component name="RunManager" selected="Application.Jaiku">
<configuration default="true" type="Applet" factoryName="Applet">
<module name="" />
<option name="MAIN_CLASS_NAME" />
@ -481,25 +490,6 @@
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="TEST_OBJECT" />
<option name="VM_PARAMETERS" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ADDITIONAL_CLASS_PATH" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<method>
<option name="Make" value="true" />
</method>
</configuration>
<configuration default="true" type="WebLogic Instance" factoryName="Local">
<option name="WORKING_DIRECTORY" />
<option name="HOST" value="localhost" />
@ -529,6 +519,25 @@
<option name="Make" value="true" />
</method>
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="TEST_OBJECT" />
<option name="VM_PARAMETERS" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ADDITIONAL_CLASS_PATH" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<method>
<option name="Make" value="true" />
</method>
</configuration>
<configuration default="false" name="Mobibot" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" value="net.thauvin.erik.mobibot.Mobibot" />
<option name="VM_PARAMETERS" value="" />
@ -546,6 +555,24 @@
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method>
<option name="Make" value="true" />
</method>
</configuration>
<configuration default="false" name="Jaiku" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" value="net.thauvin.erik.mobibot.Jaiku" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<module name="mobibot" />
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Run" />
<method>
<option name="Make" value="true" />
</method>
</configuration>
</component>
<component name="ScopeViewComponent">
@ -647,7 +674,7 @@
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.099162914" order="1" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="true" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.39524516" order="2" x="22" y="277" width="980" height="213" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="true" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.39500463" order="2" x="22" y="277" width="980" height="213" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
<window_info id="File View" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3296845" order="5" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="0" />
@ -752,7 +779,7 @@
</component>
<component name="com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectRootMasterDetailsConfigurable" proportions="0.28625" version="1">
<option name="myPlainMode" value="false" />
<option name="myLastEditedConfigurable" value="Project 'mobibot'" />
<option name="myLastEditedConfigurable" value="mobibot" />
</component>
<component name="com.intellij.profile.ui.ErrorOptionsConfigurable" proportions="" version="1">
<option name="myLastEditedConfigurable" />
@ -772,72 +799,79 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/GoogleSearch.java">
<provider selected="true" editor-type-id="text-editor">
<state line="54" column="13" selection-start="2041" selection-end="2041" vertical-scroll-proportion="0.25073746">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/FeedReader.java">
<provider selected="true" editor-type-id="text-editor">
<state line="59" column="13" selection-start="2216" selection-end="2216" vertical-scroll-proportion="0.24709302">
<state line="59" column="13" selection-start="2216" selection-end="2216" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryLink.java">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/GoogleSearch.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2001" selection-end="2001" vertical-scroll-proportion="0.23062016">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryComment.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2016" selection-end="2016" vertical-scroll-proportion="0.24709302">
<state line="54" column="49" selection-start="2053" selection-end="2073" vertical-scroll-proportion="0.01671583">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/DeliciousPoster.java">
<provider selected="true" editor-type-id="text-editor">
<state line="50" column="13" selection-start="1995" selection-end="1995" vertical-scroll-proportion="0.24709302">
<state line="50" column="13" selection-start="1995" selection-end="1995" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/CurrencyConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state line="63" column="13" selection-start="2150" selection-end="2150" vertical-scroll-proportion="0.24709302">
<state line="63" column="13" selection-start="2150" selection-end="2150" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/StockQuote.java">
<provider selected="true" editor-type-id="text-editor">
<state line="52" column="13" selection-start="2029" selection-end="2029" vertical-scroll-proportion="0.23062016">
<state line="52" column="13" selection-start="2029" selection-end="2029" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/SwingWorker.java">
<provider selected="true" editor-type-id="text-editor">
<state line="16" column="22" selection-start="536" selection-end="536" vertical-scroll-proportion="0.2635659">
<state line="16" column="22" selection-start="536" selection-end="536" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Weather.java">
<provider selected="true" editor-type-id="text-editor">
<state line="54" column="13" selection-start="2110" selection-end="2110" vertical-scroll-proportion="0.21414728">
<state line="54" column="13" selection-start="2110" selection-end="2110" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryLink.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2001" selection-end="2001" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/EntryComment.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2016" selection-end="2016" vertical-scroll-proportion="0.016472869">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Mobibot.java">
<provider selected="true" editor-type-id="text-editor">
<state line="1972" column="24" selection-start="47849" selection-end="47849" vertical-scroll-proportion="0.33333334">
<state line="715" column="56" selection-start="17568" selection-end="17568" vertical-scroll-proportion="0.3677483">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/erik/mobibot/Jaiku.java">
<provider selected="true" editor-type-id="text-editor">
<state line="83" column="25" selection-start="1610" selection-end="1610" vertical-scroll-proportion="0.6647287">
<folding />
</state>
</provider>

View file

@ -0,0 +1,100 @@
/*
* @(#)Jaiku.java
*
* Copyright (C) 2007 Erik C. Thauvin
* All rights reserved.
*
* $Id$
*
*/
package net.thauvin.erik.mobibot;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Inserts presence information into Jaiku.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @version $Revision$, $Date$
* @created Oct 11, 2007
* @since 1.0
*/
public class Jaiku implements Runnable
{
/**
* The bot.
*/
private final Mobibot _bot;
/**
* The Jaiku API key.
*/
private final String _key;
/**
* The Jaiku user.
*/
private final String _user;
/**
* The Jaiku message.
*/
private final String _message;
/**
* The nick of the person who sent the message.
*/
private final String _sender;
/**
* Creates a new Jaiku object.
*
* @param bot The bot.
* @param sender The nick of the person who sent the message.
* @param user The Jaiku user.
* @param key The Jaiku API key.
* @param message The Jaiku message.
*/
public Jaiku(Mobibot bot, String sender, String user, String key, String message)
{
_bot = bot;
_user = user;
_key = key;
_message = message;
_sender = sender;
}
public final void run()
{
try
{
final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://api.jaiku.com/xmlrpc"));
final XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
final Map map = new HashMap(0);
map.put("user", _user);
map.put("personal_key", _key);
map.put("message", _bot.getChannel() + ' ' + _message + " (" + _sender + ')');
final List params = new ArrayList(0);
params.add(map);
client.execute("presence.send", params);
}
catch (Exception e)
{
_bot.getLogger().warn("Unable to post to Jaiku: " + _message, e);
_bot.send(_sender, "An error has occurred: " + e.getMessage());
}
}
}

View file

@ -37,36 +37,27 @@
package net.thauvin.erik.mobibot;
import com.primalworld.math.MathEvaluator;
import com.sun.syndication.feed.synd.*;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.SyndFeedOutput;
import org.apache.commons.cli.*;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.net.WhoisClient;
import org.apache.log4j.Level;
import org.jibble.pircbot.Colors;
import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Implements the #mobitopia bot.
*
@ -85,11 +76,10 @@ public class Mobibot extends PircBot
/**
* The info strings.
*/
private static final String[] INFO_STRS =
{
"Mobibot v" + ReleaseInfo.getVersion() + '.' + ReleaseInfo.getBuildNumber() +
" by Erik C. Thauvin (erik@thauvin.net)", "http://www.mobitopia.org/mobibot/"
};
private static final String[] INFO_STRS = {"Mobibot v" + ReleaseInfo.getVersion() + '.'
+ ReleaseInfo.getBuildNumber()
+ " by Erik C. Thauvin (erik@thauvin.net)",
"http://www.mobitopia.org/mobibot/"};
/**
* Debug command line argument.
@ -196,6 +186,10 @@ public class Mobibot extends PircBot
*/
private static final String GOOGLE_CMD = "google";
/**
* The Jaiku command.
*/
private static final String JAIKU_CMD = "jaiku";
/**
* The math command.
*/
@ -443,6 +437,16 @@ public class Mobibot extends PircBot
private String _googleKey = "";
/**
* The Jaiku API key.
*/
private String _jaikuKey = "";
/**
* The Jaiku user.
*/
private String _jaikuUser = "";
/**
* The history/backlogs array.
*/
@ -453,7 +457,6 @@ public class Mobibot extends PircBot
*/
private String _identMsg = "";
/**
* The ident nick.
*/
@ -504,7 +507,6 @@ public class Mobibot extends PircBot
*/
private String _weblogURL = "";
/**
* Creates a new Mobibot object.
*
@ -586,7 +588,9 @@ public class Mobibot extends PircBot
// Setup the command line options
final Options options = new Options();
options.addOption(HELP_ARG.substring(0, 1), HELP_ARG, false, "print this help message");
options.addOption(DEBUG_ARG.substring(0, 1), DEBUG_ARG, false,
options.addOption(DEBUG_ARG.substring(0, 1),
DEBUG_ARG,
false,
"print debug & logging data directly to the console");
options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("use alternate properties file")
.withLongOpt(PROPS_ARG).create(PROPS_ARG.substring(0, 1)));
@ -664,9 +668,8 @@ public class Mobibot extends PircBot
try
{
stdout =
new PrintStream(new FileOutputStream(logsDir + channel.substring(1) + '.' + today() + ".log",
true));
stdout = new PrintStream(new FileOutputStream(
logsDir + channel.substring(1) + '.' + today() + ".log", true));
}
catch (IOException e)
{
@ -692,7 +695,6 @@ public class Mobibot extends PircBot
System.setErr(stderr);
}
// Get the bot's properties
final String login = p.getProperty("login", nickname);
final String weblogURL = p.getProperty("weblog", "");
@ -709,6 +711,10 @@ public class Mobibot extends PircBot
final String dname = p.getProperty("delicious-user");
final String dpwd = p.getProperty("delicious-pwd");
// Get the Jaiku properties
final String jname = p.getProperty("jaiku-user");
final String jkey = p.getProperty("jaiku-key");
// Create the bot
final Mobibot bot = new Mobibot(server, port, channel, logsDir);
@ -735,13 +741,18 @@ public class Mobibot extends PircBot
// Set the Google key
bot.setGoogleKey(googleKey);
if (isValidString(dname) && isValidString(dpwd))
{
// Set the del.icio.us authentication
bot.setDeliciousAuth(dname, dpwd);
}
if (isValidString(jname) && isValidString(jkey))
{
// Set the Jaiku authentication
bot.setJaikuAuth(jname, jkey);
}
// Set the tags
bot.setTags(tags);
@ -772,8 +783,8 @@ public class Mobibot extends PircBot
{
if (retries == MAX_RECONNECT)
{
System.err.println("Unable to connect to " + server + " after " + MAX_RECONNECT +
" retries.");
System.err.println(
"Unable to connect to " + server + " after " + MAX_RECONNECT + " retries.");
e.printStackTrace(System.err);
System.exit(1);
}
@ -799,7 +810,6 @@ public class Mobibot extends PircBot
}
}
/**
* Converts XML/XHTML entities to plain text.
*
@ -919,6 +929,11 @@ public class Mobibot extends PircBot
send(sender, "To search Google:");
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + GOOGLE_CMD + " <query>"));
}
else if (lcTopic.endsWith(JAIKU_CMD))
{
send(sender, "To post to Jaiku:");
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + JAIKU_CMD + " <message>"));
}
else if (lcTopic.endsWith(RECAP_CMD))
{
send(sender, "To list the last 10 public channel messages:");
@ -1030,15 +1045,16 @@ public class Mobibot extends PircBot
send(sender, "For more information on specific command, type:");
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + HELP_CMD + " <command>"));
send(sender, "The commands are:");
send(sender, DOUBLE_INDENT +
bold(CALC_CMD + ' ' + CURRENCY_CMD + ' ' + DICE_CMD + ' ' + GOOGLE_CMD + ' ' + IGNORE_CMD));
send(sender, DOUBLE_INDENT +
bold(INFO_CMD + ' ' + getChannel().substring(1) + ' ' + LOOKUP_CMD + ' ' + HELP_POSTING_KEYWORD + ' ' +
RECAP_CMD));
send(sender, DOUBLE_INDENT +
bold(SPELL_CMD + ' ' + STOCK_CMD + ' ' + HELP_TAGS_KEYWORD + ' ' + TIME_CMD + ' ' + USERS_CMD + ' ' +
VIEW_CMD));
send(sender, DOUBLE_INDENT + bold(WEATHER_CMD));
send(sender,
DOUBLE_INDENT + bold(
CALC_CMD + ' ' + CURRENCY_CMD + ' ' + DICE_CMD + ' ' + GOOGLE_CMD + ' ' + IGNORE_CMD));
send(sender,
DOUBLE_INDENT + bold(INFO_CMD + ' ' + getChannel().substring(1) + ' ' + LOOKUP_CMD + ' '
+ HELP_POSTING_KEYWORD + ' ' + RECAP_CMD));
send(sender,
DOUBLE_INDENT + bold(SPELL_CMD + ' ' + STOCK_CMD + ' ' + HELP_TAGS_KEYWORD + ' ' + TIME_CMD + ' '
+ USERS_CMD + ' ' + VIEW_CMD));
send(sender, DOUBLE_INDENT + bold(JAIKU_CMD + ' ' + WEATHER_CMD));
if (isOp(sender))
{
@ -1145,8 +1161,9 @@ public class Mobibot extends PircBot
{
if (_logger.isDebugEnabled())
{
_logger.debug("Unable to reconnect to " + _ircServer + " after " + MAX_RECONNECT +
" retries.", ex);
_logger.debug(
"Unable to reconnect to " + _ircServer + " after " + MAX_RECONNECT + " retries.",
ex);
}
e.printStackTrace(System.err);
@ -1222,9 +1239,13 @@ public class Mobibot extends PircBot
if (tagSep != -1)
{
_entries.add(new EntryLink(cmd, title.substring(0, tagSep), sender, login, channel,
(_defaultTags + ' ' +
title.substring(tagSep + TAGS_MARKER.length()))));
_entries.add(new EntryLink(cmd,
title.substring(0, tagSep),
sender,
login,
channel,
(_defaultTags + ' ' + title
.substring(tagSep + TAGS_MARKER.length()))));
}
else
{
@ -1287,14 +1308,18 @@ public class Mobibot extends PircBot
}
else if (cmd.equals(PING_CMD))
{
final String[] pings =
{
"is barely alive.", "is trying to stay awake.", "has gone fishing.",
"is somewhere over the rainbow.", "has fallen and can't get up.",
"is running. You better go chase it.", "has just spontantiously combusted.",
"is talking to itself... don't interrupt. That's rude.", "is bartending at an AA meeting.",
"is hibernating.", "is saving energy: apathetic mode activated.", "is busy. Go away!"
};
final String[] pings = {"is barely alive.",
"is trying to stay awake.",
"has gone fishing.",
"is somewhere over the rainbow.",
"has fallen and can't get up.",
"is running. You better go chase it.",
"has just spontantiously combusted.",
"is talking to itself... don't interrupt. That's rude.",
"is bartending at an AA meeting.",
"is hibernating.",
"is saving energy: apathetic mode activated.",
"is busy. Go away!"};
final Random r = new Random();
@ -1362,6 +1387,10 @@ public class Mobibot extends PircBot
{
googleResponse(sender, args);
}
else if (cmd.startsWith(JAIKU_CMD))
{
jaikuResponse(sender, args);
}
else if (cmd.startsWith(SPELL_CMD))
{
spellResponse(sender, args);
@ -1894,8 +1923,8 @@ public class Mobibot extends PircBot
*/
private static String buildComment(int entryIndex, int commentIndex, EntryComment comment)
{
return (LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] " +
comment.getComment());
return (LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] " + comment
.getComment());
}
/**
@ -1906,7 +1935,7 @@ public class Mobibot extends PircBot
*
* @return The entry's link.
*
* @see #buildLink(int, EntryLink, boolean)
* @see #buildLink(int,EntryLink,boolean)
*/
private static String buildLink(int index, EntryLink entry)
{
@ -2131,7 +2160,7 @@ public class Mobibot extends PircBot
*
* @return The lookup query result string.
*
* @exception UnknownHostException If the host is unknown.
* @throws UnknownHostException If the host is unknown.
*/
private static String lookup(String query)
throws UnknownHostException
@ -2168,7 +2197,6 @@ public class Mobibot extends PircBot
return buffer.toString();
}
/**
* Stores the last 10 public messages and actions.
*
@ -2178,8 +2206,8 @@ public class Mobibot extends PircBot
*/
private static void recap(String sender, String message, boolean isAction)
{
RECAP_ARRAY.add(HHMM_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ") +
message);
RECAP_ARRAY.add(HHMM_SDF.format(Calendar.getInstance().getTime()) + " -> " + sender + (isAction ? " " : ": ")
+ message);
if (RECAP_ARRAY.size() > MAX_RECAP)
{
@ -2304,7 +2332,8 @@ public class Mobibot extends PircBot
if (Character.isLetter(c))
{
buff.append('[').append(String.valueOf(c).toLowerCase()).append(String.valueOf(c).toUpperCase()).append(']');
buff.append('[').append(String.valueOf(c).toLowerCase()).append(String.valueOf(c).toUpperCase())
.append(']');
}
else
{
@ -2350,6 +2379,31 @@ public class Mobibot extends PircBot
}
}
/**
* Posts a message to Jaiku.
*
* @param sender The sender's nick.
* @param message The message.
*/
private void jaikuResponse(String sender, String message)
{
if (isValidString(_jaikuKey) && isValidString(_jaikuUser))
{
if (message.length() > 0)
{
new Thread(new Jaiku(this, sender, _jaikuUser, _jaikuKey, message)).start();
}
else
{
helpResponse(sender, JAIKU_CMD);
}
}
else
{
send(sender, "The Jaiku posting facility is disabled.");
}
}
/**
* Responds with the bot's information.
*
@ -2372,8 +2426,10 @@ public class Mobibot extends PircBot
timeInSeconds -= (hours * 3600L);
final long minutes = timeInSeconds / 60L;
send(sender, "Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " +
_entries.size() + ']', isPrivate);
send(sender,
"Uptime: " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) [Entries: " + _entries.size()
+ ']',
isPrivate);
}
/**
@ -2504,10 +2560,13 @@ public class Mobibot extends PircBot
for (int i = items.size() - 1; i >= 0; i--)
{
item = (SyndEntryImpl) items.get(i);
author =
item.getAuthor().substring(item.getAuthor().lastIndexOf('(') + 1, item.getAuthor().length() - 1);
entry =
new EntryLink(item.getLink(), item.getTitle(), author, getChannel(), item.getPublishedDate(),
author = item.getAuthor()
.substring(item.getAuthor().lastIndexOf('(') + 1, item.getAuthor().length() - 1);
entry = new EntryLink(item.getLink(),
item.getTitle(),
author,
getChannel(),
item.getPublishedDate(),
item.getCategories());
description = item.getDescription();
comments = description.getValue().split("<br/>");
@ -2557,7 +2616,8 @@ public class Mobibot extends PircBot
}
catch (UnknownHostException e)
{
if (query.matches("(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"))
if (query.matches(
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"))
{
try
{
@ -2821,6 +2881,18 @@ public class Mobibot extends PircBot
_googleKey = googleKey;
}
/**
* Sets the Jaiku user and API key..
*
* @param user The Jaiku user.
* @param key The Jaiku API key.
*/
private void setJaikuAuth(String user, String key)
{
_jaikuKey = key;
_jaikuUser = user;
}
/**
* Sets the ident password.
*
@ -2831,7 +2903,6 @@ public class Mobibot extends PircBot
_ident = pwd;
}
/**
* Sets the ident message.
*
@ -2842,7 +2913,6 @@ public class Mobibot extends PircBot
_identMsg = msg;
}
/**
* Sets the ident nickname.
*
@ -2966,9 +3036,8 @@ public class Mobibot extends PircBot
else
{
TIME_SDF.setTimeZone(TimeZone.getTimeZone(tz));
response =
TIME_SDF.format(Calendar.getInstance().getTime()) +
tz.substring(tz.indexOf('/') + 1).replace('_', ' ');
response = TIME_SDF.format(Calendar.getInstance().getTime()) + tz.substring(tz.indexOf('/') + 1)
.replace('_', ' ');
}
}
else
@ -3085,14 +3154,16 @@ public class Mobibot extends PircBot
if (lcArgs.length() > 0)
{
if ((entry.getLink().toLowerCase().indexOf(lcArgs) != -1) ||
(entry.getTitle().toLowerCase().indexOf(lcArgs) != -1) ||
(entry.getNick().toLowerCase().indexOf(lcArgs) != -1))
if ((entry.getLink().toLowerCase().indexOf(lcArgs) != -1)
|| (entry.getTitle().toLowerCase().indexOf(lcArgs) != -1) || (
entry.getNick().toLowerCase().indexOf(lcArgs) != -1))
{
if (sent > MAX_ENTRIES)
{
send(sender, "To view more, try: " +
bold(getNick() + ": " + VIEW_CMD + ' ' + (i + 1) + ' ' + lcArgs), isPrivate);
send(sender,
"To view more, try: " + bold(
getNick() + ": " + VIEW_CMD + ' ' + (i + 1) + ' ' + lcArgs),
isPrivate);
break;
}
@ -3105,7 +3176,8 @@ public class Mobibot extends PircBot
{
if (sent > MAX_ENTRIES)
{
send(sender, "To view more, try: " + bold(getNick() + ": " + VIEW_CMD + ' ' + (i + 1)),
send(sender,
"To view more, try: " + bold(getNick() + ": " + VIEW_CMD + ' ' + (i + 1)),
isPrivate);
break;

View file

@ -1,5 +1,5 @@
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
/* Creation date Wed Jul 18 23:09:10 PDT 2007 */
/* Creation date Thu Oct 11 16:35:17 PDT 2007 */
package net.thauvin.erik.mobibot;
import java.util.Date;
@ -20,21 +20,21 @@ public class ReleaseInfo {
}
/** buildDate (set during build process to 1184825350594L). */
private static final Date buildDate = new Date(1184825350594L);
/** buildDate (set during build process to 1192145717288L). */
private static final Date buildDate = new Date(1192145717288L);
/**
* Get buildDate (set during build process to Wed Jul 18 23:09:10 PDT 2007).
* Get buildDate (set during build process to Thu Oct 11 16:35:17 PDT 2007).
* @return Date buildDate
*/
public static Date getBuildDate() { return buildDate; }
/**
* Get buildNumber (set during build process to 70).
* Get buildNumber (set during build process to 72).
* @return int buildNumber
*/
public static int getBuildNumber() { return 70; }
public static int getBuildNumber() { return 72; }
/** project (set during build process to "mobibot"). */