diff --git a/build.gradle b/build.gradle index 8bc47e5..1702a51 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,8 @@ plugins { id 'jacoco' id 'java' id 'net.thauvin.erik.gradle.semver' version '1.0.4' - id 'org.jetbrains.kotlin.jvm' version '1.4.31' - id 'org.jetbrains.kotlin.kapt' version '1.4.31' + id 'org.jetbrains.kotlin.jvm' version '1.5.0' + id 'org.jetbrains.kotlin.kapt' version '1.5.0' id 'org.sonarqube' version '3.1.1' id 'pmd' } @@ -23,8 +23,8 @@ final def semverProcessor = "net.thauvin.erik:semver:1.2.0" ext.versions = [ jacoco : '0.8.6', log4j : '2.14.1', - pmd : '6.32.0', - spotbugs: '4.2.2' + pmd : '6.34.0', + spotbugs: '4.2.3' ] repositories { @@ -44,12 +44,12 @@ dependencies { implementation 'com.rometools:rome:1.15.0' implementation 'commons-cli:commons-cli:1.4' - implementation 'commons-net:commons-net:3.7.2' + implementation 'commons-net:commons-net:3.8.0' implementation 'net.aksingh:owm-japis:2.5.3.0' implementation 'net.objecthunter:exp4j:0.4.8' - implementation 'net.thauvin.erik:pinboard-poster:1.0.1' + implementation 'net.thauvin.erik:pinboard-poster:1.0.3' implementation 'org.apache.commons:commons-lang3:3.12.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC' implementation 'org.json:json:20210307' implementation 'org.jsoup:jsoup:1.13.1' implementation 'org.twitter4j:twitter4j-core:4.0.7' diff --git a/config/pmd.xml b/config/pmd.xml index b1174f9..2760bff 100644 --- a/config/pmd.xml +++ b/config/pmd.xml @@ -30,7 +30,6 @@ - @@ -59,8 +58,6 @@ - - @@ -163,7 +160,6 @@ - diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d913..f371643 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt index be986bf..2d8b974 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.kt @@ -259,7 +259,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert */ private fun helpResponse(sender: String, topic: String, isPrivate: Boolean) { val isOp = isOp(sender) - if (topic.isBlank() || !addons.help(sender, topic.toLowerCase().trim(), isOp, isPrivate)) { + if (topic.isBlank() || !addons.help(sender, topic.lowercase().trim(), isOp, isPrivate)) { helpDefault(sender, isOp, isPrivate) } } @@ -317,7 +317,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert tell.send(sender, true) if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2) - val cmd = cmds[0].toLowerCase() + val cmd = cmds[0].lowercase() val args = if (cmds.size > 1) { cmds[1].trim() } else "" @@ -342,7 +342,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert ) { if (logger.isDebugEnabled) logger.debug(">>> $sender : $message") val cmds = message.split(" ".toRegex(), 2) - val cmd = cmds[0].toLowerCase() + val cmd = cmds[0].lowercase() val args = if (cmds.size > 1) { cmds[1].trim() } else "" @@ -559,7 +559,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert e.printStackTrace(System.err) exitProcess(1) } - val nickname = p.getProperty("nick", Mobibot::class.java.name.toLowerCase()) + val nickname = p.getProperty("nick", Mobibot::class.java.name.lowercase()) val channel = p.getProperty("channel") val logsDir = ensureDir(p.getProperty("logs", "."), false) diff --git a/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt b/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt index addf76b..d5ce4c5 100644 --- a/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt @@ -51,7 +51,7 @@ object PinboardUtils { */ @JvmStatic fun addPin(poster: PinboardPoster, ircServer: String, entry: EntryLink) = runBlocking { - val add = GlobalScope.async { + val add = async { poster.addPin( entry.link, entry.title, @@ -68,7 +68,7 @@ object PinboardUtils { */ @JvmStatic fun deletePin(poster: PinboardPoster, entry: EntryLink) = runBlocking { - val delete = GlobalScope.async { + val delete = async { poster.deletePin(entry.link) } delete.await() @@ -79,7 +79,7 @@ object PinboardUtils { */ @JvmStatic fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking { - val update = GlobalScope.async { + val update = async { with(entry) { if (oldUrl != link) { poster.deletePin(oldUrl) diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt index 1187286..57191bc 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Ignore.kt @@ -70,7 +70,7 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) { @JvmStatic fun isNotIgnored(nick: String): Boolean { - return !ignored.contains(nick.toLowerCase()) + return !ignored.contains(nick.lowercase()) } } @@ -82,8 +82,8 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) { isPrivate: Boolean ) { if (!isOp) { - val nick = sender.toLowerCase() - val isMe = args.toLowerCase().startsWith(me) + val nick = sender.lowercase() + val isMe = args.lowercase().startsWith(me) ignoreNick(bot, nick, isMe, isPrivate) } else { ignoreOp(bot, sender, args, isPrivate) @@ -125,10 +125,10 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) { private fun ignoreOp(bot: Mobibot, sender: String, args: String, isPrivate: Boolean) { if (args.isNotEmpty()) { - val nicks = args.toLowerCase().split(" ") + val nicks = args.lowercase().split(" ") for (nick in nicks) { val ignore = if (me == nick) { - nick.toLowerCase() + nick.lowercase() } else { nick } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt index 0ea0708..db34ffb 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt @@ -70,7 +70,7 @@ class View(bot: Mobibot) : AbstractCommand(bot) { private fun showPosts(bot: Mobibot, args: String, sender: String) { val max = entries.size - var lcArgs = args.toLowerCase() + var lcArgs = args.lowercase() var i = 0 if (lcArgs.isEmpty() && max > maxEntries) { i = max - maxEntries 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 b676591..9596534 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 { var category: SyndCategoryImpl for (tag in tags) { if (!tag.isNullOrBlank()) { - val t = tag.toLowerCase() + val t = tag.lowercase() val mod = t[0] if (mod == '-') { // Don't remove the channel tag 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 a617f0b..96534a8 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt @@ -157,8 +157,8 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) { if (cmds[3] == cmds[1] || "0" == cmds[0]) { PublicMessage("You're kidding, right?") } else { - val to = cmds[1].toUpperCase() - val from = cmds[3].toUpperCase() + val to = cmds[1].uppercase() + val from = cmds[3].uppercase() if (EXCHANGE_RATES.containsKey(to) && EXCHANGE_RATES.containsKey(from)) { try { val amt = cmds[0].replace(",", "").toDouble() @@ -166,10 +166,10 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) { val doubleTo = EXCHANGE_RATES[from]!!.toDouble() PublicMessage( NumberFormat.getCurrencyInstance(Constants.LOCALE).format(amt).substring(1) - + " ${cmds[1].toUpperCase()} = " + + " ${cmds[1].uppercase()} = " + NumberFormat.getCurrencyInstance(Constants.LOCALE) .format(amt * doubleTo / doubleFrom).substring(1) - + " ${cmds[3].toUpperCase()}" + + " ${cmds[3].uppercase()}" ) } catch (e: NumberFormatException) { ErrorMessage("Let's try with some real numbers next time, okay?") diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt index e22496a..940c3a7 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt @@ -43,17 +43,17 @@ import kotlin.random.Random class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { init { with(commands) { - add(Hands.ROCK.name.toLowerCase()) - add(Hands.PAPER.name.toLowerCase()) - add(Hands.SCISSORS.name.toLowerCase()) + add(Hands.ROCK.name.lowercase()) + add(Hands.PAPER.name.lowercase()) + add(Hands.SCISSORS.name.lowercase()) } with(help) { add("To play Rock Paper Scissors:") add( Utils.helpFormat( - "%c ${Hands.ROCK.name.toLowerCase()} | ${Hands.PAPER.name.toLowerCase()}" - + " | ${Hands.SCISSORS.name.toLowerCase()}" + "%c ${Hands.ROCK.name.lowercase()} | ${Hands.PAPER.name.lowercase()}" + + " | ${Hands.SCISSORS.name.lowercase()}" ) ) } @@ -82,8 +82,8 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { companion object { // For testing. fun winLoseOrDraw(player: String, bot: String): String { - val hand = Hands.valueOf(player.toUpperCase()) - val botHand = Hands.valueOf(bot.toUpperCase()) + val hand = Hands.valueOf(player.uppercase()) + val botHand = Hands.valueOf(bot.uppercase()) return when { hand == botHand -> "draw" @@ -94,7 +94,7 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { } override fun commandResponse(sender: String, cmd: String, args: String, isPrivate: Boolean) { - val hand = Hands.valueOf(cmd.toUpperCase()) + val hand = Hands.valueOf(cmd.uppercase()) val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)] with(bot) { when { diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt index a43eca2..3244e41 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt @@ -121,7 +121,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List { if (apiKey.isNullOrBlank()) { - throw ModuleException("${STOCK_CMD.capitalize()} is disabled. The API key is missing.") + throw ModuleException( + "${STOCK_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.") } return if (symbol.isNotBlank()) { val debugMessage = "getQuote($symbol)" @@ -131,10 +132,10 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { with(messages) { // Search for symbol/keywords response = Utils.urlReader( - URL( - "${ALAPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol) + "&apikey=" - + Utils.encodeUrl(apiKey) - ) + URL( + "${ALAPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol) + + "&apikey=" + Utils.encodeUrl(apiKey) + ) ) var json = getJsonResponse(response, debugMessage) val symbols = json.getJSONArray("bestMatches") @@ -145,11 +146,11 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { // Get quote for symbol response = Utils.urlReader( - URL( - "${ALAPHAVANTAGE_URL}GLOBAL_QUOTE&symbol=" - + Utils.encodeUrl(symbolInfo.getString("1. symbol")) - + "&apikey=" + Utils.encodeUrl(apiKey) - ) + URL( + "${ALAPHAVANTAGE_URL}GLOBAL_QUOTE&symbol=" + + Utils.encodeUrl(symbolInfo.getString("1. symbol")) + + "&apikey=" + Utils.encodeUrl(apiKey) + ) ) json = getJsonResponse(response, debugMessage) val quote = json.getJSONObject("Global Quote") @@ -158,36 +159,36 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { return messages } add( - PublicMessage( - "Symbol: " + Utils.unescapeXml(quote.getString("01. symbol")) - + " [" + Utils.unescapeXml(symbolInfo.getString("2. name")) + ']' - ) + PublicMessage( + "Symbol: " + Utils.unescapeXml(quote.getString("01. symbol")) + + " [" + Utils.unescapeXml(symbolInfo.getString("2. name")) + ']' + ) ) add(PublicMessage(" Price: " + Utils.unescapeXml(quote.getString("05. price")))) add( - PublicMessage( - " Previous: " + Utils.unescapeXml(quote.getString("08. previous close")) - ) + PublicMessage( + " Previous: " + Utils.unescapeXml(quote.getString("08. previous close")) + ) ) add(NoticeMessage(" Open: " + Utils.unescapeXml(quote.getString("02. open")))) add(NoticeMessage(" High: " + Utils.unescapeXml(quote.getString("03. high")))) add(NoticeMessage(" Low: " + Utils.unescapeXml(quote.getString("04. low")))) add( - NoticeMessage( - " Volume: " + Utils.unescapeXml(quote.getString("06. volume")) - ) + NoticeMessage( + " Volume: " + Utils.unescapeXml(quote.getString("06. volume")) + ) ) add( - NoticeMessage( - " Latest: " - + Utils.unescapeXml(quote.getString("07. latest trading day")) - ) + NoticeMessage( + " Latest: " + + Utils.unescapeXml(quote.getString("07. latest trading day")) + ) ) add( - NoticeMessage( - " Change: " + Utils.unescapeXml(quote.getString("09. change")) - + " [" + Utils.unescapeXml(quote.getString("10. change percent")) + ']' - ) + NoticeMessage( + " Change: " + Utils.unescapeXml(quote.getString("09. change")) + " [" + + Utils.unescapeXml(quote.getString("10. change percent")) + ']' + ) ) } } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/War.java b/src/main/java/net/thauvin/erik/mobibot/modules/War.java index b239e87..2cfe28e 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/War.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/War.java @@ -32,6 +32,7 @@ package net.thauvin.erik.mobibot.modules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.Utils; import org.jetbrains.annotations.NotNull; @@ -71,6 +72,7 @@ public final class War extends AbstractModule { /** * {@inheritDoc} */ + @SuppressFBWarnings("DMI_RANDOM_USED_ONLY_ONCE") @Override public void commandResponse(@NotNull final String sender, @NotNull final String cmd, 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 a6133b4..f3b740d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt @@ -100,7 +100,8 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List { if (apiKey.isNullOrBlank()) { - throw ModuleException("${WEATHER_CMD.capitalize()} is disabled. The API key is missing.") + throw ModuleException( + "${WEATHER_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.") } val owm = OWM(apiKey) val messages = mutableListOf() @@ -122,7 +123,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { } if (cwd.hasCityName()) { messages.add( - PublicMessage("City: ${cwd.cityName} [${country.toUpperCase()}]") + PublicMessage("City: ${cwd.cityName} [${country.uppercase()}]") ) with(cwd.mainData) { if (this != null) { @@ -147,7 +148,9 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { if (list != null) { for (w in list) { if (w != null) { - condition.append(' ').append(w.getDescription().capitalize()).append('.') + condition.append(' ') + .append(w.getDescription().replaceFirstChar { it.uppercase() }) + .append('.') } } messages.add(NoticeMessage(condition.toString())) @@ -162,7 +165,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { messages.add( NoticeMessage( "https://openweathermap.org/find?q=" - + Utils.encodeUrl("$city,${country.toUpperCase()}"), + + Utils.encodeUrl("$city,${country.uppercase()}"), Colors.GREEN ) ) diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt index b03f416..e1f11c3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt @@ -72,7 +72,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) { */ @JvmStatic fun worldTime(query: String): Message { - val tz = COUNTRIES_MAP[(query.substring(query.indexOf(' ') + 1).trim()).toUpperCase()] + val tz = COUNTRIES_MAP[(query.substring(query.indexOf(' ') + 1).trim()).uppercase()] val response: String = if (tz != null) { if (BEATS_KEYWORD == tz) { "The current Internet Time is: " + Utils.bold(internetTime() + ' ' + BEATS_KEYWORD) diff --git a/src/test/java/net/thauvin/erik/mobibot/LocalProperties.kt b/src/test/java/net/thauvin/erik/mobibot/LocalProperties.kt index 04490ed..564b7fb 100644 --- a/src/test/java/net/thauvin/erik/mobibot/LocalProperties.kt +++ b/src/test/java/net/thauvin/erik/mobibot/LocalProperties.kt @@ -69,7 +69,7 @@ open class LocalProperties { } private fun keyToEnv(key: String): String { - return key.replace('-', '_').toUpperCase() + return key.replace('-', '_').uppercase() } } } diff --git a/version.properties b/version.properties index 38c12ff..8b8d651 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Fri Mar 12 21:10:57 PST 2021 -version.buildmeta=434 +#Mon Apr 26 15:10:03 PDT 2021 +version.buildmeta=452 version.major=0 version.minor=8 version.patch=0 version.prerelease=beta version.project=mobibot -version.semver=0.8.0-beta+434 +version.semver=0.8.0-beta+452