Minor cleanups

This commit is contained in:
Erik C. Thauvin 2025-05-07 22:41:16 -07:00
parent dd68ef111b
commit 1ec08e732b
Signed by: erik
GPG key ID: 776702A6A2DA330E
16 changed files with 31 additions and 24 deletions

View file

@ -76,7 +76,7 @@ object Constants {
const val NO_TITLE = "No Title" const val NO_TITLE = "No Title"
/** /**
* Properties command line argument. * `Properties` command line argument.
*/ */
const val PROPS_ARG = "properties" const val PROPS_ARG = "properties"

View file

@ -43,8 +43,8 @@ import net.thauvin.erik.mobibot.entries.EntryLink
import org.pircbotx.hooks.types.GenericMessageEvent import org.pircbotx.hooks.types.GenericMessageEvent
/** /**
* Processes commands such as viewing, deleting, editing, or changing the author of a comment * Processes commands such as viewing, deleting, editing, or changing the author of a comment based on the input
* based on the input arguments and the state of the entries. * arguments and the state of the entries.
*/ */
class Comment : AbstractCommand() { class Comment : AbstractCommand() {
override val name = COMMAND override val name = COMMAND

View file

@ -42,6 +42,7 @@ class NickComparator : Comparator<String>, Serializable {
} }
companion object { companion object {
@Suppress("unused")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -38,6 +38,7 @@ import java.io.Serializable
*/ */
data class SeenNick(val nick: String, val lastSeen: Long) : Serializable { data class SeenNick(val nick: String, val lastSeen: Long) : Serializable {
companion object { companion object {
@Suppress("unused")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -284,7 +284,7 @@ class Tell(private val serialObject: String) : AbstractCommand() {
// Arrow // Arrow
private const val ARROW = " --> " private const val ARROW = " --> "
// All keyword // The `all` keyword
private const val TELL_ALL_KEYWORD = "all" private const val TELL_ALL_KEYWORD = "all"
// The delete command. // The delete command.

View file

@ -98,6 +98,7 @@ class TellMessage(
} }
companion object { companion object {
@Suppress("unused")
private const val serialVersionUID = 2L private const val serialVersionUID = 2L
} }
} }

View file

@ -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 @JvmStatic
fun printTags(entryIndex: Int, entry: EntryLink): String = fun printTags(entryIndex: Int, entry: EntryLink): String =
entryIndex.toLinkLabel() + "${Constants.TAG_CMD}: " + entry.formatTags(", ") 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 @JvmStatic
fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1) fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1)

View file

@ -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'}" override fun toString(): String = "EntryComment{comment='$comment', date=$date, nick='$nick'}"
companion object { companion object {
// Serial version UID @Suppress("unused")
private const val serialVersionUID: Long = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -93,8 +93,8 @@ class EntryLink(
} }
companion object { companion object {
// Serial version UID @Suppress("unused")
private const val serialVersionUID: Long = 1L private const val serialVersionUID = 1L
} }
/** /**

View file

@ -52,7 +52,7 @@ class Calc : AbstractModule() {
private const val CALC_CMD = "calc" private const val CALC_CMD = "calc"
/** /**
* Performs a calculation. e.g.: 1 + 1 * 2 * Performs a calculation (e.g.: 1 + 1 * 2)
*/ */
@JvmStatic @JvmStatic
@Throws(IllegalArgumentException::class) @Throws(IllegalArgumentException::class)

View file

@ -59,7 +59,7 @@ class ChatGpt2 : AbstractModule() {
const val API_KEY_PROP = "chatgpt-api-key" const val API_KEY_PROP = "chatgpt-api-key"
/** /**
* The max tokens property. * The max-tokens property.
*/ */
const val MAX_TOKENS_PROP = "chatgpt-max-tokens" const val MAX_TOKENS_PROP = "chatgpt-max-tokens"

View file

@ -53,8 +53,6 @@ import java.util.*
* Converts between currencies. * Converts between currencies.
*/ */
class CurrencyConverter : AbstractModule() { class CurrencyConverter : AbstractModule() {
private val logger: Logger = LoggerFactory.getLogger(CurrencyConverter::class.java)
override val name = "CurrencyConverter" override val name = "CurrencyConverter"
companion object { companion object {
@ -69,15 +67,18 @@ class CurrencyConverter : AbstractModule() {
// Currency codes keyword // Currency codes keyword
private const val CODES_KEYWORD = "codes" private const val CODES_KEYWORD = "codes"
// Decimal format
private val DECIMAL_FORMAT = DecimalFormat("0.00#")
// Empty symbols table. // Empty symbols table.
private const val EMPTY_SYMBOLS_TABLE = "Sorry, but the currency table is empty." 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 // Currency symbols
private val SYMBOLS: TreeMap<String, String> = TreeMap() private val SYMBOLS: TreeMap<String, String> = TreeMap()
// Decimal format
private val DECIMAL_FORMAT = DecimalFormat("0.00#")
/** /**
* Converts from a currency to another. * Converts from a currency to another.
*/ */
@ -109,7 +110,10 @@ class CurrencyConverter : AbstractModule() {
} else { } else {
ErrorMessage("Sorry, an error occurred while converting the currencies.") 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.") ErrorMessage("Sorry, an IO error occurred while converting the currencies.")
} }
} else { } else {
@ -161,7 +165,7 @@ class CurrencyConverter : AbstractModule() {
try { try {
loadSymbols(apiKey) loadSymbols(apiKey)
} catch (e: ModuleException) { } catch (e: ModuleException) {
if (logger.isWarnEnabled) logger.warn(e.debugMessage, e) if (LOGGER.isWarnEnabled) LOGGER.warn(e.debugMessage, e)
} }
} }
} }

View file

@ -36,6 +36,7 @@ class ModuleException @JvmOverloads constructor(
cause: Throwable? = null cause: Throwable? = null
) : Exception(message, cause) { ) : Exception(message, cause) {
companion object { companion object {
@Suppress("unused")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -65,7 +65,7 @@ class WolframAlpha : AbstractModule() {
private const val WOLFRAM_CMD = "wolfram" private const val WOLFRAM_CMD = "wolfram"
// Wolfram Alpha API URL // 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 @JvmStatic
@Throws(ModuleException::class) @Throws(ModuleException::class)

View file

@ -328,7 +328,7 @@ class WorldTime : AbstractModule() {
// The Time command // The Time command
private const val TIME_CMD = "time" private const val TIME_CMD = "time"
// The zones arguments // The `zones` arguments
private const val ZONES_ARGS = "zones" private const val ZONES_ARGS = "zones"
// The default zone // The default zone

View file

@ -41,8 +41,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
/** /**
* Provides the ability to handle notifications, post entries and manage interaction with a specific social media * Provides the ability to handle notifications, entries and manage interaction with a specific social media service.
* service.
*/ */
abstract class SocialModule : AbstractModule() { abstract class SocialModule : AbstractModule() {
private val logger: Logger = LoggerFactory.getLogger(SocialManager::class.java) 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 abstract fun post(message: String, isDm: Boolean): String
/** /**
* Post entry to social media. * Post an entry to social media.
*/ */
fun postEntry(index: Int) { fun postEntry(index: Int) {
if (isAutoPost && LinksManager.entries.links.size >= index) { if (isAutoPost && LinksManager.entries.links.size >= index) {