Code cleanup.

This commit is contained in:
Erik C. Thauvin 2022-02-14 22:38:51 -08:00
parent ea40d71f14
commit 4abdb268ef
5 changed files with 11 additions and 23 deletions

View file

@ -50,8 +50,6 @@ import java.time.format.DateTimeFormatter
import java.util.Date
import java.util.Properties
import java.util.stream.Collectors
import kotlin.time.DurationUnit
import kotlin.time.toDuration
/**
* Miscellaneous utilities.
@ -97,16 +95,6 @@ object Utils {
return getBot() as PircBotX
}
/**
* 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 text.replaceEach(searchFlags, replace)
}
/**
* Capitalize a string.
*/
@ -116,9 +104,9 @@ object Utils {
/**
* Capitalize words
*/
@JvmStatic
fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() }
/**
* Colorize a string.
*/
@ -254,6 +242,7 @@ object Utils {
* Send a formatted commands/modules, etc. list.
*/
@JvmStatic
@JvmOverloads
fun GenericMessageEvent.sendList(
list: List<String>,
maxPerLine: Int,

View file

@ -54,9 +54,6 @@ class Die : AbstractCommand() {
}
companion object {
/**
* Max days property.
*/
const val DIE_PROP = "die"
}

View file

@ -83,6 +83,6 @@ class Tags : AbstractCommand() {
}
override fun matches(message: String): Boolean {
return message.matches("^${Constants.LINK_CMD}[0-9]+${Constants.TAG_CMD}:.*".toRegex())
return message.matches("^${Constants.LINK_CMD}\\d+${Constants.TAG_CMD}:.*".toRegex())
}
}

View file

@ -96,8 +96,8 @@ class Weather2 : ThreadedModule() {
/**
* Converts and rounds temperature from °F to °C.
*/
fun ftoC(d: Double?): Pair<Int, Int> {
val c = (d!! - 32) * 5 / 9
fun ftoC(d: Double): Pair<Int, Int> {
val c = (d - 32) * 5 / 9
return d.roundToInt() to c.roundToInt()
}
@ -154,8 +154,10 @@ class Weather2 : ThreadedModule() {
cwd.mainData?.let {
with(it) {
if (hasTemp()) {
val t = ftoC(temp)
messages.add(PublicMessage("Temperature: ${t.first}°F, ${t.second}°C"))
temp?.let { t ->
val (f, c) = ftoC(t)
messages.add(PublicMessage("Temperature: ${f}°F, ${c}°C"))
}
}
if (hasHumidity()) {
humidity?.let { h ->

View file

@ -48,11 +48,11 @@ object ExceptionSanitizer {
if (!cause?.message.isNullOrBlank()) {
return ModuleException(
debugMessage,
cause!!.javaClass.name + ": " + cause!!.message!!.replaceEach(search, obfuscate),
cause?.javaClass?.name + ": " + cause?.message?.replaceEach(search, obfuscate),
this
)
} else if (!message.isNullOrBlank()) {
return ModuleException(debugMessage, message!!.replaceEach(search, obfuscate), this)
return ModuleException(debugMessage, message?.replaceEach(search, obfuscate), this)
}
}
}