Renamed UrlMgr to LinksMgr.
This commit is contained in:
parent
725937bf61
commit
8bc04b0940
12 changed files with 50 additions and 69 deletions
|
@ -48,9 +48,9 @@ import net.thauvin.erik.mobibot.commands.Say;
|
|||
import net.thauvin.erik.mobibot.commands.Users;
|
||||
import net.thauvin.erik.mobibot.commands.Versions;
|
||||
import net.thauvin.erik.mobibot.commands.links.Comment;
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
|
||||
import net.thauvin.erik.mobibot.commands.links.Posting;
|
||||
import net.thauvin.erik.mobibot.commands.links.Tags;
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr;
|
||||
import net.thauvin.erik.mobibot.commands.links.View;
|
||||
import net.thauvin.erik.mobibot.commands.tell.Tell;
|
||||
import net.thauvin.erik.mobibot.entries.EntriesMgr;
|
||||
|
@ -96,6 +96,7 @@ import java.nio.file.Paths;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.lowerCase;
|
||||
|
@ -184,8 +185,8 @@ public class Mobibot extends PircBot {
|
|||
|
||||
// Load the current entries and backlogs, if any
|
||||
try {
|
||||
UrlMgr.startup(logsDir + EntriesMgr.CURRENT_XML, logsDir + EntriesMgr.NAV_XML, ircChannel);
|
||||
LOGGER.debug("Last feed: {}", UrlMgr.getStartDate());
|
||||
LinksMgr.startup(logsDir + EntriesMgr.CURRENT_XML, logsDir + EntriesMgr.NAV_XML, ircChannel);
|
||||
LOGGER.debug("Last feed: {}", LinksMgr.getStartDate());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("An error occurred while loading the logs.", e);
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ public class Mobibot extends PircBot {
|
|||
addons.add(new Comment(this), p);
|
||||
addons.add(new Posting(this), p);
|
||||
addons.add(new Tags(this), p);
|
||||
addons.add(new UrlMgr(this), p);
|
||||
addons.add(new LinksMgr(this), p);
|
||||
addons.add(new View(this), p);
|
||||
|
||||
// Load the modules
|
||||
|
@ -253,7 +254,7 @@ public class Mobibot extends PircBot {
|
|||
addons.sort();
|
||||
|
||||
// Save the entries
|
||||
UrlMgr.saveEntries(this, true);
|
||||
LinksMgr.saveEntries(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,20 +287,20 @@ public class Mobibot extends PircBot {
|
|||
|
||||
// Parse the command line
|
||||
final CommandLineParser parser = new DefaultParser();
|
||||
CommandLine line = null;
|
||||
CommandLine commandLine = null;
|
||||
|
||||
try {
|
||||
line = parser.parse(options, args);
|
||||
commandLine = parser.parse(options, args);
|
||||
} catch (ParseException e) {
|
||||
System.err.println("CLI Parsing failed. Reason: " + e.getMessage());
|
||||
e.printStackTrace(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (line.hasOption(Constants.HELP_ARG.charAt(0))) {
|
||||
if (commandLine.hasOption(Constants.HELP_ARG.charAt(0))) {
|
||||
// Output the usage
|
||||
new HelpFormatter().printHelp(Mobibot.class.getName(), options);
|
||||
} else if (line.hasOption(Constants.VERSION_ARG.charAt(0))) {
|
||||
} else if (commandLine.hasOption(Constants.VERSION_ARG.charAt(0))) {
|
||||
for (final String s : INFO) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
@ -307,7 +308,7 @@ public class Mobibot extends PircBot {
|
|||
final Properties p = new Properties();
|
||||
|
||||
try (final InputStream fis = Files.newInputStream(
|
||||
Paths.get(line.getOptionValue(Constants.PROPS_ARG.charAt(0), "./mobibot.properties")))) {
|
||||
Paths.get(commandLine.getOptionValue(Constants.PROPS_ARG.charAt(0), "./mobibot.properties")))) {
|
||||
// Load the properties files
|
||||
p.load(fis);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -325,7 +326,7 @@ public class Mobibot extends PircBot {
|
|||
final String logsDir = Utils.ensureDir(p.getProperty("logs", "."), false);
|
||||
|
||||
// Redirect the stdout and stderr
|
||||
if (!line.hasOption(Constants.DEBUG_ARG.charAt(0))) {
|
||||
if (!commandLine.hasOption(Constants.DEBUG_ARG.charAt(0))) {
|
||||
try {
|
||||
final PrintStream stdout = new PrintStream(
|
||||
new FileOutputStream(logsDir + channel.substring(1) + '.' + Utils.today() + ".log", true));
|
||||
|
@ -493,26 +494,6 @@ public class Mobibot extends PircBot {
|
|||
return addons.getModulesNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bot's nickname regexp pattern.
|
||||
*
|
||||
* @return The nickname regexp pattern.
|
||||
*/
|
||||
private String getNickPattern() {
|
||||
final StringBuilder buff = new StringBuilder(0);
|
||||
|
||||
for (final char c : getNick().toCharArray()) {
|
||||
if (Character.isLetter(c)) {
|
||||
buff.append('[').append(lowerCase(String.valueOf(c))).append(StringUtils.upperCase(String.valueOf(c)))
|
||||
.append(']');
|
||||
} else {
|
||||
buff.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Tell command.
|
||||
*
|
||||
|
@ -700,7 +681,7 @@ public class Mobibot extends PircBot {
|
|||
|
||||
tell.send(sender, true);
|
||||
|
||||
if (message.matches(getNickPattern() + ":.*")) { // mobibot: <command>
|
||||
if (message.matches("(?i)" + Pattern.quote(getNick()) + ":.*")) { // mobibot: <command>
|
||||
final String[] cmds = message.substring(message.indexOf(':') + 1).trim().split(" ", 2);
|
||||
final String cmd = lowerCase(cmds[0]);
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
package net.thauvin.erik.mobibot.commands
|
||||
|
||||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr.Companion.addHistory
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr.Companion.getHistory
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.addHistory
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.getHistory
|
||||
import net.thauvin.erik.mobibot.entries.EntriesMgr
|
||||
import java.io.File
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ package net.thauvin.erik.mobibot.commands
|
|||
|
||||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr
|
||||
import java.util.*
|
||||
|
||||
class Ignore(bot: Mobibot) : AbstractCommand(bot) {
|
||||
|
@ -150,7 +150,7 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
|
|||
override fun setProperty(key: String, value: String) {
|
||||
super.setProperty(key, value)
|
||||
if (IGNORE_PROP == key) {
|
||||
ignored.addAll(value.split(UrlMgr.LINK_MATCH.toRegex()))
|
||||
ignored.addAll(value.split(LinksMgr.LINK_MATCH.toRegex()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ package net.thauvin.erik.mobibot.commands
|
|||
|
||||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr
|
||||
import java.lang.management.ManagementFactory
|
||||
|
||||
class Info(bot: Mobibot) : AbstractCommand(bot) {
|
||||
|
@ -63,7 +63,7 @@ class Info(bot: Mobibot) : AbstractCommand(bot) {
|
|||
with(info) {
|
||||
append(Utils.uptime(ManagementFactory.getRuntimeMXBean().uptime))
|
||||
append(" [Entries: ")
|
||||
append(UrlMgr.entriesCount)
|
||||
append(LinksMgr.entriesCount)
|
||||
|
||||
if (isOp) {
|
||||
if (bot.tell.isEnabled()) {
|
||||
|
|
|
@ -68,8 +68,8 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
|
|||
val cmds = args.substring(1).split("[.:]".toRegex(), 3)
|
||||
val index = cmds[0].toInt() - 1
|
||||
|
||||
if (index < UrlMgr.entriesCount) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
if (index < LinksMgr.entriesCount) {
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
val commentIndex = cmds[1].toInt() - 1
|
||||
if (commentIndex < entry.commentsCount) {
|
||||
when (val cmd = cmds[2].trim()) {
|
||||
|
@ -124,7 +124,7 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
|
|||
val comment = entry.getComment(commentIndex)
|
||||
comment.nick = cmd.substring(1)
|
||||
bot.send(EntriesUtils.buildComment(index, commentIndex, comment))
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
} else {
|
||||
bot.send(sender, "Please ask a channel op to change the author of this comment for you.", false)
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
|
|||
if (isOp || sender == entry.getComment(commentIndex).nick) {
|
||||
entry.deleteComment(commentIndex)
|
||||
bot.send("Comment ${Constants.LINK_CMD}${index + 1}.${commentIndex + 1} removed.")
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
} else {
|
||||
bot.send(sender, "Please ask a channel op to delete this comment for you.", false)
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
|
|||
entry.setComment(commentIndex, cmd, sender)
|
||||
val comment = entry.getComment(commentIndex)
|
||||
bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment), false)
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
}
|
||||
|
||||
private fun showComment(bot: Mobibot, entry: EntryLink, index: Int, commentIndex: Int) {
|
||||
|
|
|
@ -43,7 +43,7 @@ import net.thauvin.erik.mobibot.entries.EntryLink
|
|||
import org.jsoup.Jsoup
|
||||
import java.io.IOException
|
||||
|
||||
class UrlMgr(bot: Mobibot) : AbstractCommand(bot) {
|
||||
class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
|
||||
private val keywords: MutableList<String> = ArrayList()
|
||||
private val defaultTags: MutableList<String> = ArrayList()
|
||||
|
|
@ -67,7 +67,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
|
|||
val cmds = args.substring(1).split(":", limit = 2)
|
||||
val index = cmds[0].toInt() - 1
|
||||
|
||||
if (index < UrlMgr.entriesCount) {
|
||||
if (index < LinksMgr.entriesCount) {
|
||||
when (val cmd = cmds[1].trim()) {
|
||||
"" -> showEntry(index)
|
||||
"-" -> removeEntry(sender, login, isOp, index) // L1:-
|
||||
|
@ -88,33 +88,33 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
|
|||
}
|
||||
|
||||
private fun addComment(cmd: String, sender: String, index: Int) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
val commentIndex = entry.addComment(cmd, sender)
|
||||
val comment = entry.getComment(commentIndex)
|
||||
bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment), false)
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
}
|
||||
|
||||
private fun changeTitle(cmd: String, index: Int) {
|
||||
if (cmd.length > 1) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
entry.title = cmd.substring(1).trim()
|
||||
bot.updatePin(entry.link, entry)
|
||||
bot.send(EntriesUtils.buildLink(index, entry))
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeUrl(cmd: String, login: String, isOp: Boolean, index: Int) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
if (entry.login == login || isOp) {
|
||||
val link = cmd.substring(1)
|
||||
if (link.matches(UrlMgr.LINK_MATCH.toRegex())) {
|
||||
if (link.matches(LinksMgr.LINK_MATCH.toRegex())) {
|
||||
val oldLink = entry.link
|
||||
entry.link = link
|
||||
bot.updatePin(oldLink, entry)
|
||||
bot.send(EntriesUtils.buildLink(index, entry))
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,10 +122,10 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
|
|||
private fun changeAuthor(cmd: String, sender: String, isOp: Boolean, index: Int) {
|
||||
if (isOp) {
|
||||
if (cmd.length > 1) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
entry.nick = cmd.substring(1)
|
||||
bot.send(EntriesUtils.buildLink(index, entry))
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
}
|
||||
} else {
|
||||
bot.send(sender, "Please ask a channel op to change the author of this link for you.", false)
|
||||
|
@ -133,19 +133,19 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
|
|||
}
|
||||
|
||||
private fun removeEntry(sender: String, login: String, isOp: Boolean, index: Int) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
if (entry.login == login || isOp) {
|
||||
bot.deletePin(index, entry)
|
||||
UrlMgr.removeEntry(index)
|
||||
LinksMgr.removeEntry(index)
|
||||
bot.send("Entry ${Constants.LINK_CMD}${index + 1} removed.")
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
} else {
|
||||
bot.send(sender, "Please ask a channel op to remove this entry for you.", false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showEntry(index: Int) {
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
bot.send(EntriesUtils.buildLink(index, entry))
|
||||
if (entry.hasTags()) {
|
||||
bot.send(EntriesUtils.buildTags(index, entry))
|
||||
|
|
|
@ -63,15 +63,15 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) {
|
|||
val cmds = args.substring(1).split("T:", limit = 2)
|
||||
val index = cmds[0].toInt() - 1
|
||||
|
||||
if (index < UrlMgr.entriesCount) {
|
||||
if (index < LinksMgr.entriesCount) {
|
||||
val cmd = cmds[1].trim()
|
||||
val entry: EntryLink = UrlMgr.getEntry(index)
|
||||
val entry: EntryLink = LinksMgr.getEntry(index)
|
||||
if (cmd.isNotEmpty()) {
|
||||
if (entry.login == login || isOp) {
|
||||
entry.setTags(cmd)
|
||||
bot.updatePin(entry.link, entry)
|
||||
bot.send(EntriesUtils.buildTags(index, entry))
|
||||
UrlMgr.saveEntries(bot, false)
|
||||
LinksMgr.saveEntries(bot, false)
|
||||
} else {
|
||||
bot.send(sender, "Please ask a channel op to change the tags for you.",isPrivate)
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ package net.thauvin.erik.mobibot.commands.links
|
|||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr.Companion.entriesCount
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr.Companion.getEntry
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.entriesCount
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.getEntry
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ package net.thauvin.erik.mobibot.entries;
|
|||
import com.rometools.rome.feed.synd.SyndCategory;
|
||||
import com.rometools.rome.feed.synd.SyndCategoryImpl;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr;
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -347,7 +347,7 @@ public class EntryLink implements Serializable {
|
|||
* @param tags The space-delimited tags.
|
||||
*/
|
||||
public final void setTags(final String tags) {
|
||||
setTags(Arrays.asList(tags.split(UrlMgr.TAG_MATCH)));
|
||||
setTags(Arrays.asList(tags.split(LinksMgr.TAG_MATCH)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,7 +38,7 @@ import net.thauvin.erik.mobibot.Mobibot;
|
|||
import net.thauvin.erik.mobibot.ReleaseInfo;
|
||||
import net.thauvin.erik.mobibot.TwitterTimer;
|
||||
import net.thauvin.erik.mobibot.Utils;
|
||||
import net.thauvin.erik.mobibot.commands.links.UrlMgr;
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import net.thauvin.erik.mobibot.msg.NoticeMessage;
|
||||
|
@ -221,8 +221,8 @@ public final class Twitter extends ThreadedModule {
|
|||
*/
|
||||
@SuppressFBWarnings("SUI_CONTAINS_BEFORE_REMOVE")
|
||||
public final void postEntry(final int index) {
|
||||
if (isAutoPost() && hasEntry(index) && UrlMgr.getEntriesCount() >= index) {
|
||||
final EntryLink entry = UrlMgr.getEntry(index);
|
||||
if (isAutoPost() && hasEntry(index) && LinksMgr.getEntriesCount() >= index) {
|
||||
final EntryLink entry = LinksMgr.getEntry(index);
|
||||
final String msg =
|
||||
entry.getTitle() + ' ' + entry.getLink() + " via " + entry.getNick() + " on " + bot.getChannel();
|
||||
new Thread(() -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue