Identica
class.
+ *
+ * @author Erik C. Thauvin
+ * @version $Revision$, $Date$
+ * @created Sep 14, 2010
+ * @since 1.0
+ */
+public class Identica implements Runnable
+{
+ /**
+ * The bot.
+ */
+ private final Mobibot _bot;
+
+ /**
+ * The identi.ca user.
+ */
+ private final String _user;
+
+ /**
+ * The identi.ca password.
+ */
+ private final String _pwd;
+ /**
+ * The identi.ca message.
+ */
+ private final String _message;
+
+ /**
+ * The nick of the person who sent the message.
+ */
+ private final String _sender;
+
+ /**
+ * Creates a new identi.ca object.
+ *
+ * @param bot The bot.
+ * @param sender The nick of the person who sent the message.
+ * @param user The identi.ca user.
+ * @param pwd The identi.ca passwword.
+ * @param message The identi.ca message.
+ */
+ public Identica(Mobibot bot, String sender, String user, String pwd, String message)
+ {
+ _bot = bot;
+ _sender = sender;
+ _user = user;
+ _pwd = pwd;
+ _message = message;
+ }
+
+ public final void run()
+ {
+ try
+ {
+ final String auth = _user + ':' + _pwd;
+
+ final URL url = new URL("http://identi.ca/api/statuses/update.xml");
+ final URLConnection conn = url.openConnection();
+ conn.setRequestProperty("Authorization", "Basic " + BASE64Encoder.encode(auth.getBytes()));
+ conn.setDoOutput(true);
+
+ final OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
+
+ writer.write("status=" + URLEncoder.encode(_message + " (" + _sender + ')', "UTF-8"));
+ writer.flush();
+
+ final StringBuffer sb = new StringBuffer();
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ sb.append(line);
+ }
+
+ final JSONObject response = XML.toJSONObject(sb.toString());
+ final int id = response.getJSONObject("status").getInt("id");
+
+ _bot.send(_sender, "You message was posted to http://identi.ca/notice/" + id);
+
+ writer.close();
+ reader.close();
+ }
+ catch (Exception e)
+ {
+ _bot.getLogger().warn("Unable to post to identi.ca: " + _message, e);
+ _bot.send(_sender, "An error has occurred: " + e.getMessage());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/net/thauvin/erik/mobibot/Jaiku.java b/src/net/thauvin/erik/mobibot/Jaiku.java
deleted file mode 100644
index 90048a3..0000000
--- a/src/net/thauvin/erik/mobibot/Jaiku.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * @(#)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 Erik C. Thauvin
- * @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);
-
- _bot.send(_sender, "You message was posted to http://jaiku.com/channel/" + _bot.getChannel().substring(1));
- }
- catch (Exception e)
- {
- _bot.getLogger().warn("Unable to post to Jaiku: " + _message, e);
- _bot.send(_sender, "An error has occurred: " + e.getMessage());
- }
- }
-}
diff --git a/src/net/thauvin/erik/mobibot/Mobibot.java b/src/net/thauvin/erik/mobibot/Mobibot.java
index 47e2b55..49a7ac6 100644
--- a/src/net/thauvin/erik/mobibot/Mobibot.java
+++ b/src/net/thauvin/erik/mobibot/Mobibot.java
@@ -87,15 +87,14 @@ public class Mobibot extends PircBot
* The info strings.
*/
private static final String[] INFO_STRS =
- {"Mobibot v" + ReleaseInfo.getVersion() + '.' + ReleaseInfo.getBuildNumber()
+ {ReleaseInfo.getProject() + " v" + ReleaseInfo.getVersion() + '.' + ReleaseInfo.getBuildNumber()
+ " by Erik C. Thauvin (erik@thauvin.net)", "http://www.mobitopia.org/mobibot/"};
/**
* The version strings.
*/
private static final String[] VERSION_STRS =
- {"Version: " + ReleaseInfo.getVersion() + '.' + ReleaseInfo.getBuildNumber() + " ("
- + ISO_SDF.format(ReleaseInfo.getBuildDate()) + ')',
+ {"Version: " + ReleaseInfo.getVersion() + '.' + ReleaseInfo.getBuildNumber() + " (" + ISO_SDF.format(ReleaseInfo.getBuildDate()) + ')',
"Platform: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ", "
+ System.getProperty("os.arch") + ", " + System.getProperty("user.country") + ')',
"Runtime: " + System.getProperty("java.runtime.name") + " (build "
@@ -209,9 +208,9 @@ public class Mobibot extends PircBot
private static final String GOOGLE_CMD = "google";
/**
- * The Jaiku command.
+ * The identi.ca command.
*/
- private static final String JAIKU_CMD = "jaiku";
+ private static final String IDENTICA_CMD = "identica";
/**
* The Twitter command.
@@ -262,11 +261,6 @@ public class Mobibot extends PircBot
*/
private static final String RECAP_CMD = "recap";
- /**
- * The spell command.
- */
- private static final String SPELL_CMD = "spell";
-
/**
* The stock command.
*/
@@ -455,20 +449,14 @@ public class Mobibot extends PircBot
private String _feedURL = "";
/**
- * The Google API key.
+ * The identi.ca user.
*/
-
- private String _googleKey = "";
+ private String _identicaUser = "";
/**
- * The Jaiku API key.
+ * The identi.ca password.
*/
- private String _jaikuKey = "";
-
- /**
- * The Jaiku user.
- */
- private String _jaikuUser = "";
+ private String _identicaPwd = "";
/**
* The Twitter consumer key.
@@ -743,7 +731,6 @@ public class Mobibot extends PircBot
final String weblogURL = p.getProperty("weblog", "");
final String feedURL = p.getProperty("feed", "");
final String backlogsURL = ensureDir(p.getProperty("backlogs", weblogURL), true);
- final String googleKey = p.getProperty("google", "");
final String ignoredNicks = p.getProperty("ignore", "");
final String identNick = p.getProperty("ident-nick", "");
final String identMsg = p.getProperty("ident-msg", "");
@@ -754,9 +741,9 @@ 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");
+ // Get the identi.ca properties
+ final String iname = p.getProperty("identica-user");
+ final String ipwd = p.getProperty("identica-pwd");
// Get the Twitter properties
final String tconsumerKey = p.getProperty("twitter-consumerKey");
@@ -787,19 +774,16 @@ public class Mobibot extends PircBot
bot.setFeedURL(feedURL);
bot.setBacklogsURL(backlogsURL);
- // 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))
+ if (isValidString(iname) && isValidString(ipwd))
{
- // Set the Jaiku authentication
- bot.setJaikuAuth(jname, jkey);
+ // Set the identi.ca authentication
+ bot.setIdenticaAuth(iname, ipwd);
}
if (isValidString(tconsumerKey) && isValidString(tconsumerSecret) && isValidString(ttoken) && isValidString(
@@ -980,15 +964,15 @@ public class Mobibot extends PircBot
send(sender, "To list the last 5 posts from the channel's weblog:");
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + getChannel().substring(1)));
}
- else if (lcTopic.endsWith(GOOGLE_CMD) && isGoogleEnabled())
+ else if (lcTopic.endsWith(GOOGLE_CMD))
{
send(sender, "To search Google:");
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + GOOGLE_CMD + " true
if Google services are enabled.
- *
- * @return true
or false
- */
- private boolean isGoogleEnabled()
- {
- return isValidString(_googleKey);
- }
-
/**
* Responds with the Google search results for the specified query.
*
@@ -2513,55 +2471,50 @@ public class Mobibot extends PircBot
*/
private void googleResponse(String sender, String query)
{
- if (isGoogleEnabled())
+
+ if (query.length() > 0)
{
- if (query.length() > 0)
- {
- new Thread(new GoogleSearch(this, _googleKey, sender, query, false)).start();
- }
- else
- {
- helpResponse(sender, GOOGLE_CMD);
- }
+ new Thread(new GoogleSearch(this, sender, query)).start();
}
else
{
- send(sender, "The Google search facility is disabled.");
+ helpResponse(sender, GOOGLE_CMD);
}
+
}
/**
- * Returns true
if jaiku posting is enabled.
+ * Returns true
if identi.ca posting is enabled.
*
* @return true
or false
*/
- private boolean isJaikuEnabled()
+ private boolean isIdenticaEnabled()
{
- return isValidString(_jaikuKey) && isValidString(_jaikuUser);
+ return isValidString(_identicaPwd) && isValidString(_identicaUser);
}
/**
- * Posts a message to Jaiku.
+ * Posts a message to identi.ca.
*
* @param sender The sender's nick.
* @param message The message.
*/
- private void jaikuResponse(String sender, String message)
+ private void identicaResponse(String sender, String message)
{
- if (isJaikuEnabled())
+ if (isIdenticaEnabled())
{
if (message.length() > 0)
{
- new Thread(new Jaiku(this, sender, _jaikuUser, _jaikuKey, message)).start();
+ new Thread(new Identica(this, sender, _identicaUser, _identicaPwd, message)).start();
}
else
{
- helpResponse(sender, JAIKU_CMD);
+ helpResponse(sender, IDENTICA_CMD);
}
}
else
{
- send(sender, "The Jaiku posting facility is disabled.");
+ send(sender, "The identi.ca posting facility is disabled.");
}
}
@@ -3088,25 +3041,15 @@ public class Mobibot extends PircBot
}
/**
- * Sets the Google API key.
+ * Sets the identi.ca user and password...
*
- * @param googleKey The Google API key.
+ * @param user The identi.ca user.
+ * @param key The identi.ca password.
*/
- private void setGoogleKey(String googleKey)
+ private void setIdenticaAuth(String user, String key)
{
- _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;
+ _identicaPwd = key;
+ _identicaUser = user;
}
/**
@@ -3203,31 +3146,6 @@ public class Mobibot extends PircBot
_weblogURL = weblogURL;
}
- /**
- * Uses Google to correctly spell a sentence.
- *
- * @param sender The nick of the person who sent the message
- * @param spell The sentence to spell.
- */
- private void spellResponse(String sender, String spell)
- {
- if (isGoogleEnabled())
- {
- if (spell.length() > 0)
- {
- new Thread(new GoogleSearch(this, _googleKey, getChannel(), spell, true)).start();
- }
- else
- {
- helpResponse(sender, SPELL_CMD);
- }
- }
- else
- {
- send(getChannel(), "The Google spelling facility is disabled.");
- }
- }
-
/**
* Responds with the specified stock quote.
*
diff --git a/src/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/net/thauvin/erik/mobibot/ReleaseInfo.java
index 98080e5..a26391d 100644
--- a/src/net/thauvin/erik/mobibot/ReleaseInfo.java
+++ b/src/net/thauvin/erik/mobibot/ReleaseInfo.java
@@ -1,5 +1,5 @@
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
-/* Creation date Tue Sep 14 16:51:11 PDT 2010 */
+/* Creation date Wed Sep 15 03:24:37 PDT 2010 */
package net.thauvin.erik.mobibot;
import java.util.Date;
@@ -20,21 +20,21 @@ public class ReleaseInfo {
}
- /** buildDate (set during build process to 1284508271605L). */
- private static final Date buildDate = new Date(1284508271605L);
+ /** buildDate (set during build process to 1284546277926L). */
+ private static final Date buildDate = new Date(1284546277926L);
/**
- * Get buildDate (set during build process to Tue Sep 14 16:51:11 PDT 2010).
+ * Get buildDate (set during build process to Wed Sep 15 03:24:37 PDT 2010).
* @return Date buildDate
*/
public static Date getBuildDate() { return buildDate; }
/**
- * Get buildNumber (set during build process to 8).
+ * Get buildNumber (set during build process to 0).
* @return int buildNumber
*/
- public static int getBuildNumber() { return 8; }
+ public static int getBuildNumber() { return 0; }
/** project (set during build process to "mobibot"). */
@@ -47,11 +47,11 @@ public class ReleaseInfo {
public static String getProject() { return project; }
- /** version (set during build process to "0.4"). */
- private static final String version = "0.4";
+ /** version (set during build process to "0.5"). */
+ private static final String version = "0.5";
/**
- * Get version (set during build process to "0.4").
+ * Get version (set during build process to "0.5").
* @return String version
*/
public static String getVersion() { return version; }
diff --git a/src/net/thauvin/erik/mobibot/StockQuote.java b/src/net/thauvin/erik/mobibot/StockQuote.java
index fb765e0..6eb946b 100644
--- a/src/net/thauvin/erik/mobibot/StockQuote.java
+++ b/src/net/thauvin/erik/mobibot/StockQuote.java
@@ -36,19 +36,19 @@
*/
package net.thauvin.erik.mobibot;
+import com.Ostermiller.util.CSVParser;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import java.io.IOException;
-
/**
* Retrieves a stock quote from Yahoo!.
*
- * @author Erik C. Thauvin
+ * @author Erik C. Thauvin
* @version $Revision$, $Date$
* @created Feb 7, 2004
- * @since 1.0
+ * @since 1.0
*/
public class StockQuote implements Runnable
{
@@ -75,7 +75,7 @@ public class StockQuote implements Runnable
/**
* Creates a new StockQuote object.
*
- * @param bot The bot.
+ * @param bot The bot.
* @param sender The nick of the person who sent the message.
* @param symbol The stock symbol.
*/
@@ -100,48 +100,55 @@ public class StockQuote implements Runnable
final GetMethod getMethod = new GetMethod(YAHOO_URL + _symbol.toUpperCase());
client.executeMethod(getMethod);
- final String[] quote = getMethod.getResponseBodyAsString().split(",");
+ final String[][] lines = CSVParser.parse(getMethod.getResponseBodyAsString());
- if (quote.length > 0)
+ if (lines.length > 0)
{
- if ((quote.length > 3) && (!"\"N/A\"".equalsIgnoreCase(quote[3])))
- {
- _bot.send(_bot.getChannel(),
- "Symbol: " + quote[0].replaceAll("\"", "") + " [" + quote[1].replaceAll("\"", "") + ']');
+ final String[] quote = lines[0];
- if (quote.length > 5)
+ if (quote.length > 0)
+ {
+ if ((quote.length > 3) && (!"N/A".equalsIgnoreCase(quote[3])))
{
- _bot.send(_bot.getChannel(), "Last Trade: " + quote[2] + " (" + quote[5] + ')');
+ _bot.send(_bot.getChannel(), "Symbol: " + quote[0] + " [" + quote[1] + ']');
+
+ if (quote.length > 5)
+ {
+ _bot.send(_bot.getChannel(), "Last Trade: " + quote[2] + " (" + quote[5] + ')');
+ }
+ else
+ {
+ _bot.send(_bot.getChannel(), "Last Trade: " + quote[2]);
+ }
+
+ if (quote.length > 4)
+ {
+ _bot.send(_sender, "Time: " + quote[3] + ' ' + quote[4]);
+ }
+
+ if (quote.length > 6 && !"N/A".equalsIgnoreCase(quote[6]))
+ {
+ _bot.send(_sender, "Open: " + quote[6]);
+ }
+
+ if (quote.length > 7 && !"N/A".equalsIgnoreCase(quote[7]) && !"N/A".equalsIgnoreCase(quote[8]))
+ {
+ _bot.send(_sender, "Day's Range: " + quote[7] + " - " + quote[8]);
+ }
+
+ if (quote.length > 9 && !"0".equalsIgnoreCase(quote[9]))
+ {
+ _bot.send(_sender, "Volume: " + quote[9]);
+ }
}
else
{
- _bot.send(_bot.getChannel(), "Last Trade: " + quote[2]);
- }
-
- if (quote.length > 4)
- {
- _bot.send(_sender,
- "Time: " + quote[3].replaceAll("\"", "") + ' ' + quote[4].replaceAll("\"", ""));
- }
-
- if (quote.length > 6)
- {
- _bot.send(_sender, "Open: " + quote[6]);
- }
-
- if (quote.length > 7)
- {
- _bot.send(_sender, "Day's Range: " + quote[7] + " - " + quote[8]);
- }
-
- if (quote.length > 9)
- {
- _bot.send(_sender, "Volume: " + quote[9]);
+ _bot.send(_sender, "Invalid ticker symbol.");
}
}
else
{
- _bot.send(_sender, "Invalid ticker symbol.");
+ _bot.send(_sender, "No values returned.");
}
}
else
diff --git a/src/net/thauvin/erik/mobibot/Twitter.java b/src/net/thauvin/erik/mobibot/Twitter.java
index 7ed175d..ed8a907 100644
--- a/src/net/thauvin/erik/mobibot/Twitter.java
+++ b/src/net/thauvin/erik/mobibot/Twitter.java
@@ -1,9 +1,36 @@
/*
- * @(#)Jaiku.java
+ * @(#)Twitter.java
*
* Copyright (C) 2007 Erik C. Thauvin
* All rights reserved.
*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of the author nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
* $Id$
*
*/
diff --git a/website/index.html b/website/index.html
index 064d2bc..ec80add 100644
--- a/website/index.html
+++ b/website/index.html
@@ -19,7 +19,6 @@
Some of the internal features include RSS feed backlogs, rolling logs, debugging toggle and much more.
-If you have any feature suggestions, please post them to the mobibot wiki.
+If you have any feature suggestions, please post them to the mobibot wiki.
To use mobibot, simply join #mobitopia on irc.freenode.net and type:
mobibot: help