diff --git a/src/main/java/net/thauvin/erik/mobibot/Constants.java b/src/main/java/net/thauvin/erik/mobibot/Constants.java index 411c688..9943398 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Constants.java +++ b/src/main/java/net/thauvin/erik/mobibot/Constants.java @@ -42,10 +42,6 @@ import java.util.Locale; * @since 1.0 */ public final class Constants { - /** - * The add (back)log command. - */ - public static final String ADDLOG_CMD = "addlog"; /** * The connect/read timeout in ms. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index 63a6e4d..cf460ea 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -34,6 +34,7 @@ package net.thauvin.erik.mobibot; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.commands.AbstractCommand; +import net.thauvin.erik.mobibot.commands.AddLog; import net.thauvin.erik.mobibot.commands.Cycle; import net.thauvin.erik.mobibot.commands.Ignore; import net.thauvin.erik.mobibot.commands.Info; @@ -85,7 +86,6 @@ import org.apache.logging.log4j.core.config.Configurator; import org.jibble.pircbot.PircBot; import org.jibble.pircbot.User; -import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -240,6 +240,7 @@ public class Mobibot extends PircBot { ignoreCommand = new Ignore(p.getProperty("ignore", "")); // Load the commands + commands.add(new AddLog()); commands.add(new Cycle()); commands.add(ignoreCommand); commands.add(new Info()); @@ -858,38 +859,28 @@ public class Mobibot extends PircBot { final boolean isOp = isOp(sender); - if (cmd.startsWith(Constants.HELP_CMD)) { + if (cmd.startsWith(Constants.HELP_CMD)) { // help helpResponse(sender, args, true); - } else if (isOp && "kill".equals(cmd)) { + } else if (isOp && "kill".equals(cmd)) { // kill sendRawLine("QUIT : Poof!"); System.exit(0); - } else if (isOp && Constants.DIE_CMD.equals(cmd)) { - send(sender + " has just signed my death sentence."); - timer.cancel(); - twitterShutdown(); - twitterNotification("killed by " + sender + " on " + ircChannel); - - sleep(3); - quitServer("The Bot Is Out There!"); - System.exit(0); - } else if (isOp && (cmds.length > 1) && Constants.ADDLOG_CMD.equals(cmd)) { - // e.g 2014-04-01 - final File backlog = new File(logsDir + args + EntriesMgr.XML_EXT); - if (backlog.exists()) { - UrlMgr.addHistory(0, args); - send(sender, UrlMgr.getHistory().toString(), true); - } else { - send(sender, "The specified log could not be found.", true); - } - } else if (Tell.TELL_CMD.equals(cmd) && tell.isEnabled()) { - tell.response(sender, args, true); - } else if (isOp && Constants.DEBUG_CMD.equals(cmd)) { + } else if (isOp && Constants.DEBUG_CMD.equals(cmd)) { // debug if (logger.isDebugEnabled()) { Configurator.setLevel(logger.getName(), loggerLevel); } else { Configurator.setLevel(logger.getName(), Level.DEBUG); } send(sender, "Debug logging is " + (logger.isDebugEnabled() ? "enabled." : "disabled."), true); + } else if (isOp && Constants.DIE_CMD.equals(cmd)) { // die + send(sender + " has just signed my death sentence."); + timer.cancel(); + twitterShutdown(); + twitterNotification("killed by " + sender + " on " + ircChannel); + sleep(3); + quitServer("The Bot Is Out There!"); + System.exit(0); + } else if (Tell.TELL_CMD.equals(cmd) && tell.isEnabled()) { // tell + tell.response(sender, args, true); } else { for (final AbstractCommand command : commands) { if (command.getCommand().startsWith(cmd)) { @@ -1054,7 +1045,7 @@ public class Mobibot extends PircBot { */ final void setPinboardAuth(final String apiToken) { if (isNotBlank(apiToken)) { - pinboard = new Pinboard(this, apiToken, ircServer); + pinboard = new Pinboard(this, apiToken); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt b/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt new file mode 100644 index 0000000..0c01306 --- /dev/null +++ b/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt @@ -0,0 +1,67 @@ +/* + * AddLog.kt + * + * Copyright (c) 2004-2020, 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.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.entries.EntriesMgr +import java.io.File + +class AddLog : AbstractCommand() { + override val command = "addlog" + override val help = emptyList() + override val isOp = true + override val isPublic = false + override val isVisible = false + + override fun commandResponse( + bot: Mobibot, + sender: String, + login: String, + args: String, + isOp: Boolean, + isPrivate: Boolean + ) { + if (isOp && args.isNotBlank()) { + // e.g: 2014-04-01 + val backlog = File("${bot.logsDir}$args${EntriesMgr.XML_EXT}") + if (backlog.exists()) { + addHistory(0, args) + bot.send(sender, getHistory().toString(), isPrivate) + } else { + bot.send(sender, "The specified log could not be found.", isPrivate) + } + } + } +}