Moved to gradle build system.
Using exp4j instead of MathEvaluator for calcuation now.
This commit is contained in:
parent
3b9c5d6431
commit
5858e12b1a
50 changed files with 3124 additions and 1920 deletions
|
@ -40,24 +40,18 @@ import org.jdom.Document;
|
|||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jdom.Namespace;
|
||||
|
||||
import org.jdom.input.SAXBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Converts various currencies.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
*
|
||||
* @created Feb 11, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -78,11 +72,6 @@ public class CurrencyConverter implements Runnable
|
|||
*/
|
||||
private static final String RATES_KEYWORD = "rates";
|
||||
|
||||
/**
|
||||
* The last exchange rates table publication date.
|
||||
*/
|
||||
private String s_date = "";
|
||||
|
||||
/**
|
||||
* The bot.
|
||||
*/
|
||||
|
@ -98,6 +87,11 @@ public class CurrencyConverter implements Runnable
|
|||
*/
|
||||
private final String _sender;
|
||||
|
||||
/**
|
||||
* The last exchange rates table publication date.
|
||||
*/
|
||||
private String s_date = "";
|
||||
|
||||
/**
|
||||
* Creates a new CurrencyConverter object.
|
||||
*
|
||||
|
@ -155,8 +149,7 @@ public class CurrencyConverter implements Runnable
|
|||
catch (IOException e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to fetch the exchange rates table.", e);
|
||||
_bot.send(_sender,
|
||||
"An error has occurred while fetching the exchange rates table: " + e.getMessage());
|
||||
_bot.send(_sender, "An error has occurred while fetching the exchange rates table: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,15 +174,15 @@ public class CurrencyConverter implements Runnable
|
|||
final double to = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[3].toUpperCase()));
|
||||
|
||||
_bot.send(_bot.getChannel(),
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
|
||||
cmds[1].toUpperCase() + " = " +
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from)
|
||||
.substring(1) + ' ' + cmds[3].toUpperCase());
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
|
||||
cmds[1].toUpperCase() + " = " +
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from).substring(1)
|
||||
+ ' ' + cmds[3].toUpperCase()
|
||||
);
|
||||
}
|
||||
catch (NullPointerException ignore)
|
||||
catch (NullPointerException ignored)
|
||||
{
|
||||
_bot.send(_sender,
|
||||
"The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
_bot.send(_sender, "The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,26 +38,26 @@ package net.thauvin.erik.mobibot;
|
|||
|
||||
import del.icio.us.Delicious;
|
||||
|
||||
|
||||
/**
|
||||
* The class to handle posts to del.icio.us.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
* @created Mar 5, 2005
|
||||
* @since 1.0
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
* @created Mar 5, 2005
|
||||
* @noinspection UnnecessaryBoxing
|
||||
* @since 1.0
|
||||
*/
|
||||
public class DeliciousPoster
|
||||
{
|
||||
private final Delicious _delicious;
|
||||
|
||||
private final String _ircServer;
|
||||
|
||||
/**
|
||||
* Creates a new DeliciousPoster instance.
|
||||
*
|
||||
* @param username The del.icio.us username.
|
||||
* @param password The del.icio.us password.
|
||||
* @param username The del.icio.us username.
|
||||
* @param password The del.icio.us password.
|
||||
* @param ircServer The IRC server.
|
||||
*/
|
||||
public DeliciousPoster(String username, String password, String ircServer)
|
||||
|
@ -73,15 +73,17 @@ public class DeliciousPoster
|
|||
*/
|
||||
public final void addPost(final EntryLink entry)
|
||||
{
|
||||
final SwingWorker worker =
|
||||
new SwingWorker()
|
||||
final SwingWorker worker = new SwingWorker()
|
||||
{
|
||||
public Object construct()
|
||||
{
|
||||
public Object construct()
|
||||
{
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(), entry.getTitle(), postedBy(entry),
|
||||
entry.getDeliciousTags(), entry.getDate()));
|
||||
}
|
||||
};
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(),
|
||||
entry.getTitle(),
|
||||
postedBy(entry),
|
||||
entry.getDeliciousTags(),
|
||||
entry.getDate()));
|
||||
}
|
||||
};
|
||||
|
||||
worker.start();
|
||||
}
|
||||
|
@ -95,14 +97,13 @@ public class DeliciousPoster
|
|||
{
|
||||
final String link = entry.getLink();
|
||||
|
||||
final SwingWorker worker =
|
||||
new SwingWorker()
|
||||
final SwingWorker worker = new SwingWorker()
|
||||
{
|
||||
public Object construct()
|
||||
{
|
||||
public Object construct()
|
||||
{
|
||||
return Boolean.valueOf(_delicious.deletePost(link));
|
||||
}
|
||||
};
|
||||
return Boolean.valueOf(_delicious.deletePost(link));
|
||||
}
|
||||
};
|
||||
|
||||
worker.start();
|
||||
}
|
||||
|
@ -111,39 +112,44 @@ public class DeliciousPoster
|
|||
* Updates a post to del.icio.us.
|
||||
*
|
||||
* @param oldUrl The old post URL.
|
||||
* @param entry The entry to add.
|
||||
* @param entry The entry to add.
|
||||
*/
|
||||
public final void updatePost(final String oldUrl, final EntryLink entry)
|
||||
{
|
||||
final SwingWorker worker =
|
||||
new SwingWorker()
|
||||
final SwingWorker worker = new SwingWorker()
|
||||
{
|
||||
public Object construct()
|
||||
{
|
||||
public Object construct()
|
||||
if (!oldUrl.equals(entry.getLink()))
|
||||
{
|
||||
if (!oldUrl.equals(entry.getLink()))
|
||||
{
|
||||
_delicious.deletePost(oldUrl);
|
||||
_delicious.deletePost(oldUrl);
|
||||
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(), entry.getTitle(), postedBy(entry),
|
||||
entry.getDeliciousTags(), entry.getDate()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(), entry.getTitle(), postedBy(entry),
|
||||
entry.getDeliciousTags(), entry.getDate(), true,
|
||||
true));
|
||||
}
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(),
|
||||
entry.getTitle(),
|
||||
postedBy(entry),
|
||||
entry.getDeliciousTags(),
|
||||
entry.getDate()));
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
return Boolean.valueOf(_delicious.addPost(entry.getLink(),
|
||||
entry.getTitle(),
|
||||
postedBy(entry),
|
||||
entry.getDeliciousTags(),
|
||||
entry.getDate(),
|
||||
true,
|
||||
true));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
worker.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns he del.icio.us extended attribution line.
|
||||
*
|
||||
* @param entry The entry.
|
||||
* @param entry The entry.
|
||||
*
|
||||
* @return The extended attribution line.
|
||||
*/
|
|
@ -37,17 +37,14 @@
|
|||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* The class used to store comments associated to a specific entry.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
*
|
||||
* @created Jan 31, 2004
|
||||
* @since 1.0
|
||||
*/
|
||||
|
@ -62,7 +59,9 @@ public class EntryComment implements Serializable
|
|||
* The creation date.
|
||||
*/
|
||||
private final Date _date = Calendar.getInstance().getTime();
|
||||
|
||||
private String _comment = "";
|
||||
|
||||
private String _nick = "";
|
||||
|
||||
/**
|
||||
|
@ -79,22 +78,13 @@ public class EntryComment implements Serializable
|
|||
|
||||
/**
|
||||
* Creates a new comment.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
protected EntryComment()
|
||||
{
|
||||
; // Required for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment.
|
||||
*
|
||||
* @param comment The actual comment.
|
||||
*/
|
||||
public final void setComment(String comment)
|
||||
{
|
||||
_comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment.
|
||||
*
|
||||
|
@ -105,6 +95,17 @@ public class EntryComment implements Serializable
|
|||
return _comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment.
|
||||
*
|
||||
* @param comment The actual comment.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public final void setComment(String comment)
|
||||
{
|
||||
_comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment's creation date.
|
||||
*
|
||||
|
@ -115,16 +116,6 @@ public class EntryComment implements Serializable
|
|||
return _date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the nickname of the author of the comment.
|
||||
*
|
||||
* @param nick The new nickname.
|
||||
*/
|
||||
public final void setNick(String nick)
|
||||
{
|
||||
_nick = nick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nickname of the author of the comment.
|
||||
*
|
||||
|
@ -134,4 +125,14 @@ public class EntryComment implements Serializable
|
|||
{
|
||||
return _nick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the nickname of the author of the comment.
|
||||
*
|
||||
* @param nick The new nickname.
|
||||
*/
|
||||
public final void setNick(String nick)
|
||||
{
|
||||
_nick = nick;
|
||||
}
|
||||
}
|
|
@ -39,17 +39,18 @@ package net.thauvin.erik.mobibot;
|
|||
import com.sun.syndication.feed.synd.SyndCategoryImpl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The class used to store link entries.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
* @created Jan 31, 2004
|
||||
* @since 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EntryLink implements Serializable
|
||||
{
|
||||
|
@ -58,12 +59,15 @@ public class EntryLink implements Serializable
|
|||
*/
|
||||
static final long serialVersionUID = 3676245542270899086L;
|
||||
|
||||
// The channel
|
||||
private String _channel = "";
|
||||
|
||||
// The link's comments
|
||||
private final List _comments = new ArrayList(0);
|
||||
|
||||
// The tags/categories
|
||||
private final List _tags = new ArrayList(0);
|
||||
|
||||
// The channel
|
||||
private String _channel = "";
|
||||
|
||||
// The creation date
|
||||
private Date _date = Calendar.getInstance().getTime();
|
||||
|
||||
|
@ -76,21 +80,18 @@ public class EntryLink implements Serializable
|
|||
// The author's nickname
|
||||
private String _nick = "";
|
||||
|
||||
// The tags/categories
|
||||
private final List _tags = new ArrayList(0);
|
||||
|
||||
// The link's title
|
||||
private String _title = "";
|
||||
|
||||
/**
|
||||
* Creates a new entry.
|
||||
*
|
||||
* @param link The new entry's link.
|
||||
* @param title The new entry's title.
|
||||
* @param nick The nickname of the author of the link.
|
||||
* @param login The login of the author of the link.
|
||||
* @param link The new entry's link.
|
||||
* @param title The new entry's title.
|
||||
* @param nick The nickname of the author of the link.
|
||||
* @param login The login of the author of the link.
|
||||
* @param channel The channel.
|
||||
* @param tags The entry's tags/categories.
|
||||
* @param tags The entry's tags/categories.
|
||||
*/
|
||||
public EntryLink(String link, String title, String nick, String login, String channel, String tags)
|
||||
{
|
||||
|
@ -103,16 +104,15 @@ public class EntryLink implements Serializable
|
|||
setTags(tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new entry.
|
||||
*
|
||||
* @param link The new entry's link.
|
||||
* @param title The new entry's title.
|
||||
* @param nick The nickname of the author of the link.
|
||||
* @param link The new entry's link.
|
||||
* @param title The new entry's title.
|
||||
* @param nick The nickname of the author of the link.
|
||||
* @param channel The channel.
|
||||
* @param date The entry date.
|
||||
* @param tags The entry's tags/categories.
|
||||
* @param date The entry date.
|
||||
* @param tags The entry's tags/categories.
|
||||
*/
|
||||
public EntryLink(String link, String title, String nick, String channel, Date date, List tags)
|
||||
{
|
||||
|
@ -122,12 +122,12 @@ public class EntryLink implements Serializable
|
|||
_channel = channel;
|
||||
_date = date;
|
||||
|
||||
|
||||
setTags(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EntryLink object.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
protected EntryLink()
|
||||
{
|
||||
|
@ -137,8 +137,8 @@ public class EntryLink implements Serializable
|
|||
/**
|
||||
* Adds a new comment.
|
||||
*
|
||||
* @param comment The actual comment.
|
||||
* @param nick The nickname of the author of the comment.
|
||||
* @param comment The actual comment.
|
||||
* @param nick The nickname of the author of the comment.
|
||||
*
|
||||
* @return The total number of comments for this entry.
|
||||
*/
|
||||
|
@ -172,10 +172,21 @@ public class EntryLink implements Serializable
|
|||
return _channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the channel.
|
||||
*
|
||||
* @param channel The channel.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public final synchronized void setChannel(String channel)
|
||||
{
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comment.
|
||||
*
|
||||
* @param index The comment's index.
|
||||
* @param index The comment's index.
|
||||
*
|
||||
* @return The specific comment.
|
||||
*/
|
||||
|
@ -242,6 +253,16 @@ public class EntryLink implements Serializable
|
|||
return _link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment's link.
|
||||
*
|
||||
* @param link The new link.
|
||||
*/
|
||||
public final synchronized void setLink(String link)
|
||||
{
|
||||
_link = link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return's the comment's author login.
|
||||
*
|
||||
|
@ -252,6 +273,17 @@ public class EntryLink implements Serializable
|
|||
return _login;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment's author login.
|
||||
*
|
||||
* @param login The new login.
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public final synchronized void setLogin(String login)
|
||||
{
|
||||
_login = login;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment's author nickname.
|
||||
*
|
||||
|
@ -262,91 +294,6 @@ public class EntryLink implements Serializable
|
|||
return _nick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tags.
|
||||
*
|
||||
* @return The tags.
|
||||
*/
|
||||
public final synchronized List getTags()
|
||||
{
|
||||
return _tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment's title.
|
||||
*
|
||||
* @return The title.
|
||||
*/
|
||||
public final synchronized String getTitle()
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entry has comments.
|
||||
*
|
||||
* @return true if there are comments, false otherwise.
|
||||
*/
|
||||
public final synchronized boolean hasComments()
|
||||
{
|
||||
return (!_comments.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entry has tags.
|
||||
*
|
||||
* @return true if there are tags, false otherwise.
|
||||
*/
|
||||
public final synchronized boolean hasTags()
|
||||
{
|
||||
return (!_tags.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the channel.
|
||||
*
|
||||
* @param channel The channel.
|
||||
*/
|
||||
public final synchronized void setChannel(String channel)
|
||||
{
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* /** Sets a comment.
|
||||
*
|
||||
* @param index The comment's index.
|
||||
* @param comment The actual comment.
|
||||
* @param nick The nickname of the author of the comment.
|
||||
*/
|
||||
public final synchronized void setComment(int index, String comment, String nick)
|
||||
{
|
||||
if (index < _comments.size())
|
||||
{
|
||||
_comments.set(index, new EntryComment(comment, nick));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment's link.
|
||||
*
|
||||
* @param link The new link.
|
||||
*/
|
||||
public final synchronized void setLink(String link)
|
||||
{
|
||||
_link = link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment's author login.
|
||||
*
|
||||
* @param login The new login.
|
||||
*/
|
||||
public final synchronized void setLogin(String login)
|
||||
{
|
||||
_login = login;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment's author nickname.
|
||||
*
|
||||
|
@ -358,13 +305,13 @@ public class EntryLink implements Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the tags.
|
||||
* Returns the tags.
|
||||
*
|
||||
* @param tags The tags.
|
||||
* @return The tags.
|
||||
*/
|
||||
public final synchronized void setTags(List tags)
|
||||
public final synchronized List getTags()
|
||||
{
|
||||
_tags.addAll(tags);
|
||||
return _tags;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -422,6 +369,16 @@ public class EntryLink implements Serializable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment's title.
|
||||
*
|
||||
* @return The title.
|
||||
*/
|
||||
public final synchronized String getTitle()
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment's title.
|
||||
*
|
||||
|
@ -432,6 +389,51 @@ public class EntryLink implements Serializable
|
|||
_title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entry has comments.
|
||||
*
|
||||
* @return true if there are comments, false otherwise.
|
||||
*/
|
||||
public final synchronized boolean hasComments()
|
||||
{
|
||||
return (!_comments.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entry has tags.
|
||||
*
|
||||
* @return true if there are tags, false otherwise.
|
||||
*/
|
||||
public final synchronized boolean hasTags()
|
||||
{
|
||||
return (!_tags.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* /** Sets a comment.
|
||||
*
|
||||
* @param index The comment's index.
|
||||
* @param comment The actual comment.
|
||||
* @param nick The nickname of the author of the comment.
|
||||
*/
|
||||
public final synchronized void setComment(int index, String comment, String nick)
|
||||
{
|
||||
if (index < _comments.size())
|
||||
{
|
||||
_comments.set(index, new EntryComment(comment, nick));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tags.
|
||||
*
|
||||
* @param tags The tags.
|
||||
*/
|
||||
public final synchronized void setTags(List tags)
|
||||
{
|
||||
_tags.addAll(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
*
|
||||
|
@ -439,17 +441,9 @@ public class EntryLink implements Serializable
|
|||
*/
|
||||
public final String toString()
|
||||
{
|
||||
final StringBuffer sb = new StringBuffer(super.toString());
|
||||
sb.append("[ channel -> '").append(_channel).append('\'');
|
||||
sb.append(", comments -> ").append(_comments);
|
||||
sb.append(", date -> ").append(_date);
|
||||
sb.append(", link -> '").append(_link).append('\'');
|
||||
sb.append(", login -> '").append(_login).append('\'');
|
||||
sb.append(", nick -> '").append(_nick).append('\'');
|
||||
sb.append(", tags -> ").append(_tags);
|
||||
sb.append(", title -> '").append(_title).append('\'');
|
||||
sb.append(" ]");
|
||||
|
||||
return sb.toString();
|
||||
return super.toString() + "[ channel -> '" + _channel + '\'' + ", comments -> " + _comments + ", date -> "
|
||||
+ _date + ", link -> '" + _link + '\'' + ", login -> '" + _login + '\'' + ", nick -> '" + _nick + '\''
|
||||
+ ", tags -> " + _tags + ", title -> '" + _title + '\'' + " ]";
|
||||
}
|
||||
}
|
|
@ -44,16 +44,13 @@ import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Reads a RSS feed.
|
||||
*
|
||||
* @author Erik C. Thauvin
|
||||
* @version $Revision$, $Date$
|
||||
*
|
||||
* @created Feb 1, 2004
|
||||
* @since 1.0
|
||||
*/
|
|
@ -36,8 +36,9 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import twitter4j.internal.org.json.JSONArray;
|
||||
import twitter4j.internal.org.json.JSONObject;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
|
||||
/* Creation date Wed Jun 12 14:18:56 PDT 2013 */
|
||||
/* Creation date Sat Apr 19 21:14:33 PDT 2014 */
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -20,23 +20,16 @@ public class ReleaseInfo {
|
|||
}
|
||||
|
||||
|
||||
/** buildDate (set during build process to 1371071936682L). */
|
||||
private static final Date buildDate = new Date(1371071936682L);
|
||||
/** buildDate (set during build process to 1397967273141L). */
|
||||
private static final Date buildDate = new Date(1397967273141L);
|
||||
|
||||
/**
|
||||
* Get buildDate (set during build process to Wed Jun 12 14:18:56 PDT 2013).
|
||||
* Get buildDate (set during build process to Sat Apr 19 21:14:33 PDT 2014).
|
||||
* @return Date buildDate
|
||||
*/
|
||||
public static Date getBuildDate() { return buildDate; }
|
||||
|
||||
|
||||
/**
|
||||
* Get buildNumber (set during build process to 10).
|
||||
* @return int buildNumber
|
||||
*/
|
||||
public static int getBuildNumber() { return 10; }
|
||||
|
||||
|
||||
/** project (set during build process to "mobibot"). */
|
||||
private static final String project = "mobibot";
|
||||
|
||||
|
@ -56,4 +49,11 @@ public class ReleaseInfo {
|
|||
*/
|
||||
public static String getVersion() { return version; }
|
||||
|
||||
|
||||
/**
|
||||
* Get buildNumber (set during build process to 40).
|
||||
* @return int buildNumber
|
||||
*/
|
||||
public static int getBuildNumber() { return 40; }
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@ import javax.swing.SwingUtilities;
|
|||
* Note that the API changed slightly in the 3rd version:
|
||||
* You must now invoke start() on the SwingWorker after
|
||||
* creating it.
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public abstract class SwingWorker {
|
||||
private Object value; // see getValue(), setValue()
|
|
@ -122,12 +122,8 @@ public class Twitter implements Runnable
|
|||
|
||||
_bot.send(_sender,
|
||||
"You message was posted to http://twitter.com/" + twitter.getScreenName() + "/statuses/" + status
|
||||
.getId());
|
||||
|
||||
twitter.shutdown();
|
||||
|
||||
// @TODO Does it help?
|
||||
twitter4j.internal.json.DataObjectFactoryUtil.clearThreadLocalMap();
|
||||
.getId()
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
|
@ -56,7 +56,8 @@ public class TwitterOAuth
|
|||
System.out.println(
|
||||
"Please add the following to the bot's property file:" + "\n\n" + "twitter-consumerKey="
|
||||
+ args[0] + '\n' + "twitter-consumerSecret=" + args[1] + '\n' + "twitter-token="
|
||||
+ accessToken.getToken() + '\n' + "twitter-tokenSecret=" + accessToken.getTokenSecret());
|
||||
+ accessToken.getToken() + '\n' + "twitter-tokenSecret=" + accessToken.getTokenSecret()
|
||||
);
|
||||
}
|
||||
catch (TwitterException te)
|
||||
{
|
|
@ -116,9 +116,10 @@ public class Weather implements Runnable
|
|||
_bot.send(_sender, "Station ID: " + metar.getStationID(), _isPrivate);
|
||||
|
||||
_bot.send(_sender,
|
||||
"At: " + metar.getDateString() + " UTC ("
|
||||
+ (((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L) + " minutes ago)",
|
||||
_isPrivate);
|
||||
"At: " + metar.getDateString() + " UTC (" + (
|
||||
((new Date()).getTime() - metar.getDate().getTime()) / 1000L / 60L) + " minutes ago)",
|
||||
_isPrivate
|
||||
);
|
||||
|
||||
result = metar.getWindSpeedInMPH();
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* @(#)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 org.json.XML;
|
||||
import twitter4j.internal.http.BASE64Encoder;
|
||||
import org.json.JSONObject;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue