Removed Jaiku (defunct) support.
Replaced Google SOAP API (defunct) with JSON API. Added support for posting to identi.ca. Fixed various StockQuote fetching problems.
This commit is contained in:
parent
dc3b4bb675
commit
a70a0629c3
26 changed files with 586 additions and 778 deletions
|
@ -36,34 +36,25 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import com.google.soap.search.GoogleSearchFault;
|
||||
|
||||
import net.thauvin.google.GoogleSearchBean;
|
||||
|
||||
import org.jibble.pircbot.Colors;
|
||||
import twitter4j.internal.org.json.JSONArray;
|
||||
import twitter4j.internal.org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* Performs a Google search or spell checking query.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
*
|
||||
* @created Feb 7, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
public class GoogleSearch implements Runnable
|
||||
{
|
||||
/**
|
||||
* The maximum number of Google results to display.
|
||||
*/
|
||||
private static final int MAX_GOOGLE = 5;
|
||||
|
||||
/**
|
||||
* The Google search bean.
|
||||
*/
|
||||
private static final GoogleSearchBean GOOGLE_BEAN = new GoogleSearchBean();
|
||||
|
||||
/**
|
||||
* The tab indent (4 spaces).
|
||||
*/
|
||||
|
@ -74,11 +65,6 @@ public class GoogleSearch implements Runnable
|
|||
*/
|
||||
private final Mobibot _bot;
|
||||
|
||||
/**
|
||||
* The Google API key.
|
||||
*/
|
||||
private final String _key;
|
||||
|
||||
/**
|
||||
* The search query.
|
||||
*/
|
||||
|
@ -89,27 +75,18 @@ public class GoogleSearch implements Runnable
|
|||
*/
|
||||
private final String _sender;
|
||||
|
||||
/**
|
||||
* Spell Checking query flag.
|
||||
*/
|
||||
private final boolean _isSpellQuery;
|
||||
|
||||
/**
|
||||
* Creates a new GoogleSearch object.
|
||||
*
|
||||
* @param bot The bot.
|
||||
* @param key The Google API key.
|
||||
* @param sender The nick of the person who sent the message.
|
||||
* @param query The Google query
|
||||
* @param isSpellQuery Set to true if the query is a Spell Checking query
|
||||
*/
|
||||
public GoogleSearch(Mobibot bot, String key, String sender, String query, boolean isSpellQuery)
|
||||
public GoogleSearch(Mobibot bot, String sender, String query)
|
||||
{
|
||||
_bot = bot;
|
||||
_key = key;
|
||||
_sender = sender;
|
||||
_query = query;
|
||||
_isSpellQuery = isSpellQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,53 +94,41 @@ public class GoogleSearch implements Runnable
|
|||
*/
|
||||
public final void run()
|
||||
{
|
||||
GOOGLE_BEAN.setKey(_key);
|
||||
|
||||
if (_isSpellQuery)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
final String r = GOOGLE_BEAN.getSpellingSuggestion(_query);
|
||||
final String query = URLEncoder.encode(_query, "UTF-8");
|
||||
|
||||
if (Mobibot.isValidString(r))
|
||||
{
|
||||
_bot.send(_sender, Mobibot.unescapeXml(r));
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.send(_sender, "You've just won our spelling bee contest.");
|
||||
}
|
||||
}
|
||||
catch (GoogleSearchFault e)
|
||||
final URL url =
|
||||
new URL("http://ajax.googleapis.com/ajax/services/search/web?start=0&rsz=small&v=1.0&q=" + query);
|
||||
final URLConnection conn = url.openConnection();
|
||||
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
_bot.getLogger().warn("Unable to spell: " + _query, e);
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
final JSONObject json = new JSONObject(sb.toString());
|
||||
final JSONArray ja = json.getJSONObject("responseData").getJSONArray("results");
|
||||
|
||||
for (int i = 0; i < ja.length(); i++)
|
||||
{
|
||||
final JSONObject j = ja.getJSONObject(i);
|
||||
_bot.send(_sender, Mobibot.unescapeXml(j.getString("titleNoFormatting")));
|
||||
_bot.send(_sender, TAB_INDENT + j.getString("url"));
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
GOOGLE_BEAN.getGoogleSearch(_query, GoogleSearchBean.DEFAULT_START, MAX_GOOGLE,
|
||||
GoogleSearchBean.DEFAULT_FILTER, GoogleSearchBean.DEFAULT_RESTRICT,
|
||||
GoogleSearchBean.DEFAULT_SAFE_SEARCH, GoogleSearchBean.DEFAULT_LR);
|
||||
|
||||
if (GOOGLE_BEAN.isValidResult())
|
||||
{
|
||||
for (int i = 0; i < GOOGLE_BEAN.getResultElementsCount(); i++)
|
||||
{
|
||||
_bot.send(_sender,
|
||||
Mobibot.unescapeXml(GOOGLE_BEAN.getResultElementProperty(i, "title").replaceAll("<([bB]|/[bB])>",
|
||||
Colors.BOLD)));
|
||||
_bot.send(_sender, TAB_INDENT + GOOGLE_BEAN.getResultElementProperty(i, "url"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GoogleSearchFault e)
|
||||
{
|
||||
_bot.getLogger().warn("Unable to search in Google for: " + _query, e);
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
}
|
||||
_bot.getLogger().warn("Unable to search in Google for: " + _query, e);
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
141
src/net/thauvin/erik/mobibot/Identica.java
Normal file
141
src/net/thauvin/erik/mobibot/Identica.java
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* @(#)Identica.java
|
||||
*
|
||||
* Copyright (C) 2010 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$
|
||||
*
|
||||
*/
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import twitter4j.internal.http.BASE64Encoder;
|
||||
import twitter4j.internal.org.json.JSONObject;
|
||||
import twitter4j.internal.org.json.XML;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* The <code>Identica</code> class.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <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);
|
||||
|
||||
_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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 + " <query>"));
|
||||
}
|
||||
else if (lcTopic.endsWith(JAIKU_CMD) && isJaikuEnabled())
|
||||
else if (lcTopic.endsWith(IDENTICA_CMD) && isIdenticaEnabled())
|
||||
{
|
||||
send(sender, "To post to Jaiku:");
|
||||
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + JAIKU_CMD + " <message>"));
|
||||
send(sender, "To post to identi.ca:");
|
||||
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + IDENTICA_CMD + " <message>"));
|
||||
}
|
||||
else if (lcTopic.endsWith(TWITTER_CMD) && isTwitterEnabled())
|
||||
{
|
||||
|
@ -1018,11 +1002,6 @@ public class Mobibot extends PircBot
|
|||
send(sender, "For a listing of the supported countries:");
|
||||
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + TIME_CMD));
|
||||
}
|
||||
else if (lcTopic.endsWith(SPELL_CMD) && isGoogleEnabled())
|
||||
{
|
||||
send(sender, "To have Google try to correctly spell a sentence:");
|
||||
send(sender, DOUBLE_INDENT + bold(getNick() + ": " + SPELL_CMD + " <sentence>"));
|
||||
}
|
||||
else if (lcTopic.endsWith(STOCK_CMD))
|
||||
{
|
||||
send(sender, "To retrieve a stock quote:");
|
||||
|
@ -1119,14 +1098,13 @@ public class Mobibot extends PircBot
|
|||
CURRENCY_CMD,
|
||||
DICE_CMD,
|
||||
GOOGLE_CMD,
|
||||
IDENTICA_CMD,
|
||||
IGNORE_CMD,
|
||||
INFO_CMD,
|
||||
JAIKU_CMD,
|
||||
LOOKUP_CMD,
|
||||
getChannel().substring(1),
|
||||
HELP_POSTING_KEYWORD,
|
||||
RECAP_CMD,
|
||||
SPELL_CMD,
|
||||
STOCK_CMD,
|
||||
HELP_TAGS_KEYWORD,
|
||||
TIME_CMD,
|
||||
|
@ -1142,14 +1120,9 @@ public class Mobibot extends PircBot
|
|||
|
||||
for (int i = 0, cmdCount = 1; i < cmds.length; i++, cmdCount++)
|
||||
{
|
||||
if (cmds[i].equals(GOOGLE_CMD) || cmds[i].equals(SPELL_CMD))
|
||||
if (cmds[i].equals(IDENTICA_CMD))
|
||||
{
|
||||
isValidCmd = isGoogleEnabled();
|
||||
}
|
||||
|
||||
if (cmds[i].equals(JAIKU_CMD))
|
||||
{
|
||||
isValidCmd = isJaikuEnabled();
|
||||
isValidCmd = isIdenticaEnabled();
|
||||
}
|
||||
|
||||
if (cmds[i].equals(TWITTER_CMD))
|
||||
|
@ -1290,9 +1263,8 @@ 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);
|
||||
|
@ -1520,18 +1492,14 @@ public class Mobibot extends PircBot
|
|||
{
|
||||
googleResponse(sender, args);
|
||||
}
|
||||
else if (cmd.startsWith(JAIKU_CMD))
|
||||
else if (cmd.startsWith(IDENTICA_CMD))
|
||||
{
|
||||
jaikuResponse(sender, args);
|
||||
identicaResponse(sender, args);
|
||||
}
|
||||
else if (cmd.startsWith(TWITTER_CMD))
|
||||
{
|
||||
twitterResponse(sender, args);
|
||||
}
|
||||
else if (cmd.startsWith(SPELL_CMD))
|
||||
{
|
||||
spellResponse(sender, args);
|
||||
}
|
||||
else if (cmd.startsWith(STOCK_CMD))
|
||||
{
|
||||
stockResponse(sender, args);
|
||||
|
@ -2495,16 +2463,6 @@ public class Mobibot extends PircBot
|
|||
return _today;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if Google services are enabled.
|
||||
*
|
||||
* @return <code>true</code> or <code>false</code>
|
||||
*/
|
||||
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 <code>true</code> if jaiku posting is enabled.
|
||||
* Returns <code>true</code> if identi.ca posting is enabled.
|
||||
*
|
||||
* @return <code>true</code> or <code>false</code>
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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$
|
||||
*
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue