From 629e26b2925a412ed32c8dcec8659df37081b7c6 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 8 Dec 2020 01:40:09 -0800 Subject: [PATCH] Cleanup. --- config/detekt/baseline.xml | 1 + .../java/net/thauvin/erik/mobibot/Addons.kt | 9 +++-- .../java/net/thauvin/erik/mobibot/Mobibot.kt | 15 ++++--- .../java/net/thauvin/erik/mobibot/Utils.kt | 40 +++++++++++++------ .../erik/mobibot/commands/AbstractCommand.kt | 14 +------ .../erik/mobibot/commands/ChannelFeed.kt | 4 +- .../thauvin/erik/mobibot/commands/Debug.kt | 3 +- .../thauvin/erik/mobibot/commands/Ignore.kt | 5 +-- .../thauvin/erik/mobibot/commands/Info.java | 4 +- .../thauvin/erik/mobibot/commands/Recap.kt | 12 +----- .../thauvin/erik/mobibot/commands/Users.kt | 4 +- .../erik/mobibot/commands/links/LinksMgr.kt | 2 +- .../erik/mobibot/commands/links/Posting.kt | 4 +- .../erik/mobibot/commands/links/Tags.kt | 2 +- .../erik/mobibot/commands/tell/Tell.kt | 10 ++--- .../erik/mobibot/commands/tell/TellMessage.kt | 8 ---- .../mobibot/commands/tell/TellMessagesMgr.kt | 6 +-- .../erik/mobibot/entries/EntriesUtils.kt | 2 +- .../thauvin/erik/mobibot/entries/EntryLink.kt | 14 +------ .../net/thauvin/erik/mobibot/modules/Calc.kt | 2 +- .../erik/mobibot/modules/ModuleException.kt | 8 ---- .../mobibot/commands/tell/TellMessageTest.kt | 1 - .../erik/mobibot/entries/EntryLinkTest.kt | 4 +- .../erik/mobibot/modules/GoogleSearchTest.kt | 2 +- .../erik/mobibot/modules/StockQuoteTest.kt | 2 +- 25 files changed, 75 insertions(+), 103 deletions(-) diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml index ac048e7..03d17a4 100644 --- a/config/detekt/baseline.xml +++ b/config/detekt/baseline.xml @@ -12,6 +12,7 @@ LongParameterList:Comment.kt$Comment$( bot: Mobibot, cmd: String, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int ) LongParameterList:Comment.kt$Comment$( bot: Mobibot, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int ) LongParameterList:Comment.kt$Comment$(bot: Mobibot, cmd: String, sender: String, entry: EntryLink, index: Int, commentIndex: Int) + LongParameterList:Mobibot.kt$Mobibot$( nick: String, list: List<String>, maxPerLine: Int, isPrivate: Boolean, isBold: Boolean = false, isIndent: Boolean = false ) LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean ) MagicNumber:AddLog.kt$AddLog$4 MagicNumber:Comment.kt$Comment$3 diff --git a/src/main/java/net/thauvin/erik/mobibot/Addons.kt b/src/main/java/net/thauvin/erik/mobibot/Addons.kt index 04dfcd8..9c8e769 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Addons.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Addons.kt @@ -69,8 +69,8 @@ class Addons { */ fun add(command: AbstractCommand, props: Properties) { with(command) { - if (hasProperties()) { - getPropertyKeys().forEach { + if (properties.isNotEmpty()) { + properties.keys.forEach { setProperty(it, props.getProperty(it, "")) } } @@ -111,13 +111,14 @@ class Addons { /** * Match a command. */ - fun match(sender: String, login: String, message: String, isOp: Boolean, isPrivate: Boolean) { + fun match(sender: String, login: String, message: String, isOp: Boolean, isPrivate: Boolean): Boolean { for (command in commands) { if (command.matches(message)) { command.commandResponse(sender, login, message, isOp, isPrivate) - break + return true } } + return false } /** diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt index 7028c22..ca7caa6 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt @@ -397,10 +397,8 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert sleep(3) quitServer("The Bot Is Out There!") exitProcess(0) - } else { - if (!addons.exec(sender, login, cmd, args, isOp, true)) { - helpDefault(sender, isOp, true) - } + } else if (!addons.exec(sender, login, cmd, args, isOp, true)) { // Execute command or module + helpDefault(sender, isOp, true) } } @@ -463,13 +461,18 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert maxPerLine: Int, isPrivate: Boolean, isBold: Boolean = false, - isIndent: Boolean = false while (i < list.size) { + isIndent: Boolean = false + ) { + var i = 0 + while (i < list.size) { send( nick, helpFormat( list.subList(i, list.size.coerceAtMost(i + maxPerLine)).joinToString(" ", truncated = ""), isBold, - isIndent isPrivate + isIndent + ), + isPrivate ) i += maxPerLine } diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.kt b/src/main/java/net/thauvin/erik/mobibot/Utils.kt index b4b91f6..7bf1580 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.kt @@ -38,6 +38,7 @@ import java.io.BufferedReader import java.io.File import java.io.IOException import java.io.InputStreamReader +import java.lang.NumberFormatException import java.net.URL import java.net.URLEncoder import java.nio.charset.StandardCharsets @@ -60,12 +61,28 @@ object Utils { @JvmStatic fun bold(i: Int): String = bold(i.toString()) + /** + * Makes the given long bold. + */ + @JvmStatic + fun bold(i: Long): String = bold(i.toString()) + /** * Makes the given string bold. */ @JvmStatic fun bold(s: String?): String = colorize(s, Colors.BOLD) + /** + * Build a help command by replacing `%c` with the bot's pub/priv command, and `%n` with the bot's + * nick. + */ + @JvmStatic + fun buildCmdSyntax(text: String, botNick: String, isPrivate: Boolean): String { + val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick) + return StringUtils.replaceEach(text, searchFlags, replace) + } + /** * Colorize a string. */ @@ -89,6 +106,7 @@ object Utils { /** * URL encodes the given string. */ + @JvmStatic fun encodeUrl(s: String): String = URLEncoder.encode(s, StandardCharsets.UTF_8) /** @@ -120,14 +138,10 @@ object Utils { */ @JvmStatic fun getIntProperty(property: String?, def: Int): Int { - return if (property == null) { + return try { + property?.toInt() ?: def + } catch (nfe: NumberFormatException) { def - } else { - try { - property.toInt() - } catch (ignore: NumberFormatException) { - def - } } } @@ -170,6 +184,12 @@ object Utils { } else s } + /** + * Returns the plural form of a word, if count > 1. + */ + @JvmStatic + fun plural(count: Int, word: String, plural: String): String = plural(count.toLong(), word, plural) + /** * Returns the plural form of a word, if count > 1. */ @@ -269,10 +289,6 @@ object Utils { */ @JvmStatic fun utcDateTime(date: LocalDateTime?): String { - return if (date != null) { - date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")) - } else { - "" - } + return date?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")) ?: "" } } 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 862ca6a..338fbd6 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/AbstractCommand.kt @@ -43,7 +43,7 @@ abstract class AbstractCommand(val bot: Mobibot) { abstract val isPublic: Boolean abstract val isVisible: Boolean - private val properties: MutableMap = ConcurrentHashMap() + val properties: MutableMap = ConcurrentHashMap() abstract fun commandResponse( sender: String, @@ -63,18 +63,6 @@ abstract class AbstractCommand(val bot: Mobibot) { return false } - open fun getProperty(key: String): String? { - return properties[key] - } - - open fun getPropertyKeys(): Set { - return properties.keys - } - - open fun hasProperties(): Boolean { - return properties.isNotEmpty() - } - open fun initProperties(vararg keys: String) { keys.forEach { properties[it] = "" diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt b/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt index f371422..3eee724 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt @@ -40,7 +40,7 @@ class ChannelFeed(bot: Mobibot, channel: String) : AbstractCommand(bot) { override val name = channel override val help = listOf( "To list the last 5 posts from the channel's weblog feed:", - Utils.helpIndent("%c $channel") + Utils.helpFormat("%c $channel") ) override val isOp = false override val isPublic = true @@ -61,7 +61,7 @@ class ChannelFeed(bot: Mobibot, channel: String) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - with(getProperty(FEED_PROP)) { + with(properties[FEED_PROP]) { if (!isNullOrBlank()) { Thread(FeedReader(bot, sender, this)).start() } else { diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt index 9bf3630..fa6b462 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt @@ -32,12 +32,13 @@ package net.thauvin.erik.mobibot.commands +import net.thauvin.erik.mobibot.Constants import net.thauvin.erik.mobibot.Mobibot import org.apache.logging.log4j.Level import org.apache.logging.log4j.core.config.Configurator class Debug(bot: Mobibot) : AbstractCommand(bot) { - override val name = "debug" + override val name = Constants.DEBUG_CMD override val help = emptyList() override val isOp = true override val isPublic = false 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 91ea685..1187286 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt @@ -35,7 +35,6 @@ 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.LinksMgr -import java.util.* class Ignore(bot: Mobibot) : AbstractCommand(bot) { private val me = "me" @@ -67,7 +66,7 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) { companion object { const val IGNORE_CMD = "ignore" const val IGNORE_PROP = IGNORE_CMD - private val ignored = TreeSet() + private val ignored = mutableSetOf() @JvmStatic fun isNotIgnored(nick: String): Boolean { @@ -150,7 +149,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(LinksMgr.LINK_MATCH.toRegex())) + ignored.addAll(value.split(LinksMgr.TAG_MATCH.toRegex())) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java index a9bf07b..09043aa 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java @@ -43,7 +43,7 @@ import java.lang.management.ManagementFactory; import java.util.List; public class Info extends AbstractCommand { - private final List version = List.of( + private final List allVersions = List.of( StringUtils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION + " (" + Utils.green(ReleaseInfo.WEBSITE) + ')', "Written by " + ReleaseInfo.AUTHOR + " (" + Utils.green(ReleaseInfo.AUTHOR_URL) + ')'); @@ -102,7 +102,7 @@ public class Info extends AbstractCommand { } } - info.append(", Recap: ").append(Recap.recapCount()).append(']'); + info.append(", Recap: ").append(Recap.recaps.size()).append(']'); getBot().send(sender, info.toString(), 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 57477ef..d695e46 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Recap.kt @@ -48,19 +48,11 @@ class Recap(bot: Mobibot) : AbstractCommand(bot) { override val isVisible = true companion object { - private val recaps = mutableListOf() - - @JvmStatic - fun recapCount(): Int { - return recaps.size - } + @JvmField + val recaps = mutableListOf() /** * Stores the last 10 public messages and actions. - * - * @param sender The nick of the person who sent the private message. - * @param message The actual message sent. - * @param isAction Set to `true` if the message is an action. */ @JvmStatic fun storeRecap(sender: String, message: String, isAction: Boolean) { 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 e3a868a..9fab49e 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Users.kt @@ -34,7 +34,6 @@ package net.thauvin.erik.mobibot.commands import net.thauvin.erik.mobibot.Mobibot import net.thauvin.erik.mobibot.Utils -import org.jibble.pircbot.User class Users(bot: Mobibot) : AbstractCommand(bot) { override val name = "users" @@ -54,9 +53,8 @@ class Users(bot: Mobibot) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - val users: Array = bot.getUsers(bot.channel) val nicks = mutableListOf() - users.forEach { user -> + bot.getUsers(bot.channel).forEach { user -> if (bot.isOp(user.nick)) { nicks.add("@${user.nick}") } else { diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt index 374b9d5..80b4fbc 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt @@ -89,7 +89,7 @@ class LinksMgr(bot: Mobibot) : AbstractCommand(bot) { fun startup(current: String, backlogs: String, channel: String) { startDate = EntriesMgr.loadEntries(current, channel, entries) if (Utils.today() != startDate) { - this.entries.clear() + entries.clear() startDate = Utils.today() } EntriesMgr.loadBacklogs(backlogs, history) 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 5582fbb..12a3f8d 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 @@ -148,10 +148,10 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) { private fun showEntry(index: Int) { val entry: EntryLink = entries[index] bot.send(EntriesUtils.buildLink(index, entry)) - if (entry.hasTags()) { + if (entry.tags.isNotEmpty()) { bot.send(EntriesUtils.buildTags(index, entry)) } - if (entry.hasComments()) { + if (entry.comments.isNotEmpty()) { val comments = entry.comments for (i in comments.indices) { 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 e07fe21..14ae0d2 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 @@ -76,7 +76,7 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) { bot.send(sender, "Please ask a channel op to change the tags for you.", isPrivate) } } else { - if (entry.hasTags()) { + if (entry.tags.isNotEmpty()) { bot.send(EntriesUtils.buildTags(index, entry)) } else { 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/tell/Tell.kt b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt index af6a603..5627285 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt @@ -35,7 +35,7 @@ import net.thauvin.erik.mobibot.Mobibot import net.thauvin.erik.mobibot.Utils.bold import net.thauvin.erik.mobibot.Utils.getIntProperty import net.thauvin.erik.mobibot.Utils.helpFormat -import net.thauvin.erik.mobibot.Utils.helpIndent +import net.thauvin.erik.mobibot.Utils.buildCmdSyntax import net.thauvin.erik.mobibot.Utils.plural import net.thauvin.erik.mobibot.Utils.reverseColor import net.thauvin.erik.mobibot.Utils.utcDateTime @@ -63,7 +63,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { */ private fun clean(): Boolean { if (bot.logger.isDebugEnabled) bot.logger.debug("Cleaning the messages.") - return TellMessagesMgr.clean(messages, maxDays) + return TellMessagesMgr.clean(messages, maxDays.toLong()) } // Delete message. @@ -88,7 +88,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { } else { var found = false for (message in messages) { - found = message.isMatchId(id) + found = (message.id == id) if (found && (message.sender.equals(sender, ignoreCase = true) || bot.isOp(sender))) { messages.remove(message) save() @@ -122,7 +122,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { "To view queued and sent messages:", helpFormat("%c $name ${View.VIEW_CMD}"), "Messages are kept for " + bold(maxDays) - + plural(maxDays.toLong(), " day.", " days.") + + plural(maxDays, " day.", " days.") ) override val isOp: Boolean get() = false @@ -313,7 +313,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { ) bot.send( sender, - "Messages are kept for ${bold(maxDays)}${plural(maxDays.toLong(), " day.", " days.")}", + "Messages are kept for ${bold(maxDays)}${plural(maxDays, " day.", " days.")}", isPrivate ) } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt b/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt index 09dc5da..396b854 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt @@ -86,7 +86,6 @@ class TellMessage internal constructor( */ var receptionDate: LocalDateTime = LocalDateTime.MIN - /** * Matches the message sender or recipient. */ @@ -94,13 +93,6 @@ class TellMessage internal constructor( return sender.equals(nick, ignoreCase = true) || recipient.equals(nick, ignoreCase = true) } - /** - * Match the message ID. - */ - fun isMatchId(id: String): Boolean { - return this.id == id - } - override fun toString(): String { return ("TellMessage{id='$id', isNotified=$isNotified, isReceived=$isReceived, message='$message', " + "queued=$queued, received=$receptionDate, recipient='$recipient', sender='$sender'}") diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgr.kt b/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgr.kt index 8bc0b18..92e0e32 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgr.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgr.kt @@ -46,13 +46,13 @@ import java.time.LocalDateTime /** * The Tell Messages Manager. */ -internal object TellMessagesMgr { +object TellMessagesMgr { /** * Cleans the messages queue. */ - fun clean(tellMessages: MutableList, tellMaxDays: Int): Boolean { + fun clean(tellMessages: MutableList, tellMaxDays: Long): Boolean { val today = LocalDateTime.now(Clock.systemUTC()) - return tellMessages.removeIf { o: TellMessage -> o.queued.plusDays(tellMaxDays.toLong()).isBefore(today) } + return tellMessages.removeIf { o: TellMessage -> o.queued.plusDays(tellMaxDays).isBefore(today) } } /** diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt index d9ca531..5f83aa2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt @@ -57,7 +57,7 @@ object EntriesUtils { fun buildLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String { val buff = StringBuilder().append(buildLinkCmd(entryIndex)).append(": ") .append('[').append(entry.nick).append(']') - if (isView && entry.hasComments()) { + if (isView && entry.comments.isNotEmpty()) { buff.append("[+").append(entry.comments.size).append(']') } buff.append(' ') diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt b/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt index a33a180..b676591 100644 --- a/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt +++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt @@ -107,8 +107,8 @@ class EntryLink : Serializable { /** * Adds a new comment. */ - fun addComment(comment: String?, nick: String?): Int { - comments.add(EntryComment(comment!!, nick!!)) + fun addComment(comment: String, nick: String): Int { + comments.add(EntryComment(comment, nick)) return comments.size - 1 } @@ -139,16 +139,6 @@ class EntryLink : Serializable { return pinboardTags.toString() } - /** - * Returns true if the entry has comments. - */ - fun hasComments(): Boolean = comments.isNotEmpty() - - /** - * Returns true if the entry has tags. - */ - fun hasTags(): Boolean = tags.isNotEmpty() - /** * Returns true if a string is contained in the link, title, or nick. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Calc.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Calc.kt index b1ea6a2..5795480 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Calc.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Calc.kt @@ -75,6 +75,6 @@ class Calc(bot: Mobibot) : AbstractModule(bot) { init { commands.add(CALC_CMD) help.add("To solve a mathematical calculation:") - help.add(Utils.helpIndent("%c $CALC_CMD ")) + help.add(Utils.helpFormat("%c $CALC_CMD ")) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/ModuleException.kt b/src/main/java/net/thauvin/erik/mobibot/modules/ModuleException.kt index f9a3d81..3e77d96 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/ModuleException.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/ModuleException.kt @@ -80,14 +80,6 @@ class ModuleException : Exception { } } - /** - * Return `true` if the exception has a cause. - */ - @Suppress("unused") - fun hasCause(): Boolean { - return cause != null - } - companion object { private const val serialVersionUID = 1L } diff --git a/src/test/java/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt b/src/test/java/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt index 75a1139..57cdb46 100644 --- a/src/test/java/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt @@ -58,7 +58,6 @@ class TellMessageTest { Assertions.assertThat(tellMessage.isMatch(sender)).`as`("match sender").isTrue Assertions.assertThat(tellMessage.isMatch(recipient)).`as`("match recipient").isTrue Assertions.assertThat(tellMessage.isMatch("foo")).`as`("foo is no match").isFalse - Assertions.assertThat(tellMessage.isMatchId(tellMessage.id)).`as`("is match ID").isTrue tellMessage.isReceived = true Assertions.assertThat(tellMessage.isReceived).`as`("is received").isTrue Assertions.assertThat(isValidDate(tellMessage.receptionDate)).`as`("received is valid date/time").isTrue diff --git a/src/test/java/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt b/src/test/java/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt index d92b58f..7e710f0 100644 --- a/src/test/java/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt @@ -67,7 +67,7 @@ class EntryLinkTest { while (entryLink.comments.size > 0) { entryLink.deleteComment(r.nextInt(entryLink.comments.size)) } - Assertions.assertThat(entryLink.hasComments()).`as`("hasComments()").isFalse + Assertions.assertThat(entryLink.comments.isNotEmpty()).`as`("hasComments()").isFalse entryLink.addComment("nothing", "nobody") entryLink.setComment(0, "something", "somebody") Assertions.assertThat(entryLink.getComment(0).nick).`as`("getNick(somebody)").isEqualTo("somebody") @@ -81,7 +81,7 @@ class EntryLinkTest { Assertions.assertThat(tag.name).`as`("tag.getName($i)").isEqualTo("tag" + (i + 1)) } Assertions.assertThat(entryLink.tags.size).`as`("getTags().size() is 5").isEqualTo(5) - Assertions.assertThat(entryLink.hasTags()).`as`("hasTags() is true").isTrue + Assertions.assertThat(entryLink.tags.isNotEmpty()).`as`("hasTags() is true").isTrue entryLink.setTags("-tag5") entryLink.setTags("+mobitopia") entryLink.setTags("tag4") diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt b/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt index 8592447..6797682 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt @@ -62,7 +62,7 @@ class GoogleSearchTest : LocalProperties() { .`as`("no query").isInstanceOf(ModuleException::class.java).hasNoCause() } catch (e: ModuleException) { // Avoid displaying api keys in CI logs - if ("true" == System.getenv("CI") && !apiKey.isBlank() && !cseKey.isBlank()) { + if ("true" == System.getenv("CI") && apiKey.isNotBlank() && cseKey.isNotBlank()) { throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey, cseKey)) } else { throw e diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt index c47509b..08f12db 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt @@ -63,7 +63,7 @@ class StockQuoteTest : LocalProperties() { .isInstanceOf(ModuleException::class.java).hasNoCause() } catch (e: ModuleException) { // Avoid displaying api keys in CI logs - if ("true" == System.getenv("CI") && !apiKey.isBlank()) { + if ("true" == System.getenv("CI") && apiKey.isNotBlank()) { throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey)) } else { throw e