Minor cleanup

This commit is contained in:
Erik C. Thauvin 2023-01-12 00:57:20 -08:00
parent 6894e05610
commit 66ca972b9b
12 changed files with 44 additions and 42 deletions

View file

@ -47,7 +47,6 @@ import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.net.HttpURLConnection
import java.net.URL
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.time.LocalDateTime
@ -189,7 +188,7 @@ object Utils {
}
/**
* Returns {@code true} if the specified user is an operator on the [channel].
* Returns `true` if the specified user is an operator on the [channel].
*/
@JvmStatic
fun GenericMessageEvent.isChannelOp(channel: String): Boolean {
@ -197,7 +196,7 @@ object Utils {
}
/**
* Returns {@code true} if a HTTP status code indicates a successful response.
* Returns `true` if a HTTP status code indicates a successful response.
*/
@JvmStatic
fun Int.isHttpSuccess() = this in 200..399
@ -214,10 +213,10 @@ object Utils {
}
/**
* Load data.
* Load serial data from file.
*/
@JvmStatic
fun loadData(file: String, default: Any, logger: Logger, description: String): Any {
fun loadSerialData(file: String, default: Any, logger: Logger, description: String): Any {
val serialFile = Paths.get(file)
if (serialFile.exists() && serialFile.fileSize() > 0) {
try {
@ -237,7 +236,7 @@ object Utils {
}
/**
* Returns {@code true} if the list does not contain the given string.
* Returns `true` if the list does not contain the given string.
*/
@JvmStatic
fun List<String>.notContains(text: String, ignoreCase: Boolean = false) = this.none { it.equals(text, ignoreCase) }
@ -290,7 +289,7 @@ object Utils {
* Save data
*/
@JvmStatic
fun saveData(file: String, data: Any, logger: Logger, description: String) {
fun saveSerialData(file: String, data: Any, logger: Logger, description: String) {
try {
BufferedOutputStream(Files.newOutputStream(Paths.get(file))).use { bos ->
ObjectOutputStream(bos).use { output ->

View file

@ -35,8 +35,8 @@ package net.thauvin.erik.mobibot.commands.seen
import com.google.common.collect.ImmutableSortedSet
import net.thauvin.erik.mobibot.Utils.bot
import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.Utils.loadData
import net.thauvin.erik.mobibot.Utils.saveData
import net.thauvin.erik.mobibot.Utils.loadSerialData
import net.thauvin.erik.mobibot.Utils.saveSerialData
import net.thauvin.erik.mobibot.Utils.sendMessage
import net.thauvin.erik.mobibot.commands.AbstractCommand
import net.thauvin.erik.mobibot.commands.Info.Companion.toUptime
@ -107,7 +107,7 @@ class Seen(private val serialObject: String) : AbstractCommand() {
if (isEnabled()) {
@Suppress("UNCHECKED_CAST")
seenNicks.putAll(
loadData(
loadSerialData(
serialObject,
TreeMap<String, SeenNick>(),
logger,
@ -118,7 +118,7 @@ class Seen(private val serialObject: String) : AbstractCommand() {
}
fun save() {
saveData(serialObject, seenNicks, logger, "seen nicknames")
saveSerialData(serialObject, seenNicks, logger, "seen nicknames")
}
init {

View file

@ -31,8 +31,8 @@
*/
package net.thauvin.erik.mobibot.commands.tell
import net.thauvin.erik.mobibot.Utils.loadData
import net.thauvin.erik.mobibot.Utils.saveData
import net.thauvin.erik.mobibot.Utils.loadSerialData
import net.thauvin.erik.mobibot.Utils.saveSerialData
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Clock
@ -60,7 +60,7 @@ object TellManager {
@JvmStatic
fun load(file: String): List<TellMessage> {
@Suppress("UNCHECKED_CAST")
return loadData(file, emptyList<TellMessage>(), logger, "message queue") as List<TellMessage>
return loadSerialData(file, emptyList<TellMessage>(), logger, "message queue") as List<TellMessage>
}
/**
@ -69,7 +69,7 @@ object TellManager {
@JvmStatic
fun save(file: String, messages: List<TellMessage?>?) {
if (messages != null) {
saveData(file, messages, logger, "messages")
saveSerialData(file, messages, logger, "messages")
}
}
}

View file

@ -66,12 +66,12 @@ class TellMessage(
var id: String = queued.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
/**
* Returns {@code true} if a notification was sent.
* Returns `true` if a notification was sent.
*/
var isNotified = false
/**
* Returns {@code true} if the message was received.
* Returns `true` if the message was received.
*/
var isReceived = false
set(value) {

View file

@ -130,8 +130,8 @@ class EntryLink(
/**
* Formats the tags.
*/
fun formatTags(sep: String, prefix: String = "") : String {
return tags.joinToString(separator = sep, prefix = prefix){it.name}
fun formatTags(sep: String, prefix: String = ""): String {
return tags.joinToString(separator = sep, prefix = prefix) { it.name }
}
/**