From 37f3c4941386a3844282b0638197a724e7a73939 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 30 Mar 2020 21:59:23 -0700 Subject: [PATCH] Added Utils.botCommand(). --- src/main/java/net/thauvin/erik/mobibot/Constants.java | 8 ++++++++ src/main/java/net/thauvin/erik/mobibot/Utils.java | 10 ++++++++++ .../thauvin/erik/mobibot/commands/AbstractCommand.kt | 8 ++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/Constants.java b/src/main/java/net/thauvin/erik/mobibot/Constants.java index 9943398..d985b72 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Constants.java +++ b/src/main/java/net/thauvin/erik/mobibot/Constants.java @@ -42,6 +42,14 @@ import java.util.Locale; * @since 1.0 */ public final class Constants { + /** + * The bot's private message command format. + */ + public static final String BOT_PRIVATE_CMD = "/msg %s "; + /** + * The bot's public message command format. + */ + public static final String BOT_PUB_CMD = "%s: "; /** * The connect/read timeout in ms. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index 67c81c8..07767a5 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -335,4 +335,14 @@ public final class Utils { public static String utcDateTime(final LocalDateTime date) { return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); } + + public static String botCommand(final String name, boolean isPrivate) { + if (isPrivate) { + return String.format(Constants.BOT_PRIVATE_CMD, name); + } else { + return String.format(Constants.BOT_PUB_CMD, name); + } + + } + } 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 4b42bc3..bcafa66 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt @@ -33,6 +33,7 @@ package net.thauvin.erik.mobibot.commands import net.thauvin.erik.mobibot.Mobibot +import net.thauvin.erik.mobibot.Utils abstract class AbstractCommand { abstract val command: String @@ -53,12 +54,7 @@ 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) { - if (isPrivate) { - bot.send(sender, String.format(h, "/msg ${bot.nick}"), true) - } else if (isPublic) { - bot.send(sender, String.format(h, "${bot.nick}:"), false) - } - + bot.send(sender, String.format(h, Utils.botCommand(bot.nick, isPrivate)), isPrivate) } return true }