Added Utils.botCommand().

This commit is contained in:
Erik C. Thauvin 2020-03-30 21:59:23 -07:00
parent 0ec1e75106
commit 37f3c49413
3 changed files with 20 additions and 6 deletions

View file

@ -42,6 +42,14 @@ import java.util.Locale;
* @since 1.0 * @since 1.0
*/ */
public final class Constants { 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. * The connect/read timeout in ms.
*/ */

View file

@ -335,4 +335,14 @@ public final class Utils {
public static String utcDateTime(final LocalDateTime date) { public static String utcDateTime(final LocalDateTime date) {
return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); 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);
}
}
} }

View file

@ -33,6 +33,7 @@
package net.thauvin.erik.mobibot.commands package net.thauvin.erik.mobibot.commands
import net.thauvin.erik.mobibot.Mobibot import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils
abstract class AbstractCommand { abstract class AbstractCommand {
abstract val command: String 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 { open fun helpResponse(bot: Mobibot, command: String, sender: String, isOp: Boolean, isPrivate: Boolean): Boolean {
if (!this.isOp || this.isOp == isOp) { if (!this.isOp || this.isOp == isOp) {
for (h in help) { for (h in help) {
if (isPrivate) { bot.send(sender, String.format(h, Utils.botCommand(bot.nick, isPrivate)), 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 return true
} }