Created tell and entries packages and Constants class.
This commit is contained in:
parent
7cede1d560
commit
474a31bdee
12 changed files with 259 additions and 116 deletions
|
@ -4,7 +4,11 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
|
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
|
||||||
<Match>
|
<Match>
|
||||||
<Package name="net.thauvin.erik.mobibot.*"/>
|
<Or>
|
||||||
|
<Package name="net.thauvin.erik.mobibot.*"/>
|
||||||
|
<Package name="net.thauvin.erik.mobibot.tell.*"/>
|
||||||
|
<Package name="net.thauvin.erik.mobibot.entries.*"/>
|
||||||
|
</Or>
|
||||||
<Or>
|
<Or>
|
||||||
<Bug pattern="PATH_TRAVERSAL_IN"/>
|
<Bug pattern="PATH_TRAVERSAL_IN"/>
|
||||||
<Bug pattern="PATH_TRAVERSAL_OUT"/>
|
<Bug pattern="PATH_TRAVERSAL_OUT"/>
|
||||||
|
|
59
src/main/java/net/thauvin/erik/mobibot/Constants.java
Normal file
59
src/main/java/net/thauvin/erik/mobibot/Constants.java
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Constants.java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||||
|
* 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 this project 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 HOLDER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.thauvin.erik.mobibot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <code>Constants</code> class.
|
||||||
|
*
|
||||||
|
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||||
|
* @created 2019-04-19
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public final class Constants {
|
||||||
|
/**
|
||||||
|
* The empty title string.
|
||||||
|
*/
|
||||||
|
public static final String NO_TITLE = "No Title";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Twitter handle property key.
|
||||||
|
*/
|
||||||
|
public static final String TWITTER_HANDLE_PROP = "twitter-handle";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the default constructor.
|
||||||
|
*/
|
||||||
|
private Constants() {
|
||||||
|
throw new UnsupportedOperationException("Illegal constructor call.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,10 @@ package net.thauvin.erik.mobibot;
|
||||||
|
|
||||||
import com.rometools.rome.io.FeedException;
|
import com.rometools.rome.io.FeedException;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
import net.thauvin.erik.mobibot.entries.EntriesMgr;
|
||||||
|
import net.thauvin.erik.mobibot.entries.EntriesUtils;
|
||||||
|
import net.thauvin.erik.mobibot.entries.EntryComment;
|
||||||
|
import net.thauvin.erik.mobibot.entries.EntryLink;
|
||||||
import net.thauvin.erik.mobibot.modules.AbstractModule;
|
import net.thauvin.erik.mobibot.modules.AbstractModule;
|
||||||
import net.thauvin.erik.mobibot.modules.Calc;
|
import net.thauvin.erik.mobibot.modules.Calc;
|
||||||
import net.thauvin.erik.mobibot.modules.CurrencyConverter;
|
import net.thauvin.erik.mobibot.modules.CurrencyConverter;
|
||||||
|
@ -41,6 +45,7 @@ import net.thauvin.erik.mobibot.modules.Dice;
|
||||||
import net.thauvin.erik.mobibot.modules.GoogleSearch;
|
import net.thauvin.erik.mobibot.modules.GoogleSearch;
|
||||||
import net.thauvin.erik.mobibot.modules.Joke;
|
import net.thauvin.erik.mobibot.modules.Joke;
|
||||||
import net.thauvin.erik.mobibot.modules.Lookup;
|
import net.thauvin.erik.mobibot.modules.Lookup;
|
||||||
|
import net.thauvin.erik.mobibot.modules.ModuleException;
|
||||||
import net.thauvin.erik.mobibot.modules.Ping;
|
import net.thauvin.erik.mobibot.modules.Ping;
|
||||||
import net.thauvin.erik.mobibot.modules.StockQuote;
|
import net.thauvin.erik.mobibot.modules.StockQuote;
|
||||||
import net.thauvin.erik.mobibot.modules.Twitter;
|
import net.thauvin.erik.mobibot.modules.Twitter;
|
||||||
|
@ -48,6 +53,7 @@ import net.thauvin.erik.mobibot.modules.War;
|
||||||
import net.thauvin.erik.mobibot.modules.Weather2;
|
import net.thauvin.erik.mobibot.modules.Weather2;
|
||||||
import net.thauvin.erik.mobibot.modules.WorldTime;
|
import net.thauvin.erik.mobibot.modules.WorldTime;
|
||||||
import net.thauvin.erik.mobibot.msg.Message;
|
import net.thauvin.erik.mobibot.msg.Message;
|
||||||
|
import net.thauvin.erik.mobibot.tell.Tell;
|
||||||
import net.thauvin.erik.semver.Version;
|
import net.thauvin.erik.semver.Version;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
|
@ -96,9 +102,6 @@ public class Mobibot extends PircBot {
|
||||||
*/
|
*/
|
||||||
public static final int CONNECT_TIMEOUT = 5000;
|
public static final int CONNECT_TIMEOUT = 5000;
|
||||||
|
|
||||||
// The empty title string.
|
|
||||||
static final String NO_TITLE = "No Title";
|
|
||||||
|
|
||||||
// The default port.
|
// The default port.
|
||||||
private static final int DEFAULT_PORT = 6667;
|
private static final int DEFAULT_PORT = 6667;
|
||||||
|
|
||||||
|
@ -186,6 +189,10 @@ public class Mobibot extends PircBot {
|
||||||
private final List<String> recap = new ArrayList<>(0);
|
private final List<String> recap = new ArrayList<>(0);
|
||||||
// The tell object.
|
// The tell object.
|
||||||
private final Tell tell;
|
private final Tell tell;
|
||||||
|
// The Twitter handle for channel join notifications.
|
||||||
|
private final String twitterHandle;
|
||||||
|
// The Twitter module.
|
||||||
|
private final Twitter twitterModule;
|
||||||
// The backlogs URL.
|
// The backlogs URL.
|
||||||
private String backLogsUrl = "";
|
private String backLogsUrl = "";
|
||||||
// The default tags/categories.
|
// The default tags/categories.
|
||||||
|
@ -202,7 +209,6 @@ public class Mobibot extends PircBot {
|
||||||
private Pinboard pinboard = null;
|
private Pinboard pinboard = null;
|
||||||
// Today's date.
|
// Today's date.
|
||||||
private String today = Utils.today();
|
private String today = Utils.today();
|
||||||
|
|
||||||
// The weblog URL.
|
// The weblog URL.
|
||||||
private String weblogUrl = "";
|
private String weblogUrl = "";
|
||||||
|
|
||||||
|
@ -943,14 +949,6 @@ public class Mobibot extends PircBot {
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onJoin(final String channel, final String sender, final String login, final String hostname) {
|
|
||||||
tell.send(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -988,7 +986,7 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder tags = new StringBuilder(defaultTags);
|
final StringBuilder tags = new StringBuilder(defaultTags);
|
||||||
String title = NO_TITLE;
|
String title = Constants.NO_TITLE;
|
||||||
|
|
||||||
if (cmds.length == 2) {
|
if (cmds.length == 2) {
|
||||||
final String[] data = cmds[1].trim().split(TAGS_MARKER, 2);
|
final String[] data = cmds[1].trim().split(TAGS_MARKER, 2);
|
||||||
|
@ -1004,7 +1002,7 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NO_TITLE.equals(title)) {
|
if (Constants.NO_TITLE.equals(title)) {
|
||||||
try {
|
try {
|
||||||
final Document html = Jsoup.connect(link).userAgent("Mozilla").get();
|
final Document html = Jsoup.connect(link).userAgent("Mozilla").get();
|
||||||
final String htmlTitle = html.title();
|
final String htmlTitle = html.title();
|
||||||
|
@ -1021,7 +1019,7 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
final int index = entries.size() - 1;
|
final int index = entries.size() - 1;
|
||||||
final EntryLink entry = entries.get(index);
|
final EntryLink entry = entries.get(index);
|
||||||
send(channel, Utils.buildLink(index, entry));
|
send(channel, EntriesUtils.buildLink(index, entry));
|
||||||
|
|
||||||
if (pinboard != null) {
|
if (pinboard != null) {
|
||||||
pinboard.addPost(entry);
|
pinboard.addPost(entry);
|
||||||
|
@ -1029,13 +1027,14 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
saveEntries(isBackup);
|
saveEntries(isBackup);
|
||||||
|
|
||||||
if (NO_TITLE.equals(entry.getTitle())) {
|
if (Constants.NO_TITLE.equals(entry.getTitle())) {
|
||||||
send(sender, "Please specify a title, by typing:", true);
|
send(sender, "Please specify a title, by typing:", true);
|
||||||
send(sender, helpIndent(Commands.LINK_CMD + (index + 1) + ":|This is the title"), true);
|
send(sender, helpIndent(Commands.LINK_CMD + (index + 1) + ":|This is the title"), true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final EntryLink entry = entries.get(dupIndex);
|
final EntryLink entry = entries.get(dupIndex);
|
||||||
send(sender, Utils.bold("Duplicate") + " >> " + Utils.buildLink(dupIndex, entry));
|
send(sender, Utils.bold("Duplicate") + " >> "
|
||||||
|
+ EntriesUtils.buildLink(dupIndex, entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.matches(getNickPattern() + ":.*")) { // mobibot: <command>
|
} else if (message.matches(getNickPattern() + ":.*")) { // mobibot: <command>
|
||||||
|
@ -1090,17 +1089,17 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
if (cmd.length() == 0) {
|
if (cmd.length() == 0) {
|
||||||
final EntryLink entry = entries.get(index);
|
final EntryLink entry = entries.get(index);
|
||||||
send(channel, Utils.buildLink(index, entry));
|
send(channel, EntriesUtils.buildLink(index, entry));
|
||||||
|
|
||||||
if (entry.hasTags()) {
|
if (entry.hasTags()) {
|
||||||
send(channel, Utils.buildTags(index, entry));
|
send(channel, EntriesUtils.buildTags(index, entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.hasComments()) {
|
if (entry.hasComments()) {
|
||||||
final EntryComment[] comments = entry.getComments();
|
final EntryComment[] comments = entry.getComments();
|
||||||
|
|
||||||
for (int i = 0; i < comments.length; i++) {
|
for (int i = 0; i < comments.length; i++) {
|
||||||
send(channel, Utils.buildComment(index, i, comments[i]));
|
send(channel, EntriesUtils.buildComment(index, i, comments[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1128,7 +1127,7 @@ public class Mobibot extends PircBot {
|
||||||
pinboard.updatePost(entry.getLink(), entry);
|
pinboard.updatePost(entry.getLink(), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(channel, Utils.buildLink(index, entry));
|
send(channel, EntriesUtils.buildLink(index, entry));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
} else if (cmd.charAt(0) == '=') { // L1:=<url>
|
} else if (cmd.charAt(0) == '=') { // L1:=<url>
|
||||||
|
@ -1146,7 +1145,7 @@ public class Mobibot extends PircBot {
|
||||||
pinboard.updatePost(oldLink, entry);
|
pinboard.updatePost(oldLink, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(channel, Utils.buildLink(index, entry));
|
send(channel, EntriesUtils.buildLink(index, entry));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1157,7 +1156,7 @@ public class Mobibot extends PircBot {
|
||||||
if (cmd.length() > 1) {
|
if (cmd.length() > 1) {
|
||||||
final EntryLink entry = entries.get(index);
|
final EntryLink entry = entries.get(index);
|
||||||
entry.setNick(cmd.substring(1));
|
entry.setNick(cmd.substring(1));
|
||||||
send(channel, Utils.buildLink(index, entry));
|
send(channel, EntriesUtils.buildLink(index, entry));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1168,7 +1167,7 @@ public class Mobibot extends PircBot {
|
||||||
final int cindex = entry.addComment(cmd, sender);
|
final int cindex = entry.addComment(cmd, sender);
|
||||||
|
|
||||||
final EntryComment comment = entry.getComment(cindex);
|
final EntryComment comment = entry.getComment(cindex);
|
||||||
send(sender, Utils.buildComment(index, cindex, comment));
|
send(sender, EntriesUtils.buildComment(index, cindex, comment));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1192,14 +1191,14 @@ public class Mobibot extends PircBot {
|
||||||
pinboard.updatePost(entry.getLink(), entry);
|
pinboard.updatePost(entry.getLink(), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(channel, Utils.buildTags(index, entry));
|
send(channel, EntriesUtils.buildTags(index, entry));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
} else {
|
} else {
|
||||||
send(sender, "Please ask a channel op to change the tags for you.");
|
send(sender, "Please ask a channel op to change the tags for you.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (entry.hasTags()) {
|
if (entry.hasTags()) {
|
||||||
send(channel, Utils.buildTags(index, entry));
|
send(channel, EntriesUtils.buildTags(index, entry));
|
||||||
} else {
|
} else {
|
||||||
send(sender, "The entry has no tags. Why don't add some?");
|
send(sender, "The entry has no tags. Why don't add some?");
|
||||||
}
|
}
|
||||||
|
@ -1221,7 +1220,7 @@ public class Mobibot extends PircBot {
|
||||||
// L1.1:
|
// L1.1:
|
||||||
if (cmd.length() == 0) {
|
if (cmd.length() == 0) {
|
||||||
final EntryComment comment = entry.getComment(cindex);
|
final EntryComment comment = entry.getComment(cindex);
|
||||||
send(channel, Utils.buildComment(index, cindex, comment));
|
send(channel, EntriesUtils.buildComment(index, cindex, comment));
|
||||||
} else if ("-".equals(cmd)) { // L1.1:-
|
} else if ("-".equals(cmd)) { // L1.1:-
|
||||||
entry.deleteComment(cindex);
|
entry.deleteComment(cindex);
|
||||||
send(channel, "Comment " + Commands.LINK_CMD + (index + 1) + '.' + (cindex + 1) + " removed.");
|
send(channel, "Comment " + Commands.LINK_CMD + (index + 1) + '.' + (cindex + 1) + " removed.");
|
||||||
|
@ -1231,7 +1230,7 @@ public class Mobibot extends PircBot {
|
||||||
if (cmd.length() > 1) {
|
if (cmd.length() > 1) {
|
||||||
final EntryComment comment = entry.getComment(cindex);
|
final EntryComment comment = entry.getComment(cindex);
|
||||||
comment.setNick(cmd.substring(1));
|
comment.setNick(cmd.substring(1));
|
||||||
send(channel, Utils.buildComment(index, cindex, comment));
|
send(channel, EntriesUtils.buildComment(index, cindex, comment));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1241,7 +1240,7 @@ public class Mobibot extends PircBot {
|
||||||
entry.setComment(cindex, cmd, sender);
|
entry.setComment(cindex, cmd, sender);
|
||||||
|
|
||||||
final EntryComment comment = entry.getComment(cindex);
|
final EntryComment comment = entry.getComment(cindex);
|
||||||
send(sender, Utils.buildComment(index, cindex, comment));
|
send(sender, EntriesUtils.buildComment(index, cindex, comment));
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1255,14 +1254,6 @@ public class Mobibot extends PircBot {
|
||||||
tell.send(sender, true);
|
tell.send(sender, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onNickChange(final String oldNick, final String login, final String hostname, final String newNick) {
|
|
||||||
tell.send(newNick);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -1373,6 +1364,36 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected final void onAction(final String sender,
|
||||||
|
final String login,
|
||||||
|
final String hostname,
|
||||||
|
final String target,
|
||||||
|
final String action) {
|
||||||
|
if (target.equals(ircChannel)) {
|
||||||
|
storeRecap(sender, action, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onJoin(final String channel, final String sender, final String login, final String hostname) {
|
||||||
|
tell.send(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onNickChange(final String oldNick, final String login, final String hostname, final String newNick) {
|
||||||
|
tell.send(newNick);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds with the last 10 public messages.
|
* Responds with the last 10 public messages.
|
||||||
*
|
*
|
||||||
|
@ -1657,7 +1678,7 @@ public class Mobibot extends PircBot {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
send(sender, Utils.buildLink(i, entry, true), isPrivate);
|
send(sender, EntriesUtils.buildLink(i, entry, true), isPrivate);
|
||||||
sent++;
|
sent++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1670,7 +1691,7 @@ public class Mobibot extends PircBot {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
send(sender, Utils.buildLink(i, entry, true), isPrivate);
|
send(sender, EntriesUtils.buildLink(i, entry, true), isPrivate);
|
||||||
sent++;
|
sent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot;
|
||||||
|
|
||||||
|
import net.thauvin.erik.mobibot.entries.EntryLink;
|
||||||
import net.thauvin.erik.pinboard.PinboardPoster;
|
import net.thauvin.erik.pinboard.PinboardPoster;
|
||||||
|
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
|
|
@ -74,73 +74,7 @@ public final class Utils {
|
||||||
* @return The bold string.
|
* @return The bold string.
|
||||||
*/
|
*/
|
||||||
public static String bold(final String s) {
|
public static String bold(final String s) {
|
||||||
return colorize(s, Colors.BOLD);
|
return colorize(s, Colors.BOLD);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds an entry's comment for display on the channel.
|
|
||||||
*
|
|
||||||
* @param entryIndex The entry's index.
|
|
||||||
* @param commentIndex The comment's index.
|
|
||||||
* @param comment The {@link net.thauvin.erik.mobibot.EntryComment comment} object.
|
|
||||||
* @return The entry's comment.
|
|
||||||
*/
|
|
||||||
static String buildComment(final int entryIndex, final int commentIndex, final EntryComment comment) {
|
|
||||||
return (Commands.LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] "
|
|
||||||
+ comment.getComment());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds an entry's link for display on the channel.
|
|
||||||
*
|
|
||||||
* @param index The entry's index.
|
|
||||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
|
||||||
* @return The entry's link.
|
|
||||||
* @see #buildLink(int, net.thauvin.erik.mobibot.EntryLink, boolean)
|
|
||||||
*/
|
|
||||||
static String buildLink(final int index, final EntryLink entry) {
|
|
||||||
return buildLink(index, entry, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds an entry's link for display on the channel.
|
|
||||||
*
|
|
||||||
* @param index The entry's index.
|
|
||||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
|
||||||
* @param isView Set to true to display the number of comments.
|
|
||||||
* @return The entry's link.
|
|
||||||
*/
|
|
||||||
static String buildLink(final int index, final EntryLink entry, final boolean isView) {
|
|
||||||
final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": ");
|
|
||||||
|
|
||||||
buff.append('[').append(entry.getNick()).append(']');
|
|
||||||
|
|
||||||
if (isView && entry.hasComments()) {
|
|
||||||
buff.append("[+").append(entry.getCommentsCount()).append(']');
|
|
||||||
}
|
|
||||||
|
|
||||||
buff.append(' ');
|
|
||||||
|
|
||||||
if (Mobibot.NO_TITLE.equals(entry.getTitle())) {
|
|
||||||
buff.append(entry.getTitle());
|
|
||||||
} else {
|
|
||||||
buff.append(bold(entry.getTitle()));
|
|
||||||
}
|
|
||||||
|
|
||||||
buff.append(" ( ").append(Utils.green(entry.getLink())).append(" )");
|
|
||||||
|
|
||||||
return buff.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build an entry's tags/categories for display on the channel.
|
|
||||||
*
|
|
||||||
* @param entryIndex The entry's index.
|
|
||||||
* @param entry The {@link net.thauvin.erik.mobibot.EntryLink entry} object.
|
|
||||||
* @return The entry's tags.
|
|
||||||
*/
|
|
||||||
static String buildTags(final int entryIndex, final EntryLink entry) {
|
|
||||||
return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getPinboardTags().replaceAll(",", ", "));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.entries;
|
||||||
|
|
||||||
import com.rometools.rome.feed.synd.SyndContent;
|
import com.rometools.rome.feed.synd.SyndContent;
|
||||||
import com.rometools.rome.feed.synd.SyndContentImpl;
|
import com.rometools.rome.feed.synd.SyndContentImpl;
|
||||||
|
@ -41,6 +41,8 @@ import com.rometools.rome.feed.synd.SyndFeedImpl;
|
||||||
import com.rometools.rome.io.FeedException;
|
import com.rometools.rome.io.FeedException;
|
||||||
import com.rometools.rome.io.SyndFeedInput;
|
import com.rometools.rome.io.SyndFeedInput;
|
||||||
import com.rometools.rome.io.SyndFeedOutput;
|
import com.rometools.rome.io.SyndFeedOutput;
|
||||||
|
import net.thauvin.erik.mobibot.Mobibot;
|
||||||
|
import net.thauvin.erik.mobibot.Utils;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -60,7 +62,7 @@ import java.util.List;
|
||||||
* @created 2014-04-28
|
* @created 2014-04-28
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
final class EntriesMgr {
|
public final class EntriesMgr {
|
||||||
/**
|
/**
|
||||||
* The name of the file containing the current entries.
|
* The name of the file containing the current entries.
|
||||||
*/
|
*/
|
118
src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.java
Normal file
118
src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.java
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* EntriesUtils.java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||||
|
* 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 this project 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 HOLDER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.thauvin.erik.mobibot.entries;
|
||||||
|
|
||||||
|
import net.thauvin.erik.mobibot.Commands;
|
||||||
|
import net.thauvin.erik.mobibot.Constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <code>Utils</code> class.
|
||||||
|
*
|
||||||
|
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||||
|
* @created 2019-04-19
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public final class EntriesUtils {
|
||||||
|
/**
|
||||||
|
* Disables the default constructor.
|
||||||
|
*/
|
||||||
|
private EntriesUtils() {
|
||||||
|
throw new UnsupportedOperationException("Illegal constructor call.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an entry's comment for display on the channel.
|
||||||
|
*
|
||||||
|
* @param entryIndex The entry's index.
|
||||||
|
* @param commentIndex The comment's index.
|
||||||
|
* @param comment The {@link EntryComment comment} object.
|
||||||
|
* @return The entry's comment.
|
||||||
|
*/
|
||||||
|
public static String buildComment(final int entryIndex, final int commentIndex, final EntryComment comment) {
|
||||||
|
return (Commands.LINK_CMD + (entryIndex + 1) + '.' + (commentIndex + 1) + ": [" + comment.getNick() + "] "
|
||||||
|
+ comment.getComment());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an entry's link for display on the channel.
|
||||||
|
*
|
||||||
|
* @param index The entry's index.
|
||||||
|
* @param entry The {@link EntryLink entry} object.
|
||||||
|
* @return The entry's link.
|
||||||
|
* @see #buildLink(int, EntryLink, boolean)
|
||||||
|
*/
|
||||||
|
public static String buildLink(final int index, final EntryLink entry) {
|
||||||
|
return buildLink(index, entry, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an entry's link for display on the channel.
|
||||||
|
*
|
||||||
|
* @param index The entry's index.
|
||||||
|
* @param entry The {@link EntryLink entry} object.
|
||||||
|
* @param isView Set to true to display the number of comments.
|
||||||
|
* @return The entry's link.
|
||||||
|
*/
|
||||||
|
public static String buildLink(final int index, final EntryLink entry, final boolean isView) {
|
||||||
|
final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": ");
|
||||||
|
|
||||||
|
buff.append('[').append(entry.getNick()).append(']');
|
||||||
|
|
||||||
|
if (isView && entry.hasComments()) {
|
||||||
|
buff.append("[+").append(entry.getCommentsCount()).append(']');
|
||||||
|
}
|
||||||
|
|
||||||
|
buff.append(' ');
|
||||||
|
|
||||||
|
if (Constants.NO_TITLE.equals(entry.getTitle())) {
|
||||||
|
buff.append(entry.getTitle());
|
||||||
|
} else {
|
||||||
|
buff.append(net.thauvin.erik.mobibot.Utils.bold(entry.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
buff.append(" ( ").append(net.thauvin.erik.mobibot.Utils.green(entry.getLink())).append(" )");
|
||||||
|
|
||||||
|
return buff.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an entry's tags/categories for display on the channel.
|
||||||
|
*
|
||||||
|
* @param entryIndex The entry's index.
|
||||||
|
* @param entry The {@link EntryLink entry} object.
|
||||||
|
* @return The entry's tags.
|
||||||
|
*/
|
||||||
|
public static String buildTags(final int entryIndex, final EntryLink entry) {
|
||||||
|
return (Commands.LINK_CMD + (entryIndex + 1) + "T: " + entry.getPinboardTags().replaceAll(",", ", "));
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,7 +30,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.entries;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
|
@ -30,7 +30,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.entries;
|
||||||
|
|
||||||
import com.rometools.rome.feed.synd.SyndCategory;
|
import com.rometools.rome.feed.synd.SyndCategory;
|
||||||
import com.rometools.rome.feed.synd.SyndCategoryImpl;
|
import com.rometools.rome.feed.synd.SyndCategoryImpl;
|
|
@ -30,7 +30,11 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.tell;
|
||||||
|
|
||||||
|
import net.thauvin.erik.mobibot.Commands;
|
||||||
|
import net.thauvin.erik.mobibot.Mobibot;
|
||||||
|
import net.thauvin.erik.mobibot.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
@ -30,7 +30,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.tell;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
|
@ -30,7 +30,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot;
|
package net.thauvin.erik.mobibot.tell;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ final class TellMessagesMgr {
|
||||||
*
|
*
|
||||||
* @param file The serialized objects file.
|
* @param file The serialized objects file.
|
||||||
* @param logger The logger.
|
* @param logger The logger.
|
||||||
* @return The {@link net.thauvin.erik.mobibot.TellMessage} array.
|
* @return The {@link TellMessage} array.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<TellMessage> load(final String file, final Logger logger) {
|
public static List<TellMessage> load(final String file, final Logger logger) {
|
||||||
|
@ -121,7 +121,7 @@ final class TellMessagesMgr {
|
||||||
* Saves the messages.
|
* Saves the messages.
|
||||||
*
|
*
|
||||||
* @param file The serialized objects file.
|
* @param file The serialized objects file.
|
||||||
* @param messages The {@link net.thauvin.erik.mobibot.TellMessage} array.
|
* @param messages The {@link TellMessage} array.
|
||||||
* @param logger The logger.
|
* @param logger The logger.
|
||||||
*/
|
*/
|
||||||
public static void save(final String file, final List<TellMessage> messages, final Logger logger) {
|
public static void save(final String file, final List<TellMessage> messages, final Logger logger) {
|
Loading…
Add table
Add a link
Reference in a new issue