"));
+ }
else if (lcTopic.endsWith(RECAP_CMD))
{
send(sender, "To list the last 10 public channel messages:");
@@ -1054,7 +1090,7 @@ public class Mobibot extends PircBot
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));
+ send(sender, DOUBLE_INDENT + bold(JAIKU_CMD + ' ' + TWITTER_CMD + ' ' + WEATHER_CMD));
if (isOp(sender))
{
@@ -1391,6 +1427,10 @@ public class Mobibot extends PircBot
{
jaikuResponse(sender, args);
}
+ else if (cmd.startsWith(TWITTER_CMD))
+ {
+ twitterResponse(sender, args);
+ }
else if (cmd.startsWith(SPELL_CMD))
{
spellResponse(sender, args);
@@ -2404,6 +2444,31 @@ public class Mobibot extends PircBot
}
}
+ /**
+ * Posts a message to Twitter.
+ *
+ * @param sender The sender's nick.
+ * @param message The message.
+ */
+ private void twitterResponse(String sender, String message)
+ {
+ if (isValidString(_twitterPwd) && isValidString(_twitterUser))
+ {
+ if (message.length() > 0)
+ {
+ new Thread(new Twitter(this, sender, _twitterUser, _twitterPwd, _twitterSrc, message)).start();
+ }
+ else
+ {
+ helpResponse(sender, TWITTER_CMD);
+ }
+ }
+ else
+ {
+ send(sender, "The Twitter posting facility is disabled.");
+ }
+ }
+
/**
* Responds with the bot's information.
*
@@ -2441,12 +2506,8 @@ public class Mobibot extends PircBot
*/
private boolean isIgnoredNick(String nick)
{
- if (isValidString(nick))
- {
- return _ignoredNicks.contains(nick.toLowerCase());
- }
+ return isValidString(nick) && _ignoredNicks.contains(nick.toLowerCase());
- return false;
}
/**
@@ -2893,6 +2954,20 @@ public class Mobibot extends PircBot
_jaikuUser = user;
}
+ /**
+ * Sets the Twitter user and password..
+ *
+ * @param user The Twitter user.
+ * @param key The Twitter password.
+ * @param source The Twitter source.
+ */
+ private void setTwitterAuth(String user, String key, String source)
+ {
+ _twitterPwd = key;
+ _twitterUser = user;
+ _twitterSrc = source;
+ }
+
/**
* Sets the ident password.
*
diff --git a/src/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/net/thauvin/erik/mobibot/ReleaseInfo.java
index bb75834..4d33a81 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 Thu Oct 11 18:41:48 PDT 2007 */
+/* Creation date Wed Sep 10 20:04:51 PDT 2008 */
package net.thauvin.erik.mobibot;
import java.util.Date;
@@ -20,21 +20,21 @@ public class ReleaseInfo {
}
- /** buildDate (set during build process to 1192153308645L). */
- private static final Date buildDate = new Date(1192153308645L);
+ /** buildDate (set during build process to 1221102291797L). */
+ private static final Date buildDate = new Date(1221102291797L);
/**
- * Get buildDate (set during build process to Thu Oct 11 18:41:48 PDT 2007).
+ * Get buildDate (set during build process to Wed Sep 10 20:04:51 PDT 2008).
* @return Date buildDate
*/
public static Date getBuildDate() { return buildDate; }
/**
- * Get buildNumber (set during build process to 0).
+ * Get buildNumber (set during build process to 3).
* @return int buildNumber
*/
- public static int getBuildNumber() { return 0; }
+ public static int getBuildNumber() { return 3; }
/** project (set during build process to "mobibot"). */
diff --git a/src/net/thauvin/erik/mobibot/Twitter.java b/src/net/thauvin/erik/mobibot/Twitter.java
new file mode 100644
index 0000000..588bd50
--- /dev/null
+++ b/src/net/thauvin/erik/mobibot/Twitter.java
@@ -0,0 +1,93 @@
+/*
+ * @(#)Jaiku.java
+ *
+ * Copyright (C) 2007 Erik C. Thauvin
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+package net.thauvin.erik.mobibot;
+
+/**
+ * Inserts presence information into Twitter.
+ *
+ * @author Erik C. Thauvin
+ * @version $Revision$, $Date$
+ * @created Sept 10, 2008
+ * @since 1.0
+ */
+public class Twitter implements Runnable
+{
+ /**
+ * The bot.
+ */
+ private final Mobibot _bot;
+
+ /**
+ * The Twitter API password.
+ */
+ private final String _pwd;
+
+ /**
+ * The Twitter user.
+ */
+ private final String _user;
+
+ /**
+ * The Twitter message.
+ */
+ private final String _message;
+
+ /**
+ * The Twitter source.
+ */
+ private final String _source;
+
+ /**
+ * The nick of the person who sent the message.
+ */
+ private final String _sender;
+
+ /**
+ * Creates a new Twitter object.
+ *
+ * @param bot The bot.
+ * @param sender The nick of the person who sent the message.
+ * @param user The Twitter user.
+ * @param password The Twitter password.
+ * @param source The Twitter client id/source.
+ * @param message The Twitter message.
+ */
+ public Twitter(Mobibot bot, String sender, String user, String password, String source, String message)
+ {
+ _bot = bot;
+ _user = user;
+ _pwd = password;
+ _source = source;
+ _message = message;
+ _sender = sender;
+ }
+
+ public final void run()
+ {
+ try
+ {
+ twitter4j.Twitter twitter = new twitter4j.Twitter(_user, _pwd);
+
+ if (Mobibot.isValidString(_source))
+ {
+ twitter.setSource(_source);
+ }
+
+ twitter.update(_message + " (" + _sender + ')');
+
+ _bot.send(_sender, "You message was posted to http://twitter.com/" + _user);
+ }
+ catch (Exception e)
+ {
+ _bot.getLogger().warn("Unable to post to Twitter: " + _message, e);
+ _bot.send(_sender, "An error has occurred: " + e.getMessage());
+ }
+ }
+}
\ No newline at end of file
diff --git a/website/index.html b/website/index.html
index cebb98e..fcbaff2 100644
--- a/website/index.html
+++ b/website/index.html
@@ -22,9 +22,11 @@
Google Tag Library
JWeather
MathEvaluator
- Rome
+ Rome
+ Apache XML-RPC (for Jaiku)
+ Twitter4J
- mobibot was written by Erik C. Thauvin as a replacement for the channel's original ChumpBot.
+ mobibot was written by Erik C. Thauvin as a replacement for the channel's original ChumpBot.
Features
mobibot's main functionality is to capture URLs posted on the channel. The URLs are automatically gathered into a publishable RSS feed.
Other features include:
@@ -41,9 +43,10 @@
Displaying the time in various time zones
Listing the users on the channel
Displaying weather information
+ Posting to Jaiku's #mobitopia channel
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.
Using mobibot
To use mobibot, simply join #mobitopia on irc.freenode.net and type:
mobibot: help