From 89eac6b0254e8d116370def8513e7403339ba22b Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 30 Mar 2020 15:38:43 -0700 Subject: [PATCH] Fixed isPrivate() and bold() usage. --- .../net/thauvin/erik/mobibot/FeedReader.java | 10 +- .../net/thauvin/erik/mobibot/Mobibot.java | 129 +++++++++--------- .../java/net/thauvin/erik/mobibot/Utils.java | 14 +- .../erik/mobibot/commands/AbstractCommand.kt | 7 +- .../thauvin/erik/mobibot/commands/Cycle.kt | 8 +- .../thauvin/erik/mobibot/commands/Ignore.kt | 40 +++--- .../net/thauvin/erik/mobibot/commands/Info.kt | 6 +- .../net/thauvin/erik/mobibot/commands/Me.kt | 6 +- .../thauvin/erik/mobibot/commands/Modules.kt | 10 +- .../net/thauvin/erik/mobibot/commands/Msg.kt | 6 +- .../net/thauvin/erik/mobibot/commands/Nick.kt | 6 +- .../thauvin/erik/mobibot/commands/Recap.kt | 7 +- .../net/thauvin/erik/mobibot/commands/Say.kt | 8 +- .../thauvin/erik/mobibot/commands/Users.kt | 6 +- .../erik/mobibot/commands/Versions.java | 8 +- .../erik/mobibot/commands/links/Comment.kt | 48 ++++--- .../erik/mobibot/commands/links/Posting.kt | 34 ++--- .../erik/mobibot/commands/links/Tags.kt | 10 +- .../erik/mobibot/commands/links/UrlMgr.kt | 13 +- .../erik/mobibot/commands/links/View.kt | 12 +- .../erik/mobibot/commands/tell/Tell.java | 63 +++++---- .../erik/mobibot/modules/AbstractModule.java | 7 +- .../thauvin/erik/mobibot/modules/Calc.java | 12 +- .../thauvin/erik/mobibot/modules/Dice.java | 8 +- .../erik/mobibot/modules/GoogleSearch.java | 16 +-- .../thauvin/erik/mobibot/modules/Joke.java | 14 +- .../thauvin/erik/mobibot/modules/Lookup.java | 10 +- .../thauvin/erik/mobibot/modules/Ping.java | 8 +- .../erik/mobibot/modules/ThreadedModule.java | 10 +- .../thauvin/erik/mobibot/modules/Twitter.java | 17 ++- .../net/thauvin/erik/mobibot/modules/War.java | 11 +- 31 files changed, 292 insertions(+), 272 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java index 6f52e3a..99c68bd 100644 --- a/src/main/java/net/thauvin/erik/mobibot/FeedReader.java +++ b/src/main/java/net/thauvin/erik/mobibot/FeedReader.java @@ -89,20 +89,20 @@ class FeedReader implements Runnable { SyndEntry item; final List items = feed.getEntries(); if (items.isEmpty()) { - bot.send(sender, "There is currently nothing to view. Why don't you post something?"); + bot.send(sender, "There is currently nothing to view. Why don't you post something?", false); } else { for (int i = 0; (i < items.size()) && (i < MAX_ITEMS); i++) { item = items.get(i); - bot.send(sender, item.getTitle()); - bot.send(sender, TAB_INDENT + Utils.green(item.getLink())); + bot.send(sender, item.getTitle(), false); + bot.send(sender, TAB_INDENT + Utils.green(item.getLink()), false); } } } catch (MalformedURLException e) { bot.getLogger().debug("Invalid feed URL.", e); - bot.send(sender, "The feed URL is invalid."); + bot.send(sender, "The feed URL is invalid.", false); } catch (Exception e) { bot.getLogger().debug("Unable to fetch the feed.", e); - bot.send(sender, "An error has occurred while fetching the feed: " + e.getMessage()); + bot.send(sender, "An error has occurred while fetching the feed: " + e.getMessage(), false); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index 0afd2b0..63a6e4d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -482,13 +482,13 @@ public class Mobibot extends PircBot { /** * Responds with the title and links from the RSS feed. * - * @param sender The nick of the person who sent the private message. + * @param sender The nick of the person who sent the message. */ private void feedResponse(final String sender) { if (isNotBlank(feedUrl)) { new Thread(new FeedReader(this, sender, feedUrl)).start(); } else { - send(sender, "There is no weblog setup for this channel."); + send(sender, "There is no weblog setup for this channel.", false); } } @@ -597,14 +597,15 @@ public class Mobibot extends PircBot { /** * Responds with the commands help, if any. * - * @param sender The nick of the person requesting Constants. - * @param topic The help topic. + * @param sender The nick of the person requesting Constants. + * @param topic The help topic. + * @param isPrivate The private flag. * @return {@code true} if the topic was found, {@code false} otherwise. */ - private boolean helpCommands(final String sender, final String topic) { + private boolean helpCommands(final String sender, final String topic, final boolean isPrivate) { for (final AbstractCommand command : commands) { if (command.isVisible() && command.getCommand().startsWith(topic)) { - return command.helpResponse(this, topic, sender, isOp(sender), true); + return command.helpResponse(this, topic, sender, isOp(sender), isPrivate); } } return false; @@ -613,14 +614,18 @@ public class Mobibot extends PircBot { /** * Responds with the default Constants. * - * @param sender The nick of the person requesting Constants. - * @param isOp The channel operator flag. + * @param sender The nick of the person requesting Constants. + * @param isOp The channel operator flag. + * @param isPrivate The private flag. */ - public void helpDefault(final String sender, final boolean isOp) { - send(sender, Utils.bold("Type a URL on " + ircChannel + " to post it.")); - send(sender, "For more information on a specific command, type:"); - send(sender, Utils.helpIndent(getNick() + ": " + Constants.HELP_CMD + " ")); - send(sender, Utils.bold("The commands are:")); + public void helpDefault(final String sender, final boolean isOp, final boolean isPrivate) { + send(sender, "Type a URL on " + ircChannel + " to post it.", isPrivate); + send(sender, "For more information on a specific command, type:", isPrivate); + send(sender, + Utils.helpIndent( + ((isPrivate) ? "/msg " + getNick() : getNick() + ':') + " " + Constants.HELP_CMD + " "), + isPrivate); + send(sender, "The commands are:", isPrivate); if (commandsNames.isEmpty()) { // Feed command @@ -650,26 +655,29 @@ public class Mobibot extends PircBot { Collections.sort(opsCommandsNames); } - sendCommandsList(sender, commandsNames, false); + sendCommandsList(sender, commandsNames, 8, isPrivate, true); if (isOp) { - send(sender, Utils.bold("The op commands are:"), false); - sendCommandsList(sender, opsCommandsNames, false); + send(sender, "The op commands are:", isPrivate); + sendCommandsList(sender, opsCommandsNames, 8, isPrivate, true); } } /** * Responds with the modules help, if any. * - * @param sender The nick of the person requesting Constants. - * @param topic The help topic. + * @param sender The nick of the person requesting Constants. + * @param topic The help topic. + * @param isPrivate The private flag. * @return {@code true} if the topic was found, {@code false} otherwise. */ - private boolean helpModules(final String sender, final String topic) { + private boolean helpModules(final String sender, final String topic, final boolean isPrivate) { for (final AbstractModule module : modules) { - for (final String cmd : module.getCommands()) { - if (topic.equals(cmd)) { - module.helpResponse(this, sender, topic, true); - return true; + if (module.isEnabled()) { + for (final String cmd : module.getCommands()) { + if (topic.equals(cmd)) { + module.helpResponse(this, sender, isPrivate); + return true; + } } } } @@ -679,24 +687,25 @@ public class Mobibot extends PircBot { /** * Responds with the bot's Constants. * - * @param sender The nick of the person who sent the private message. - * @param topic The help topic, if any. + * @param sender The nick of the person who sent the private message. + * @param topic The help topic, if any. + * @param isPrivate The private flag. */ - private void helpResponse(final String sender, final String topic) { + private void helpResponse(final String sender, final String topic, final boolean isPrivate) { final boolean isOp = isOp(sender); if (StringUtils.isBlank(topic)) { - helpDefault(sender, isOp); + helpDefault(sender, isOp, isPrivate); } else { final String lcTopic = topic.toLowerCase(Constants.LOCALE).trim(); if (lcTopic.equals(getChannelName())) { - send(sender, Utils.bold("To list the last 5 posts from the channel's weblog:")); - send(sender, Utils.helpIndent(getNick() + ": " + getChannelName())); + send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate); + send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), isPrivate); } else if (Tell.TELL_CMD.equals(lcTopic) && tell.isEnabled()) { - tell.helpResponse(sender); + tell.helpResponse(sender, isPrivate); } else { // Command, Modules or Default - if (!helpCommands(sender, topic) && !helpModules(sender, lcTopic)) { - helpDefault(sender, isOp); + if (!helpCommands(sender, topic, isPrivate) && !helpModules(sender, lcTopic, isPrivate)) { + helpDefault(sender, isOp, isPrivate); } } } @@ -782,11 +791,11 @@ public class Mobibot extends PircBot { } if (cmd.startsWith(Constants.HELP_CMD)) { // mobibot: help - helpResponse(sender, args); + helpResponse(sender, args, false); } else if (cmd.equalsIgnoreCase(getChannelName())) { // mobibot: feedResponse(sender); } else if (cmd.startsWith(Tell.TELL_CMD) && tell.isEnabled()) { // mobibot: tell - tell.response(sender, args); + tell.response(sender, args, false); } else { boolean skip = false; // Commands @@ -850,12 +859,12 @@ public class Mobibot extends PircBot { final boolean isOp = isOp(sender); if (cmd.startsWith(Constants.HELP_CMD)) { - helpResponse(sender, args); + helpResponse(sender, args, true); } else if (isOp && "kill".equals(cmd)) { sendRawLine("QUIT : Poof!"); System.exit(0); } else if (isOp && Constants.DIE_CMD.equals(cmd)) { - send(ircChannel, sender + " has just signed my death sentence."); + send(sender + " has just signed my death sentence."); timer.cancel(); twitterShutdown(); twitterNotification("killed by " + sender + " on " + ircChannel); @@ -870,10 +879,10 @@ public class Mobibot extends PircBot { UrlMgr.addHistory(0, args); send(sender, UrlMgr.getHistory().toString(), true); } else { - send(sender, "The specified log could not be found."); + send(sender, "The specified log could not be found.", true); } } else if (Tell.TELL_CMD.equals(cmd) && tell.isEnabled()) { - tell.response(sender, args); + tell.response(sender, args, true); } else if (isOp && Constants.DEBUG_CMD.equals(cmd)) { if (logger.isDebugEnabled()) { Configurator.setLevel(logger.getName(), loggerLevel); @@ -898,7 +907,7 @@ public class Mobibot extends PircBot { } } } - helpDefault(sender, isOp); + helpDefault(sender, isOp, true); } } @@ -961,20 +970,10 @@ public class Mobibot extends PircBot { * @param notice The notice message. */ public final void send(final String notice) { - send(getChannel(), notice); + send(getChannel(), notice, false); } - /** - * Sends a message. - * - * @param who The channel or nick of the person who sent the command. - * @param message The actual message. - */ - public final void send(final String who, final String message) { - send(who, message, false); - } - /** * Sends a message. * @@ -997,29 +996,23 @@ public class Mobibot extends PircBot { send(who, Utils.colorize(message, color), isPrivate); } - /** - * Sends a message. - * - * @param who The channel or nick of the person who sent the command. - * @param message The actual message. - * @param color The message's color. - */ - @SuppressWarnings("unused") - public final void send(final String who, final String message, final String color) { - send(who, Utils.colorize(message, color), false); - } - /** * Send a formatted commands/modules, etc. list. * - * @param nick The nick to send the list to. - * @param list The list to format. + * @param nick The nick to send the list to. + * @param list The list to format. + * @param size The number of items per line. + * @param isPrivate The private flag. + * @param isBold The bold flag */ - public final void sendCommandsList(final String nick, final List list, final boolean isPrivate) { - final int chunk = 8; // 8 commands per line. - for (int i = 0; i < list.size(); i += chunk) { + public final void sendCommandsList(final String nick, + final List list, + final int size, + final boolean isPrivate, + final boolean isBold) { + for (int i = 0; i < list.size(); i += size) { send(nick, Utils.helpIndent( - String.join(" ", list.subList(i, Math.min(list.size(), i + chunk)))), isPrivate); + String.join(" ", list.subList(i, Math.min(list.size(), i + size))), isBold), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index a7ccaa4..67c81c8 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -164,9 +164,21 @@ public final class Utils { * * @param help The help string. * @return The indented help string. + * @see #helpIndent(String, boolean) */ public static String helpIndent(final String help) { - return " " + help; + return helpIndent(help, true); + } + + /** + * Returns indented help string. + * + * @param help The help string. + * @param isBold The bold flag. + * @return The indented help string. + */ + public static String helpIndent(final String help, final boolean isBold) { + return " " + (isBold ? bold(help) : help); } /** diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt b/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt index 4eeaaa8..4b42bc3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt @@ -53,7 +53,12 @@ abstract class AbstractCommand { open fun helpResponse(bot: Mobibot, command: String, sender: String, isOp: Boolean, isPrivate: Boolean): Boolean { if (!this.isOp || this.isOp == isOp) { for (h in help) { - bot.send(sender, String.format(h, bot.nick)) + if (isPrivate) { + bot.send(sender, String.format(h, "/msg ${bot.nick}"), true) + } else if (isPublic) { + bot.send(sender, String.format(h, "${bot.nick}:"), false) + } + } return true } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt index fa18a1b..73c2d7c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt @@ -39,8 +39,8 @@ class Cycle : AbstractCommand() { private val wait = 10 override val command = "cycle" override val help = listOf( - Utils.bold("To have the bot leave the channel and come back:"), - Utils.helpIndent("/msg %s $command") + "To have the bot leave the channel and come back:", + Utils.helpIndent("%s $command") ) override val isOp = true override val isPublic = false @@ -56,13 +56,13 @@ class Cycle : AbstractCommand() { isPrivate: Boolean ) { if (isOp) { - bot.send(bot.channel, "$sender has just asked me to leave. I'll be back!") + bot.send("$sender has just asked me to leave. I'll be back!") bot.sleep(wait) bot.partChannel(bot.channel) bot.sleep(wait) bot.joinChannel(bot.channel) } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt index d24ccd3..6ad42ab 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt @@ -47,18 +47,18 @@ class Ignore(defaultIgnore: String) : AbstractCommand() { override val command = IGNORE_CMD override val help = listOf( - Utils.bold("To ignore a link posted to the channel:"), + "To ignore a link posted to the channel:", Utils.helpIndent("https://www.foo.bar %s"), - Utils.bold("To check your ignore status:"), - Utils.helpIndent("%s: $command"), - Utils.bold("To toggle your ignore status:"), - Utils.helpIndent("%s: $command $me") + "To check your ignore status:", + Utils.helpIndent("%s $command"), + "To toggle your ignore status:", + Utils.helpIndent("%s $command $me") ) private val helpOp = listOf( - Utils.bold("To ignore a link posted to the channel:"), + "To ignore a link posted to the channel:", Utils.helpIndent("https://www.foo.bar %s"), - Utils.bold("To add/remove nicks from the ignored list:"), - Utils.helpIndent("/msg %s $command |$me [ ...]") + "To add/remove nicks from the ignored list:", + Utils.helpIndent("%s $command |$me [ ...]") ) override val isOp = false @@ -86,9 +86,9 @@ class Ignore(defaultIgnore: String) : AbstractCommand() { if (!isOp) { val nick = sender.toLowerCase() val isMe = args.toLowerCase().startsWith(me) - ignoreNick(bot, nick, isMe) + ignoreNick(bot, nick, isMe, isPrivate) } else { - ignoreOp(bot, sender, args) + ignoreOp(bot, sender, args, isPrivate) } } @@ -101,7 +101,7 @@ class Ignore(defaultIgnore: String) : AbstractCommand() { ): Boolean { return if (isOp) { for (h in helpOp) { - bot.send(sender, String.format(h, bot.nick)) + bot.send(sender, String.format(h, bot.nick), isPrivate) } true } else { @@ -109,24 +109,24 @@ class Ignore(defaultIgnore: String) : AbstractCommand() { } } - private fun ignoreNick(bot: Mobibot, sender: String, isMe: Boolean) { + private fun ignoreNick(bot: Mobibot, sender: String, isMe: Boolean, isPrivate: Boolean) { if (isMe) { if (ignored.remove(sender)) { - bot.send(sender, "You are no longer ignored.") + bot.send(sender, "You are no longer ignored.", isPrivate) } else { ignored.add(sender) - bot.send(sender, "You are now ignored.") + bot.send(sender, "You are now ignored.", isPrivate) } } else { if (ignored.contains(sender)) { - bot.send(sender, "You are currently ignored.") + bot.send(sender, "You are currently ignored.", isPrivate) } else { - bot.send(sender, "You are not currently ignored.") + bot.send(sender, "You are not currently ignored.", isPrivate) } } } - private fun ignoreOp(bot: Mobibot, sender: String, args: String) { + private fun ignoreOp(bot: Mobibot, sender: String, args: String, isPrivate: Boolean) { if (args.isNotEmpty()) { val nicks = args.toLowerCase().split(" ") for (nick in nicks) { @@ -142,10 +142,10 @@ class Ignore(defaultIgnore: String) : AbstractCommand() { } if (ignored.size > 0) { - bot.send(sender, Utils.bold("The following nicks are ignored:")) - bot.sendCommandsList(sender, ignored.toList(), false) + bot.send(sender, "The following nicks are ignored:", isPrivate) + bot.sendCommandsList(sender, ignored.toList(), 8, isPrivate, true) } else { - bot.send(sender, "No one is currently ${Utils.bold("ignored")}.") + bot.send(sender, "No one is currently ${Utils.bold("ignored")}.", isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Info.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Info.kt index 261e35e..8c1969c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Info.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Info.kt @@ -40,8 +40,8 @@ import java.lang.management.ManagementFactory class Info : AbstractCommand() { override val command = "info" override val help = listOf( - Utils.bold("To view information about the bot:"), - Utils.helpIndent("%s: $command") + "To view information about the bot:", + Utils.helpIndent("%s $command") ) override val isOp = false override val isPublic = true @@ -82,6 +82,6 @@ class Info : AbstractCommand() { append(']') } - bot.send(sender, info.toString()) + bot.send(sender, info.toString(), isPrivate) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Me.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Me.kt index a229009..75e4c1f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Me.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Me.kt @@ -38,8 +38,8 @@ import net.thauvin.erik.mobibot.Utils class Me : AbstractCommand() { override val command = "me" override val help = listOf( - Utils.bold("To have the bot perform an action:"), - Utils.helpIndent("/msg %s $command ") + "To have the bot perform an action:", + Utils.helpIndent("%s $command ") ) override val isOp = true override val isPublic = false @@ -56,7 +56,7 @@ class Me : AbstractCommand() { if (isOp) { bot.action(args) } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt index ae9492a..d14f437 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt @@ -38,8 +38,8 @@ import net.thauvin.erik.mobibot.Utils class Modules : AbstractCommand() { override val command = "modules" override val help = listOf( - Utils.bold("To view a list of enabled modules:"), - Utils.helpIndent("/msg %s $command") + "To view a list of enabled modules:", + Utils.helpIndent("%s $command") ) override val isOp = true override val isPublic = false @@ -58,11 +58,11 @@ class Modules : AbstractCommand() { if (modulesNames.isEmpty()) { bot.send(sender, "There are no enabled modules.", isPrivate) } else { - bot.send(sender, Utils.bold("The enabled modules are: "), false) - bot.sendCommandsList(sender, modulesNames, false ) + bot.send(sender, "The enabled modules are: ", isPrivate) + bot.sendCommandsList(sender, modulesNames, 7, isPrivate, false) } } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Msg.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Msg.kt index 8c4cc2f..a65ef5c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Msg.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Msg.kt @@ -38,8 +38,8 @@ import net.thauvin.erik.mobibot.Utils class Msg : AbstractCommand() { override val command = "msg" override val help = listOf( - Utils.bold("To have the bot send a private message to someone:"), - Utils.helpIndent("/msg %s $command ") + "To have the bot send a private message to someone:", + Utils.helpIndent("%s $command ") ) override val isOp = true override val isPublic = true @@ -61,7 +61,7 @@ class Msg : AbstractCommand() { helpResponse(bot, command, sender, isOp, isPrivate) } } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Nick.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Nick.kt index 41396ed..1ab8256 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Nick.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Nick.kt @@ -38,8 +38,8 @@ import net.thauvin.erik.mobibot.Utils class Nick : AbstractCommand() { override val command = "nick" override val help = listOf( - Utils.bold("To change the bot's nickname:"), - Utils.helpIndent("/msg %s $command ") + "To change the bot's nickname:", + Utils.helpIndent("%s $command ") ) override val isOp = true override val isPublic = true @@ -56,7 +56,7 @@ class Nick : AbstractCommand() { if (isOp) { bot.changeNick(args) } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt index 2ffc255..c6c690a 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt @@ -41,9 +41,8 @@ import java.util.* class Recap : AbstractCommand() { override val command = "recap" override val help = listOf( - Utils.bold("To list the last 10 public channel messages:"), - Utils.helpIndent("%s: $command"), - Utils.helpIndent("/msg %s $command") + "To list the last 10 public channel messages:", + Utils.helpIndent("%s $command") ) override val isOp = false override val isPublic = true @@ -89,7 +88,7 @@ class Recap : AbstractCommand() { bot.send(sender, r, isPrivate) } } else { - bot.send(sender, "Sorry, nothing to recap.", true) + bot.send(sender, "Sorry, nothing to recap.", isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Say.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Say.kt index c0b1e79..1ddb5d7 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Say.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Say.kt @@ -38,8 +38,8 @@ import net.thauvin.erik.mobibot.Utils class Say : AbstractCommand() { override val command = "say" override val help = listOf( - Utils.bold("To have the bot say something on the channel:"), - Utils.helpIndent("/msg %s $command ") + "To have the bot say something on the channel:", + Utils.helpIndent("%s $command ") ) override val isOp = true override val isPublic = false @@ -55,9 +55,9 @@ class Say : AbstractCommand() { isPrivate: Boolean ) { if (isOp) { - bot.send(bot.channel, args, true) + bot.send(args) } else { - bot.helpDefault(sender, isOp) + bot.helpDefault(sender, isOp, isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt index acfed1d..fad7358 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt @@ -40,8 +40,8 @@ import java.util.* class Users : AbstractCommand() { override val command = "users" override val help = listOf( - Utils.bold("To list the users present on the channel:"), - Utils.helpIndent("/msg %s $command") + "To list the users present on the channel:", + Utils.helpIndent("%s $command") ) override val isOp = false override val isPublic = true @@ -66,6 +66,6 @@ class Users : AbstractCommand() { } } - bot.send(sender, nicks.sorted().joinToString(" ")) + bot.send(sender, nicks.sorted().joinToString(" "), isPrivate) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Versions.java b/src/main/java/net/thauvin/erik/mobibot/commands/Versions.java index 077c985..91f0044 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Versions.java +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Versions.java @@ -60,8 +60,8 @@ public class Versions extends AbstractCommand { @NotNull @Override public List getHelp() { - return List.of(Utils.bold("To view the versions data (bot, java, etc.):"), - Utils.helpIndent("/msg %s $command")); + return List.of("To view the versions data (bot, java, etc.):", + Utils.helpIndent("%s " + getCommand())); } @Override @@ -88,10 +88,10 @@ public class Versions extends AbstractCommand { final boolean isPrivate) { if (isOp) { for (final String v : versions) { - bot.send(sender, v); + bot.send(sender, v, isPrivate); } } else { - bot.helpDefault(sender, false); + bot.helpDefault(sender, false, isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt index 435de45..db996fc 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt @@ -42,12 +42,12 @@ import net.thauvin.erik.mobibot.entries.EntryLink class Comment : AbstractCommand() { override val command = COMMAND override val help = listOf( - Utils.bold("To add a comment:"), + "To add a comment:", Utils.helpIndent("${Constants.LINK_CMD}1:This is a comment"), "I will reply with a label, for example: ${Utils.bold(Constants.LINK_CMD)}1.1", - Utils.bold("To edit a comment, use its label: "), + "To edit a comment, use its label: ", Utils.helpIndent("${Constants.LINK_CMD}1.1:This is an edited comment"), - Utils.bold("To delete a comment, use its label and a minus sign: "), + "To delete a comment, use its label and a minus sign: ", Utils.helpIndent("${Constants.LINK_CMD}1.1:-") ) override val isOp = false @@ -75,9 +75,14 @@ class Comment : AbstractCommand() { if (commentIndex < entry.commentsCount) { when (val cmd = cmds[2].trim()) { "" -> showComment(bot, entry, index, commentIndex) // L1.1: - "-" -> deleteComment(bot, entry, index, commentIndex) // L11:- - "?" -> changeAuthor(bot, cmd, sender, isOp, entry, index, commentIndex) // L1.1:? - else -> setComment(bot, cmd, sender, entry, index, commentIndex) + "-" -> deleteComment(bot, sender, isOp, entry, index, commentIndex) // L11:- + else -> { + if (cmd.startsWith('?')) { // L1.1:? + changeAuthor(bot, cmd, sender, isOp, entry, index, commentIndex) + } else { // L1.1: + setComment(bot, cmd, sender, entry, index, commentIndex) + } + } } } } @@ -92,8 +97,8 @@ class Comment : AbstractCommand() { ): Boolean { if (super.helpResponse(bot, command, sender, isOp, isPrivate)) { if (isOp) { - bot.send(sender, Utils.bold("To change a comment's author:")) - bot.send(sender, Utils.helpIndent("/msg ${bot.nick} ${Constants.LINK_CMD}1.1:?")) + bot.send(sender, "To change a comment's author:", isPrivate) + bot.send(sender, Utils.helpIndent("/msg ${bot.nick} ${Constants.LINK_CMD}1.1:?"), isPrivate) } return true } @@ -116,27 +121,38 @@ class Comment : AbstractCommand() { if (isOp && cmd.length > 1) { val comment = entry.getComment(commentIndex) comment.nick = cmd.substring(1) - bot.send(bot.channel, EntriesUtils.buildComment(index, commentIndex, comment)) + bot.send(EntriesUtils.buildComment(index, commentIndex, comment)) UrlMgr.saveEntries(bot, false) } else { - bot.send(sender, "Please ask a channel op to change the author of this comment for you.") + bot.send(sender, "Please ask a channel op to change the author of this comment for you.", false) } } - private fun deleteComment(bot: Mobibot, entry: EntryLink, index: Int, commentIndex: Int) { - entry.deleteComment(commentIndex) - bot.send(bot.channel, "Comment ${Constants.LINK_CMD}${index + 1}.${commentIndex + 1} removed.") - UrlMgr.saveEntries(bot, false) + private fun deleteComment( + bot: Mobibot, + sender: String, + isOp: Boolean, + entry: EntryLink, + index: Int, + commentIndex: Int + ) { + 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) + } else { + bot.send(sender, "Please ask a channel op to delete this comment for you.", false) + } } private fun setComment(bot: Mobibot, cmd: String, sender: String, entry: EntryLink, index: Int, commentIndex: Int) { entry.setComment(commentIndex, cmd, sender) val comment = entry.getComment(commentIndex) - bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment)) + bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment), false) UrlMgr.saveEntries(bot, false) } private fun showComment(bot: Mobibot, entry: EntryLink, index: Int, commentIndex: Int) { - bot.send(bot.channel, EntriesUtils.buildComment(index, commentIndex, entry.getComment(commentIndex))) + bot.send(EntriesUtils.buildComment(index, commentIndex, entry.getComment(commentIndex))) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt index 7b9fed5..8a90987 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt @@ -42,16 +42,16 @@ import net.thauvin.erik.mobibot.entries.EntryLink class Posting : AbstractCommand() { override val command = "posting" override val help = listOf( - Utils.bold("Post a URL, by saying it on a line on its own:"), + "Post a URL, by saying it on a line on its own:", Utils.helpIndent(" [] ${Tags.COMMAND}}: <+tag> [...]]"), - "I will reply with a label, for example:" + Utils.bold("${Constants.LINK_CMD}1"), - Utils.bold("To add a title, use its label and a pipe:"), + "I will reply with a label, for example: ${Utils.bold(Constants.LINK_CMD)}1", + "To add a title, use its label and a pipe:", Utils.helpIndent("${Constants.LINK_CMD}1:|This is the title"), - Utils.bold("To add a comment:"), + "To add a comment:", Utils.helpIndent("${Constants.LINK_CMD}1:This is a comment"), "I will reply with a label, for example: ${Utils.bold(Constants.LINK_CMD)}1.1", - Utils.bold("To edit a comment, see: "), - Utils.helpIndent("/msg %s ${Constants.HELP_CMD} ${Comment.COMMAND}") + "To edit a comment, see: ", + Utils.helpIndent("%s ${Constants.HELP_CMD} ${Comment.COMMAND}") ) override val isOp = false override val isPublic = true @@ -77,7 +77,7 @@ class Posting : AbstractCommand() { '|' -> changeTitle(bot, cmd, index) // L1:|<title> '=' -> changeUrl(bot, cmd, login, isOp, index) // L1:=<url> '?' -> changeAuthor(bot, cmd, sender, isOp, index) // L1:?<author> - else -> addComment(bot, cmd, sender, index) + else -> addComment(bot, cmd, sender, index) // L1:<comment> } } } @@ -92,7 +92,7 @@ class Posting : AbstractCommand() { val entry: EntryLink = UrlMgr.getEntry(index) val commentIndex = entry.addComment(cmd, sender) val comment = entry.getComment(commentIndex) - bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment)) + bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment), false) UrlMgr.saveEntries(bot, false) } @@ -101,7 +101,7 @@ class Posting : AbstractCommand() { val entry: EntryLink = UrlMgr.getEntry(index) entry.title = cmd.substring(1).trim() bot.updatePin(entry.link, entry) - bot.send(bot.channel, EntriesUtils.buildLink(index, entry)) + bot.send(EntriesUtils.buildLink(index, entry)) UrlMgr.saveEntries(bot, false) } } @@ -114,7 +114,7 @@ class Posting : AbstractCommand() { val oldLink = entry.link entry.link = link bot.updatePin(oldLink, entry) - bot.send(bot.channel, EntriesUtils.buildLink(index, entry)) + bot.send(EntriesUtils.buildLink(index, entry)) UrlMgr.saveEntries(bot, false) } } @@ -125,11 +125,11 @@ class Posting : AbstractCommand() { if (cmd.length > 1) { val entry: EntryLink = UrlMgr.getEntry(index) entry.nick = cmd.substring(1) - bot.send(bot.channel, EntriesUtils.buildLink(index, entry)) + bot.send(EntriesUtils.buildLink(index, entry)) UrlMgr.saveEntries(bot, false) } } else { - bot.send(sender, "Please ask a channel op to change the author of this link for you.") + bot.send(sender, "Please ask a channel op to change the author of this link for you.", false) } } @@ -141,23 +141,23 @@ class Posting : AbstractCommand() { bot.twitterRemoveEntry(index) } UrlMgr.removeEntry(index) - bot.send(bot.channel, "Entry ${Constants.LINK_CMD}${index + 1} removed.") + bot.send("Entry ${Constants.LINK_CMD}${index + 1} removed.") UrlMgr.saveEntries(bot, false) } else { - bot.send(sender, "Please ask a channel op to remove this entry for you.") + bot.send(sender, "Please ask a channel op to remove this entry for you.", false) } } private fun showEntry(bot: Mobibot, index: Int) { val entry: EntryLink = UrlMgr.getEntry(index) - bot.send(bot.channel, EntriesUtils.buildLink(index, entry)) + bot.send(EntriesUtils.buildLink(index, entry)) if (entry.hasTags()) { - bot.send(bot.channel, EntriesUtils.buildTags(index, entry)) + bot.send(EntriesUtils.buildTags(index, entry)) } if (entry.hasComments()) { val comments = entry.comments for (i in comments.indices) { - bot.send(bot.channel, EntriesUtils.buildComment(index, i, comments[i])) + bot.send(EntriesUtils.buildComment(index, i, comments[i])) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt index 204f41f..6978794 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt @@ -42,7 +42,7 @@ import net.thauvin.erik.mobibot.entries.EntryLink class Tags : AbstractCommand() { override val command = COMMAND override val help = listOf( - Utils.bold("To categorize or tag a URL, use its label and a T:"), + "To categorize or tag a URL, use its label and a T:", Utils.helpIndent("${Constants.LINK_CMD}1T:<+tag|-tag> [...]") ) override val isOp = false @@ -71,16 +71,16 @@ class Tags : AbstractCommand() { if (entry.login == login || isOp) { entry.setTags(cmd) bot.updatePin(entry.link, entry) - bot.send(bot.channel, EntriesUtils.buildTags(index, entry)) + bot.send(EntriesUtils.buildTags(index, entry)) UrlMgr.saveEntries(bot, false) } else { - bot.send(sender, "Please ask a channel op to change the tags for you.") + bot.send(sender, "Please ask a channel op to change the tags for you.",isPrivate) } } else { if (entry.hasTags()) { - bot.send(bot.channel, EntriesUtils.buildTags(index, entry)) + bot.send(EntriesUtils.buildTags(index, entry)) } else { - bot.send(sender, "The entry has no tags. Why don't add some?") + bot.send(sender, "The entry has no tags. Why don't add some?", isPrivate) } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/UrlMgr.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/UrlMgr.kt index 89519ef..1daf17e 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/UrlMgr.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/UrlMgr.kt @@ -128,7 +128,7 @@ class UrlMgr(defaultTags: String, keywords: String) : AbstractCommand() { if (Ignore.isNotIgnored(sender) && (cmds.size == 1 || !cmds[1].contains(bot.nick))) { val link = cmds[0].trim() - if (!isDupEntry(bot, sender, link)) { + if (!isDupEntry(bot, sender, link, isPrivate)) { val isBackup = saveDayBackup(bot) val tags: StringBuilder = StringBuilder(defaultTags) var title = Constants.NO_TITLE @@ -145,7 +145,7 @@ class UrlMgr(defaultTags: String, keywords: String) : AbstractCommand() { entries.add(EntryLink(link, title, sender, login, bot.channel, tags.toString())) val index: Int = entries.size - 1 val entry: EntryLink = entries[index] - bot.send(bot.channel, EntriesUtils.buildLink(index, entry)) + bot.send(EntriesUtils.buildLink(index, entry)) // Add Entry to pinboard. bot.addPin(entry) @@ -156,10 +156,11 @@ class UrlMgr(defaultTags: String, keywords: String) : AbstractCommand() { saveEntries(bot, isBackup) if (Constants.NO_TITLE == entry.title) { - bot.send(sender, Utils.bold("Please specify a title, by typing:")) + bot.send(sender, "Please specify a title, by typing:", isPrivate) bot.send( sender, - Utils.helpIndent(Constants.LINK_CMD + (index + 1) + ":|This is the title") + Utils.helpIndent(Constants.LINK_CMD + (index + 1) + ":|This is the title"), + isPrivate ) } } @@ -196,12 +197,12 @@ class UrlMgr(defaultTags: String, keywords: String) : AbstractCommand() { return title } - private fun isDupEntry(bot: Mobibot, sender: String, link: String): Boolean { + private fun isDupEntry(bot: Mobibot, sender: String, link: String, isPrivate: Boolean): Boolean { synchronized(entries) { for (i in entries.indices) { if (link == entries[i].link) { val entry: EntryLink = entries[i] - bot.send(sender, Utils.bold("Duplicate") + " >> " + EntriesUtils.buildLink(i, entry)) + bot.send(sender, Utils.bold("Duplicate") + " >> " + EntriesUtils.buildLink(i, entry), isPrivate) return true } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt index 1bf601a..94ef295 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt @@ -45,8 +45,8 @@ class View : AbstractCommand() { private val maxEntries = 8 override val command = VIEW_CMD override val help = listOf( - Utils.bold("To list or search the current URL posts:"), - Utils.helpIndent("%s: $command [<start>] [<query>]") + "To list or search the current URL posts:", + Utils.helpIndent("%s $command [<start>] [<query>]") ) override val isOp = false override val isPublic = true @@ -67,7 +67,7 @@ class View : AbstractCommand() { if (entriesCount != 0) { showPosts(bot, args, sender) } else { - bot.send(sender, "There is currently nothing to view. Why don't you post something?") + bot.send(sender, "There is currently nothing to view. Why don't you post something?", isPrivate) } } @@ -101,17 +101,17 @@ class View : AbstractCommand() { entry = getEntry(i) if (lcArgs.isNotBlank()) { if (entry.matches(lcArgs)) { - bot.send(sender, EntriesUtils.buildLink(i, entry, true)) + bot.send(sender, EntriesUtils.buildLink(i, entry, true), false) sent++ } } else { - bot.send(sender, EntriesUtils.buildLink(i, entry, true)) + bot.send(sender, EntriesUtils.buildLink(i, entry, true), false) sent++ } i++ if (sent == maxEntries && i < max) { bot.send( - sender, "To view more, try: " + Utils.bold("${bot.nick}: $command ${i + 1} $lcArgs") + sender, "To view more, try: " + Utils.bold("${bot.nick}: $command ${i + 1} $lcArgs"), false ) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.java b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.java index e8cee58..44938bf 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.java +++ b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.java @@ -114,16 +114,19 @@ public class Tell { /** * Responds with Constants. * - * @param sender The sender. + * @param sender The sender. + * @param isPrivate The private flag. */ - public void helpResponse(final String sender) { - bot.send(sender, "To send a message to someone when they join the channel:"); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + " <nick> <message>")); + public void helpResponse(final String sender, final boolean isPrivate) { + bot.send(sender, "To send a message to someone when they join the channel:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + " <nick> <message>"), isPrivate); - bot.send(sender, "To view queued and sent messages:"); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + View.VIEW_CMD)); + bot.send(sender, "To view queued and sent messages:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + View.VIEW_CMD), isPrivate); - bot.send(sender, "Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days.")); + bot.send(sender, + "Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."), + isPrivate); } /** @@ -138,15 +141,16 @@ public class Tell { /** * Processes the commands. * - * @param sender The sender's nick. - * @param cmds The commands string. + * @param sender The sender's nick. + * @param cmds The commands string. + * @param isPrivate The private flag. */ @SuppressFBWarnings(value = "CC_CYCLOMATIC_COMPLEXITY", justification = "Working on it.") - public void response(final String sender, final String cmds) { + public void response(final String sender, final String cmds, final boolean isPrivate) { final String arrow = " --> "; if (StringUtils.isBlank(cmds)) { - helpResponse(sender); + helpResponse(sender, isPrivate); } else if (cmds.startsWith(View.VIEW_CMD)) { if (bot.isOp(sender) && (View.VIEW_CMD + ' ' + TELL_ALL_KEYWORD).equals(cmds)) { if (!messages.isEmpty()) { @@ -154,10 +158,10 @@ public class Tell { bot.send(sender, Utils.bold(message.getSender()) + arrow + Utils.bold(message.getRecipient()) + " [ID: " + message.getId() + ", " + (message.isReceived() ? "DELIVERED" : "QUEUED") + ']', - true); + isPrivate); } } else { - bot.send(sender, "There are no messages in the queue.", true); + bot.send(sender, "There are no messages in the queue.", isPrivate); } } else { boolean hasMessage = false; @@ -166,7 +170,7 @@ public class Tell { if (message.isMatch(sender)) { if (!hasMessage) { hasMessage = true; - bot.send(sender, "Here are your messages: ", true); + bot.send(sender, "Here are your messages: ", isPrivate); } if (message.isReceived()) { @@ -174,29 +178,30 @@ public class Tell { Utils.bold(message.getSender()) + arrow + Utils.bold(message.getRecipient()) + " [" + Utils.utcDateTime(message.getReceived()) + ", ID: " + message.getId() + ", DELIVERED]", - true); + isPrivate); } else { bot.send(sender, Utils.bold(message.getSender()) + arrow + Utils.bold(message.getRecipient()) + " [" + Utils.utcDateTime(message.getQueued()) + ", ID: " + message.getId() + ", QUEUED]", - true); + isPrivate); } - bot.send(sender, Utils.helpIndent(message.getMessage()), true); + bot.send(sender, Utils.helpIndent(message.getMessage()), isPrivate); } } if (!hasMessage) { - bot.send(sender, "You have no messages in the queue.", true); + bot.send(sender, "You have no messages in the queue.", isPrivate); } else { - bot.send(sender, "To delete one or all delivered messages:"); + bot.send(sender, "To delete one or all delivered messages:", isPrivate); bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + TELL_DEL_KEYWORD + " <id|" - + TELL_ALL_KEYWORD + '>')); - bot.send(sender, "Messages are kept for " + Utils.bold(maxDays) - + Utils.plural(maxDays, " day.", " days.")); + + TELL_ALL_KEYWORD + '>'), isPrivate); + bot.send(sender, + "Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."), + isPrivate); } } } else if (cmds.startsWith(TELL_DEL_KEYWORD + ' ')) { @@ -216,9 +221,9 @@ public class Tell { if (deleted) { save(); - bot.send(sender, "Delivered messages have been deleted.", true); + bot.send(sender, "Delivered messages have been deleted.", isPrivate); } else { - bot.send(sender, "No delivered messages were found.", true); + bot.send(sender, "No delivered messages were found.", isPrivate); } } else { @@ -231,7 +236,7 @@ public class Tell { messages.remove(message); save(); - bot.send(sender, "Your message was deleted from the queue.", true); + bot.send(sender, "Your message was deleted from the queue.", isPrivate); deleted = true; break; } @@ -239,14 +244,14 @@ public class Tell { if (!deleted) { if (found) { - bot.send(sender, "Only messages that you sent can be deleted.", true); + bot.send(sender, "Only messages that you sent can be deleted.", isPrivate); } else { - bot.send(sender, "The specified message [ID " + id + "] could not be found.", true); + bot.send(sender, "The specified message [ID " + id + "] could not be found.", isPrivate); } } } } else { - helpResponse(sender); + helpResponse(sender, isPrivate); } } else { final String[] split = cmds.split(" ", 2); @@ -265,7 +270,7 @@ public class Tell { bot.send(sender, "Sorry, the messages queue is currently full.", true); } } else { - helpResponse(sender); + helpResponse(sender, isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/AbstractModule.java b/src/main/java/net/thauvin/erik/mobibot/modules/AbstractModule.java index 671db96..12bee34 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/AbstractModule.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/AbstractModule.java @@ -96,16 +96,13 @@ public abstract class AbstractModule { /** * Responds with the module's Constants. - * - * @param bot The bot's instance. + * @param bot The bot's instance. * @param sender The sender. - * @param args The help arguments. * @param isPrivate Set to <code>true</code> if the response should be sent as a private message. */ public abstract void helpResponse(final Mobibot bot, final String sender, - final String args, - @SuppressWarnings("unused") final boolean isPrivate); + final boolean isPrivate); /** * Returns <code>true</code> if the module is enabled. diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Calc.java b/src/main/java/net/thauvin/erik/mobibot/modules/Calc.java index 8201c8b..f9e1e2f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Calc.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Calc.java @@ -40,8 +40,6 @@ import org.apache.commons.lang3.StringUtils; import java.text.DecimalFormat; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The Calc module. * @@ -74,7 +72,7 @@ public class Calc extends AbstractModule { try { final Expression calc = new ExpressionBuilder(query).build(); - return query.replace(" ", "") + " = " + decimalFormat.format(calc.evaluate()); + return query.replace(" ", "") + " = " + Utils.bold(decimalFormat.format(calc.evaluate())); } catch (Exception e) { return "No idea. This is the kind of math I don't get."; } @@ -92,7 +90,7 @@ public class Calc extends AbstractModule { if (StringUtils.isNotBlank(args)) { bot.send(calc(args)); } else { - helpResponse(bot, sender, args, isPrivate); + helpResponse(bot, sender, isPrivate); } } @@ -100,8 +98,8 @@ public class Calc extends AbstractModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To solve a mathematical calculation:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + CALC_CMD + " <calculation>")); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To solve a mathematical calculation:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + CALC_CMD + " <calculation>"), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java index 4388724..ec1d57c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java @@ -75,7 +75,7 @@ public final class Dice extends AbstractModule { bot.send(bot.getChannel(), sender + " rolled two dice: " + bold(i) + " and " + bold(y) + " for a total of " - + bold(playerTotal)); + + bold(playerTotal), isPrivate); i = r.nextInt(6) + 1; y = r.nextInt(6) + 1; @@ -97,8 +97,8 @@ public final class Dice extends AbstractModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To roll the dice:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + DICE_CMD)); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To roll the dice:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + DICE_CMD), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.java b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.java index f40b5af..9e92783 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.java @@ -52,8 +52,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The GoogleSearch module. * @@ -145,12 +143,12 @@ public final class GoogleSearch extends ThreadedModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { if (isEnabled()) { - bot.send(sender, bold("To search Google:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + GOOGLE_CMD + " <query>")); + bot.send(sender, "To search Google:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + GOOGLE_CMD + " <query>"), isPrivate); } else { - bot.send(sender, "The Google search module is disabled."); + bot.send(sender, "The Google search module is disabled.", isPrivate); } } @@ -158,7 +156,7 @@ public final class GoogleSearch extends ThreadedModule { * Searches Google. */ @Override - void run(final Mobibot bot, final String sender, final String cmd, final String query) { + void run(final Mobibot bot, final String sender, final String cmd, final String query, final boolean isPrivate) { if (StringUtils.isNotBlank(query)) { try { final List<Message> results = searchGoogle(query, properties.get(GOOGLE_API_KEY_PROP), @@ -168,10 +166,10 @@ public final class GoogleSearch extends ThreadedModule { } } catch (ModuleException e) { bot.getLogger().warn(e.getDebugMessage(), e); - bot.send(sender, e.getMessage()); + bot.send(sender, e.getMessage(), isPrivate); } } else { - helpResponse(bot, sender, query, true); + helpResponse(bot, sender, isPrivate); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java index 199e4e7..5f30ccd 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java @@ -44,8 +44,6 @@ import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The Joke module. * @@ -107,19 +105,19 @@ public final class Joke extends ThreadedModule { final String cmd, final String args, final boolean isPrivate) { - new Thread(() -> run(bot, sender, cmd, args)).start(); + new Thread(() -> run(bot, sender, cmd, args, isPrivate)).start(); } /** * Returns a random joke from <a href="http://www.icndb.com/">The Internet Chuck Norris Database</a>. */ @Override - void run(final Mobibot bot, final String sender, final String cmd, final String arg) { + void run(final Mobibot bot, final String sender, final String cmd, final String arg, final boolean isPrivate) { try { bot.send(Utils.cyan(randomJoke().getMessage())); } catch (ModuleException e) { bot.getLogger().warn(e.getDebugMessage(), e); - bot.send(sender, e.getMessage()); + bot.send(sender, e.getMessage(), isPrivate); } } @@ -127,8 +125,8 @@ public final class Joke extends ThreadedModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To retrieve a random joke:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + JOKE_CMD)); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To retrieve a random joke:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + JOKE_CMD), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.java b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.java index 676ebbe..c1292f6 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.java @@ -41,8 +41,6 @@ import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The Lookup module. * @@ -189,7 +187,7 @@ public final class Lookup extends AbstractModule { } } } else { - helpResponse(bot, sender, args, true); + helpResponse(bot, sender, true); } } @@ -197,8 +195,8 @@ public final class Lookup extends AbstractModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To perform a DNS lookup query:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + LOOKUP_CMD + " <ip address or hostname>")); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To perform a DNS lookup query:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + LOOKUP_CMD + " <ip address or hostname>"), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java b/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java index 4e689a8..6123898 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java @@ -39,8 +39,6 @@ import java.security.SecureRandom; import java.util.Arrays; import java.util.List; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The Ping module. * @@ -96,8 +94,8 @@ public class Ping extends AbstractModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To ping the bot:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + PING_CMD)); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To ping the bot:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + PING_CMD), isPrivate); } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/ThreadedModule.java b/src/main/java/net/thauvin/erik/mobibot/modules/ThreadedModule.java index 7119950..6bdc29f 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/ThreadedModule.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/ThreadedModule.java @@ -52,14 +52,18 @@ public abstract class ThreadedModule extends AbstractModule { final String args, final boolean isPrivate) { if (isEnabled() && args.length() > 0) { - new Thread(() -> run(bot, sender, cmd, args)).start(); + new Thread(() -> run(bot, sender, cmd, args, isPrivate)).start(); } else { - helpResponse(bot, sender, args, isPrivate); + helpResponse(bot, sender, isPrivate); } } /** * Runs the thread. */ - abstract void run(Mobibot bot, String sender, @SuppressWarnings("unused") String cmd, String args); + abstract void run(Mobibot bot, + String sender, + @SuppressWarnings("unused") String cmd, + String args, + boolean isPrivate); } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java index f3ed606..2d0c997 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java @@ -41,8 +41,6 @@ import twitter4j.Status; import twitter4j.TwitterFactory; import twitter4j.conf.ConfigurationBuilder; -import static net.thauvin.erik.mobibot.Utils.bold; - /** * The Twitter module. * @@ -116,12 +114,12 @@ public final class Twitter extends ThreadedModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { if (isEnabled()) { - bot.send(sender, bold("To post to Twitter:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TWITTER_CMD + " <message>")); + bot.send(sender, "To post to Twitter:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TWITTER_CMD + " <message>"), isPrivate); } else { - bot.send(sender, "The Twitter posting facility is disabled."); + bot.send(sender, "The Twitter posting facility is " + Utils.bold("disabled") + '.', isPrivate); } } @@ -149,13 +147,14 @@ public final class Twitter extends ThreadedModule { * Posts to twitter. */ @Override - void run(final Mobibot bot, final String sender, final String cmd, final String message) { + void run(final Mobibot bot, final String sender, final String cmd, final String message, final boolean isPrivate) { try { bot.send(sender, - post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getMessage()); + post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getMessage(), + isPrivate); } catch (ModuleException e) { bot.getLogger().warn(e.getDebugMessage(), e); - bot.send(sender, e.getMessage()); + bot.send(sender, e.getMessage(), isPrivate); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/War.java b/src/main/java/net/thauvin/erik/mobibot/modules/War.java index 9d6087e..a7b294b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/War.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/War.java @@ -81,9 +81,8 @@ public final class War extends AbstractModule { i = r.nextInt(WAR_DECK.length); y = r.nextInt(WAR_DECK.length); - bot.send(bot.getChannel(), - sender + " drew the " + bold(WAR_DECK[i]) + " of " + WAR_SUITS[r.nextInt(WAR_SUITS.length)]); - bot.action("drew the " + bold(WAR_DECK[y]) + " of " + WAR_SUITS[r.nextInt(WAR_SUITS.length)]); + bot.send(sender + " drew the " + bold(WAR_DECK[i]) + " of " + bold(WAR_SUITS[r.nextInt(WAR_SUITS.length)])); + bot.action("drew the " + bold(WAR_DECK[y]) + " of " + bold(WAR_SUITS[r.nextInt(WAR_SUITS.length)])); if (i != y) { break; @@ -103,8 +102,8 @@ public final class War extends AbstractModule { * {@inheritDoc} */ @Override - public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - bot.send(sender, bold("To play war:")); - bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + WAR_CMD)); + public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) { + bot.send(sender, "To play war:", isPrivate); + bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + WAR_CMD), isPrivate); } }