Code cleanup.
This commit is contained in:
parent
ea40d71f14
commit
4abdb268ef
5 changed files with 11 additions and 23 deletions
|
@ -50,8 +50,6 @@ import java.time.format.DateTimeFormatter
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
import kotlin.time.DurationUnit
|
|
||||||
import kotlin.time.toDuration
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous utilities.
|
* Miscellaneous utilities.
|
||||||
|
@ -97,16 +95,6 @@ object Utils {
|
||||||
return getBot() as PircBotX
|
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.
|
* Capitalize a string.
|
||||||
*/
|
*/
|
||||||
|
@ -116,9 +104,9 @@ object Utils {
|
||||||
/**
|
/**
|
||||||
* Capitalize words
|
* Capitalize words
|
||||||
*/
|
*/
|
||||||
|
@JvmStatic
|
||||||
fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() }
|
fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colorize a string.
|
* Colorize a string.
|
||||||
*/
|
*/
|
||||||
|
@ -254,6 +242,7 @@ object Utils {
|
||||||
* Send a formatted commands/modules, etc. list.
|
* Send a formatted commands/modules, etc. list.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
fun GenericMessageEvent.sendList(
|
fun GenericMessageEvent.sendList(
|
||||||
list: List<String>,
|
list: List<String>,
|
||||||
maxPerLine: Int,
|
maxPerLine: Int,
|
||||||
|
|
|
@ -54,9 +54,6 @@ class Die : AbstractCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
|
||||||
* Max days property.
|
|
||||||
*/
|
|
||||||
const val DIE_PROP = "die"
|
const val DIE_PROP = "die"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,6 @@ class Tags : AbstractCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun matches(message: String): Boolean {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,8 +96,8 @@ class Weather2 : ThreadedModule() {
|
||||||
/**
|
/**
|
||||||
* Converts and rounds temperature from °F to °C.
|
* Converts and rounds temperature from °F to °C.
|
||||||
*/
|
*/
|
||||||
fun ftoC(d: Double?): Pair<Int, Int> {
|
fun ftoC(d: Double): Pair<Int, Int> {
|
||||||
val c = (d!! - 32) * 5 / 9
|
val c = (d - 32) * 5 / 9
|
||||||
return d.roundToInt() to c.roundToInt()
|
return d.roundToInt() to c.roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +154,10 @@ class Weather2 : ThreadedModule() {
|
||||||
cwd.mainData?.let {
|
cwd.mainData?.let {
|
||||||
with(it) {
|
with(it) {
|
||||||
if (hasTemp()) {
|
if (hasTemp()) {
|
||||||
val t = ftoC(temp)
|
temp?.let { t ->
|
||||||
messages.add(PublicMessage("Temperature: ${t.first}°F, ${t.second}°C"))
|
val (f, c) = ftoC(t)
|
||||||
|
messages.add(PublicMessage("Temperature: ${f}°F, ${c}°C"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (hasHumidity()) {
|
if (hasHumidity()) {
|
||||||
humidity?.let { h ->
|
humidity?.let { h ->
|
||||||
|
|
|
@ -48,11 +48,11 @@ object ExceptionSanitizer {
|
||||||
if (!cause?.message.isNullOrBlank()) {
|
if (!cause?.message.isNullOrBlank()) {
|
||||||
return ModuleException(
|
return ModuleException(
|
||||||
debugMessage,
|
debugMessage,
|
||||||
cause!!.javaClass.name + ": " + cause!!.message!!.replaceEach(search, obfuscate),
|
cause?.javaClass?.name + ": " + cause?.message?.replaceEach(search, obfuscate),
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
} else if (!message.isNullOrBlank()) {
|
} else if (!message.isNullOrBlank()) {
|
||||||
return ModuleException(debugMessage, message!!.replaceEach(search, obfuscate), this)
|
return ModuleException(debugMessage, message?.replaceEach(search, obfuscate), this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue