Cleaned up code

This commit is contained in:
Erik C. Thauvin 2023-11-01 22:02:54 -07:00
parent d700aa06df
commit 4c90870f4a
61 changed files with 496 additions and 481 deletions

View file

@ -128,12 +128,15 @@ object Utils {
isNullOrEmpty() -> {
""
}
color == DEFAULT_COLOR -> {
this
}
Colors.BOLD == color || Colors.REVERSE == color -> {
color + this + color
}
else -> {
color + this + Colors.NORMAL
}

View file

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

View file

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

View file

@ -89,6 +89,7 @@ class Tell(private val serialObject: String) : AbstractCommand() {
args.isBlank() -> {
helpResponse(channel, args, event)
}
args.startsWith(View.VIEW_CMD) -> {
if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) {
viewAll(event)
@ -96,9 +97,11 @@ class Tell(private val serialObject: String) : AbstractCommand() {
viewMessages(event)
}
}
args.startsWith("$TELL_DEL_KEYWORD ") -> {
deleteMessage(channel, args, event)
}
else -> {
newMessage(channel, args, event)
}

View file

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

View file

@ -46,6 +46,7 @@ data class EntryComment(var comment: String, var nick: String) : Serializable {
companion object {
// Serial version UID
@Suppress("ConstPropertyName")
private const val serialVersionUID: Long = 1L
}
}

View file

@ -207,6 +207,7 @@ class EntryLink(
companion object {
// Serial version UID
@Suppress("ConstPropertyName")
private const val serialVersionUID: Long = 1L
}
}

View file

@ -55,17 +55,17 @@ class FeedsManager private constructor() {
private val logger: Logger = LoggerFactory.getLogger(FeedsManager::class.java)
// The file containing the current entries.
private const val currentXml = "current.xml"
private const val CURRENT_XML = "current.xml"
// The .xml extension.
private const val dotXml = ".xml"
private const val DOT_XML = ".xml"
/**
* Loads the current feed.
*/
@JvmStatic
@Throws(IOException::class, FeedException::class)
fun loadFeed(entries: Entries, currentFile: String = currentXml): String {
fun loadFeed(entries: Entries, currentFile: String = CURRENT_XML): String {
entries.links.clear()
val xml = Paths.get("${entries.logsDir}${currentFile}")
var pubDate = today()
@ -110,7 +110,7 @@ class FeedsManager private constructor() {
* Saves the feeds.
*/
@JvmStatic
fun saveFeed(entries: Entries, currentFile: String = currentXml) {
fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML) {
if (logger.isDebugEnabled) logger.debug("Saving the feeds...")
if (entries.logsDir.isNotBlank()) {
try {
@ -167,7 +167,7 @@ class FeedsManager private constructor() {
OutputStreamWriter(
Files.newOutputStream(
Paths.get(
entries.logsDir + today() + dotXml
entries.logsDir + today() + DOT_XML
)
), StandardCharsets.UTF_8
).use { fw -> output.output(rss, fw) }

View file

@ -78,6 +78,7 @@ class CurrencyConverter : AbstractModule() {
SYMBOLS.isEmpty() -> {
event.respond(EMPTY_SYMBOLS_TABLE)
}
args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex()) -> {
val msg = convertCurrency(properties[API_KEY_PROP], args)
event.respond(msg.msg)
@ -85,10 +86,12 @@ class CurrencyConverter : AbstractModule() {
helpResponse(event)
}
}
args.contains(CODES_KEYWORD) -> {
event.sendMessage("The supported currency codes are:")
event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true)
}
else -> {
helpResponse(event)
}

View file

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

View file

@ -49,7 +49,7 @@ import org.testng.annotations.Test
/**
* The `CurrencyConvertTest` class.
*/
class CurrencyConverterTest: LocalProperties() {
class CurrencyConverterTest : LocalProperties() {
@BeforeClass
@Throws(ModuleException::class)
@ -62,22 +62,22 @@ class CurrencyConverterTest: LocalProperties() {
fun testConvertCurrency() {
val apiKey = getProperty(CurrencyConverter.API_KEY_PROP)
assertThat(
convertCurrency(apiKey,"100 USD to EUR").msg,
convertCurrency(apiKey, "100 USD to EUR").msg,
"convertCurrency(100 USD to EUR)"
).matches("100 United States Dollar = \\d{2,3}\\.\\d{2,3} Euro".toRegex())
assertThat(
convertCurrency(apiKey,"1 USD to GBP").msg,
convertCurrency(apiKey, "1 USD to GBP").msg,
"convertCurrency(1 USD to BGP)"
).matches("1 United States Dollar = 0\\.\\d{2,3} Pound Sterling".toRegex())
assertThat(
convertCurrency(apiKey,"100,000.00 CAD to USD").msg,
convertCurrency(apiKey, "100,000.00 CAD to USD").msg,
"convertCurrency(100,000.00 GBP to USD)"
).matches("100,000.00 Canadian Dollar = \\d+\\.\\d{2,3} United States Dollar".toRegex())
assertThat(convertCurrency(apiKey,"100 USD to USD"), "convertCurrency(100 USD to USD)").all {
assertThat(convertCurrency(apiKey, "100 USD to USD"), "convertCurrency(100 USD to USD)").all {
prop(Message::msg).contains("You're kidding, right?")
isInstanceOf(PublicMessage::class.java)
}
assertThat(convertCurrency(apiKey,"100 USD"), "convertCurrency(100 USD)").all {
assertThat(convertCurrency(apiKey, "100 USD"), "convertCurrency(100 USD)").all {
prop(Message::msg).contains("Invalid query.")
isInstanceOf(ErrorMessage::class.java)
}

View file

@ -44,33 +44,33 @@ import java.lang.reflect.Method
*/
class ModuleExceptionTest {
companion object {
const val debugMessage = "debugMessage"
const val message = "message"
const val DEBUG_MESSAGE = "debugMessage"
const val MESSAGE = "message"
}
@DataProvider(name = "dp")
fun createData(@Suppress("UNUSED_PARAMETER") m: Method?): Array<Array<Any>> {
return arrayOf(
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com"))),
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com?"))),
arrayOf(ModuleException(debugMessage, message))
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com"))),
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com?"))),
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE))
)
}
@Test(dataProvider = "dp")
fun testGetDebugMessage(e: ModuleException) {
assertThat(e::debugMessage).isEqualTo(debugMessage)
assertThat(e::debugMessage).isEqualTo(DEBUG_MESSAGE)
}
@Test(dataProvider = "dp")
fun testGetMessage(e: ModuleException) {
assertThat(e).hasMessage(message)
assertThat(e).hasMessage(MESSAGE)
}
@Test(groups = ["modules"])
fun testSanitizeMessage() {
val apiKey = "1234567890"
var e = ModuleException(debugMessage, message, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
var e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
assertThat(
e.sanitize(apiKey, "", "me").message, "ModuleException(debugMessage, message, IOException(url))"
).isNotNull().all {
@ -78,21 +78,21 @@ class ModuleExceptionTest {
doesNotContain(apiKey, "me")
}
e = ModuleException(debugMessage, message, null)
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(message)
e = ModuleException(DEBUG_MESSAGE, MESSAGE, null)
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(MESSAGE)
e = ModuleException(debugMessage, message, IOException())
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(message)
e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException())
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(MESSAGE)
e = ModuleException(debugMessage, apiKey)
e = ModuleException(DEBUG_MESSAGE, apiKey)
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, apiKey)").isNotNull()
.doesNotContain(apiKey)
val msg: String? = null
e = ModuleException(debugMessage, msg, IOException(msg))
e = ModuleException(DEBUG_MESSAGE, msg, IOException(msg))
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, msg, IOException(msg))").isNull()
e = ModuleException(debugMessage, msg, IOException("foo is $apiKey"))
e = ModuleException(DEBUG_MESSAGE, msg, IOException("foo is $apiKey"))
assertThat(
e.sanitize(" ", apiKey, "foo").message,
"ModuleException(debugMessage, msg, IOException(foo is $apiKey))"