From 1ec08e732b176061eb2fc58d1ca3b560dd5e8552 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 7 May 2025 22:41:16 -0700 Subject: [PATCH] Minor cleanups --- .../net/thauvin/erik/mobibot/Constants.kt | 2 +- .../erik/mobibot/commands/links/Comment.kt | 4 ++-- .../mobibot/commands/seen/NickComparator.kt | 1 + .../erik/mobibot/commands/seen/SeenNick.kt | 1 + .../thauvin/erik/mobibot/commands/tell/Tell.kt | 2 +- .../erik/mobibot/commands/tell/TellMessage.kt | 1 + .../erik/mobibot/entries/EntriesUtils.kt | 4 ++-- .../erik/mobibot/entries/EntryComment.kt | 4 ++-- .../thauvin/erik/mobibot/entries/EntryLink.kt | 4 ++-- .../net/thauvin/erik/mobibot/modules/Calc.kt | 2 +- .../thauvin/erik/mobibot/modules/ChatGpt2.kt | 2 +- .../erik/mobibot/modules/CurrencyConverter.kt | 18 +++++++++++------- .../erik/mobibot/modules/ModuleException.kt | 1 + .../erik/mobibot/modules/WolframAlpha.kt | 2 +- .../thauvin/erik/mobibot/modules/WorldTime.kt | 2 +- .../erik/mobibot/social/SocialModule.kt | 5 ++--- 16 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt index 9dab63f..6ee3e08 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt @@ -76,7 +76,7 @@ object Constants { const val NO_TITLE = "No Title" /** - * Properties command line argument. + * `Properties` command line argument. */ const val PROPS_ARG = "properties" diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Comment.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Comment.kt index 703f562..5fea73a 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Comment.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Comment.kt @@ -43,8 +43,8 @@ import net.thauvin.erik.mobibot.entries.EntryLink import org.pircbotx.hooks.types.GenericMessageEvent /** - * Processes commands such as viewing, deleting, editing, or changing the author of a comment - * based on the input arguments and the state of the entries. + * Processes commands such as viewing, deleting, editing, or changing the author of a comment based on the input + * arguments and the state of the entries. */ class Comment : AbstractCommand() { override val name = COMMAND diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/NickComparator.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/NickComparator.kt index 7e987e4..79f7475 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/NickComparator.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/NickComparator.kt @@ -42,6 +42,7 @@ class NickComparator : Comparator, Serializable { } companion object { + @Suppress("unused") private const val serialVersionUID = 1L } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenNick.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenNick.kt index 6937ee9..fd38e92 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenNick.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenNick.kt @@ -38,6 +38,7 @@ import java.io.Serializable */ data class SeenNick(val nick: String, val lastSeen: Long) : Serializable { companion object { + @Suppress("unused") private const val serialVersionUID = 1L } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt index 7f36b64..32821d0 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt @@ -284,7 +284,7 @@ class Tell(private val serialObject: String) : AbstractCommand() { // Arrow private const val ARROW = " --> " - // All keyword + // The `all` keyword private const val TELL_ALL_KEYWORD = "all" // The delete command. diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt index 2756ae6..9c263eb 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt @@ -98,6 +98,7 @@ class TellMessage( } companion object { + @Suppress("unused") private const val serialVersionUID = 2L } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt index 07b4687..cac0243 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt @@ -69,14 +69,14 @@ object EntriesUtils { } /** - * Prints an entry's tags/categories for display on the channel. e.g. L1T: tag1, tag2 + * Prints an entry's tags/categories for display on the channel. (e.g., L1T: tag1, tag2) */ @JvmStatic fun printTags(entryIndex: Int, entry: EntryLink): String = entryIndex.toLinkLabel() + "${Constants.TAG_CMD}: " + entry.formatTags(", ") /** - * Builds link label based on its index. e.g: L1 + * Builds link label based on its index. (e.g., L1) */ @JvmStatic fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryComment.kt b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryComment.kt index 80a9309..80802a9 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryComment.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryComment.kt @@ -45,7 +45,7 @@ data class EntryComment(var comment: String, var nick: String) : Serializable { override fun toString(): String = "EntryComment{comment='$comment', date=$date, nick='$nick'}" companion object { - // Serial version UID - private const val serialVersionUID: Long = 1L + @Suppress("unused") + private const val serialVersionUID = 1L } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryLink.kt b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryLink.kt index 01b38f6..8d026a1 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryLink.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntryLink.kt @@ -93,8 +93,8 @@ class EntryLink( } companion object { - // Serial version UID - private const val serialVersionUID: Long = 1L + @Suppress("unused") + private const val serialVersionUID = 1L } /** diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt index 80e6d3e..636bd92 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt @@ -52,7 +52,7 @@ class Calc : AbstractModule() { private const val CALC_CMD = "calc" /** - * Performs a calculation. e.g.: 1 + 1 * 2 + * Performs a calculation (e.g.: 1 + 1 * 2) */ @JvmStatic @Throws(IllegalArgumentException::class) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/ChatGpt2.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/ChatGpt2.kt index a18875c..c31cbaf 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/ChatGpt2.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/ChatGpt2.kt @@ -59,7 +59,7 @@ class ChatGpt2 : AbstractModule() { const val API_KEY_PROP = "chatgpt-api-key" /** - * The max tokens property. + * The max-tokens property. */ const val MAX_TOKENS_PROP = "chatgpt-max-tokens" diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt index ddc9375..f0fe844 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt @@ -53,8 +53,6 @@ import java.util.* * Converts between currencies. */ class CurrencyConverter : AbstractModule() { - private val logger: Logger = LoggerFactory.getLogger(CurrencyConverter::class.java) - override val name = "CurrencyConverter" companion object { @@ -69,15 +67,18 @@ class CurrencyConverter : AbstractModule() { // Currency codes keyword private const val CODES_KEYWORD = "codes" + // Decimal format + private val DECIMAL_FORMAT = DecimalFormat("0.00#") + // Empty symbols table. private const val EMPTY_SYMBOLS_TABLE = "Sorry, but the currency table is empty." + // Logger + private val LOGGER: Logger = LoggerFactory.getLogger(CurrencyConverter::class.java) + // Currency symbols private val SYMBOLS: TreeMap = TreeMap() - // Decimal format - private val DECIMAL_FORMAT = DecimalFormat("0.00#") - /** * Converts from a currency to another. */ @@ -109,7 +110,10 @@ class CurrencyConverter : AbstractModule() { } else { ErrorMessage("Sorry, an error occurred while converting the currencies.") } - } catch (ignore: IOException) { + } catch (ioe: IOException) { + if (LOGGER.isWarnEnabled) { + LOGGER.warn("IO error while converting currencies: ${ioe.message}", ioe) + } ErrorMessage("Sorry, an IO error occurred while converting the currencies.") } } else { @@ -161,7 +165,7 @@ class CurrencyConverter : AbstractModule() { try { loadSymbols(apiKey) } catch (e: ModuleException) { - if (logger.isWarnEnabled) logger.warn(e.debugMessage, e) + if (LOGGER.isWarnEnabled) LOGGER.warn(e.debugMessage, e) } } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/ModuleException.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/ModuleException.kt index e6a4147..2f6d4e3 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/ModuleException.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/ModuleException.kt @@ -36,6 +36,7 @@ class ModuleException @JvmOverloads constructor( cause: Throwable? = null ) : Exception(message, cause) { companion object { + @Suppress("unused") private const val serialVersionUID = 1L } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt index 4043e49..bc05a0a 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt @@ -65,7 +65,7 @@ class WolframAlpha : AbstractModule() { private const val WOLFRAM_CMD = "wolfram" // Wolfram Alpha API URL - private const val API_URL = "http://api.wolframalpha.com/v1/spoken?appid=" + private const val API_URL = "https://api.wolframalpha.com/v1/spoken?appid=" @JvmStatic @Throws(ModuleException::class) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt index 82b57db..3c73703 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt @@ -328,7 +328,7 @@ class WorldTime : AbstractModule() { // The Time command private const val TIME_CMD = "time" - // The zones arguments + // The `zones` arguments private const val ZONES_ARGS = "zones" // The default zone diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/social/SocialModule.kt b/src/main/kotlin/net/thauvin/erik/mobibot/social/SocialModule.kt index bcc1ef3..1950916 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/social/SocialModule.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/social/SocialModule.kt @@ -41,8 +41,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory /** - * Provides the ability to handle notifications, post entries and manage interaction with a specific social media - * service. + * Provides the ability to handle notifications, entries and manage interaction with a specific social media service. */ abstract class SocialModule : AbstractModule() { private val logger: Logger = LoggerFactory.getLogger(SocialManager::class.java) @@ -69,7 +68,7 @@ abstract class SocialModule : AbstractModule() { abstract fun post(message: String, isDm: Boolean): String /** - * Post entry to social media. + * Post an entry to social media. */ fun postEntry(index: Int) { if (isAutoPost && LinksManager.entries.links.size >= index) {