diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt index 0b633fa..6d37136 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt @@ -255,7 +255,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert send(sender, "For more information on a specific command, type:", isPrivate) send( sender, - helpIndent(helpFormat("""%c ${Constants.HELP_CMD} """, nick, isPrivate)), + helpIndent(helpFormat("%c ${Constants.HELP_CMD} ", nick, isPrivate)), isPrivate ) send(sender, "The commands are:", isPrivate) @@ -353,7 +353,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert logger.debug(">>> $sender: $message") tell.send(sender, true) if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: - val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2).toTypedArray() + val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2) val cmd = cmds[0].toLowerCase() val args = if (cmds.size > 1) { cmds[1].trim() @@ -399,7 +399,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert if (logger.isDebugEnabled) { logger.debug(">>> $sender : $message") } - val cmds = message.split(" ".toRegex(), 2).toTypedArray() + val cmds = message.split(" ".toRegex(), 2) val cmd = cmds[0].toLowerCase() val args = if (cmds.size > 1) { cmds[1].trim() @@ -503,7 +503,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert fun sendList( nick: String, list: List, - size: Int, + maxPerLine: Int, isPrivate: Boolean, isBold: Boolean ) { @@ -511,22 +511,16 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert while (i < list.size) { send( nick, - helpIndent(list.subList(i, list.size.coerceAtMost(i + size)).joinToString(" ", truncated = ""), isBold), + helpIndent( + list.subList(i, list.size.coerceAtMost(i + maxPerLine)).joinToString(" ", truncated = ""), + isBold + ), isPrivate ) - i += size + i += maxPerLine } } - /** - * Sets the bot's identification. - */ - private fun setIdentity(pwd: String, nick: String, msg: String) { - identPwd = pwd - identNick = nick - identMsg = msg - } - /** * Sets the pinboard authentication. */ @@ -690,7 +684,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert this.channel = channel logsDir = logsDirPath - // Set the logger level + // Set the default logger level loggerLevel = logger.level // Load the current entries and backlogs, if any @@ -707,7 +701,11 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert login = p.getProperty("login", name) version = ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION // setMessageDelay(1000); - setIdentity(p.getProperty("ident", ""), p.getProperty("ident-nick", ""), p.getProperty("ident-msg", "")) + + // Set NICKSERV identification + identPwd = p.getProperty("ident", "") + identNick = p.getProperty("ident-nick", "") + identMsg = p.getProperty("ident-msg", "") // Set the URLs weblogUrl = p.getProperty("weblog", "") diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt index 280d9aa..c0e97d0 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/tell/Tell.kt @@ -71,7 +71,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { // Delete message. private fun deleteMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) { - val split = args.split(" ").toTypedArray() + val split = args.split(" ") if (split.size == 2) { val id = split[1] var deleted = false @@ -176,7 +176,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { // New message. private fun newMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) { - val split = args.split(" ".toRegex(), 2).toTypedArray() + val split = args.split(" ".toRegex(), 2) if (split.size == 2 && split[1].isNotBlank() && split[1].contains(" ")) { if (messages.size < maxSize) { val message = TellMessage(sender, split[0], split[1].trim()) diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt b/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt index c041249..5d6eea2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt +++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntryLink.kt @@ -172,7 +172,7 @@ class EntryLink : Serializable { * Sets the tags. */ fun setTags(tags: String) { - setTags(tags.split(LinksMgr.TAG_MATCH).toTypedArray().toList()) + setTags(tags.split(LinksMgr.TAG_MATCH)) } /** diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt index 487981c..f15c184 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt @@ -152,7 +152,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) { */ @JvmStatic fun convertCurrency(query: String): Message { - val cmds = query.split(" ").toTypedArray() + val cmds = query.split(" ") return if (cmds.size == 4) { if (cmds[3] == cmds[1] || "0" == cmds[0]) { PublicMessage("You're kidding, right?") diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt index c46baf0..91954b6 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt @@ -126,13 +126,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) { /** * Performs a whois IP query. - * - * @param query The IP address. - * @return The IP whois data, if any. - * @throws java.io.IOException If a connection error occurs. */ @Throws(IOException::class) - private fun whois(query: String): Array { + private fun whois(query: String): List { return whois(query, WHOIS_HOST) } @@ -141,9 +137,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) { */ @JvmStatic @Throws(IOException::class) - fun whois(query: String, host: String): Array { + fun whois(query: String, host: String): List { val whoisClient = WhoisClient() - val lines: Array + val lines: List with(whoisClient) { try { defaultTimeout = Constants.CONNECT_TIMEOUT @@ -151,9 +147,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) { soTimeout = Constants.CONNECT_TIMEOUT setSoLinger(false, 0) lines = if (WHOIS_HOST == host) { - query("n - $query").split("\n").toTypedArray() + query("n - $query").split("\n") } else { - query(query).split("\n").toTypedArray() + query(query).split("\n") } } finally { disconnect() diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt index 023a4d9..5595519 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt @@ -107,7 +107,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { val messages = ArrayList() owm.unit = OWM.Unit.IMPERIAL if (query.isNotBlank()) { - val argv = query.split(",").toTypedArray() + val argv = query.split(",") if (argv.size in 1..2) { val city = argv[0].trim() val country: String = if (argv.size > 1 && argv[1].isNotBlank()) { diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/LookupTest.kt b/src/test/java/net/thauvin/erik/mobibot/modules/LookupTest.kt index 303a377..aad40e5 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/LookupTest.kt +++ b/src/test/java/net/thauvin/erik/mobibot/modules/LookupTest.kt @@ -52,7 +52,7 @@ class LookupTest { @Throws(Exception::class) fun testWhois() { val result = whois("17.178.96.59", Lookup.WHOIS_HOST) - Assertions.assertThat(Arrays.stream(result).anyMatch { m: String -> m.contains("Apple Inc.") }) + Assertions.assertThat(result.stream().anyMatch { m: String -> m.contains("Apple Inc.") }) .`as`("whois(17.178.96.59/Apple Inc.").isTrue } }