Upgraded to Kotlin 1.5.0

This commit is contained in:
Erik C. Thauvin 2021-04-26 15:23:21 -07:00
parent c950d7349a
commit aaf44db38a
16 changed files with 77 additions and 75 deletions

View file

@ -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'

View file

@ -30,7 +30,6 @@
<rule ref="category/java/bestpractices.xml/SystemPrintln"/>
<rule ref="category/java/bestpractices.xml/UnusedAssignment"/>
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
<rule ref="category/java/bestpractices.xml/UnusedImports"/>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
@ -59,8 +58,6 @@
<rule ref="category/java/codestyle.xml/BooleanGetMethodName"/>
<rule ref="category/java/codestyle.xml/CallSuperInConstructor"/>
<rule ref="category/java/codestyle.xml/ControlStatementBraces"/>
<rule ref="category/java/codestyle.xml/DontImportJavaLang"/>
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract"/>
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass"/>
@ -163,7 +160,6 @@
<rule ref="category/java/errorprone.xml/FinalizeOverloaded"/>
<rule ref="category/java/errorprone.xml/FinalizeShouldBeProtected"/>
<rule ref="category/java/errorprone.xml/IdempotentOperations"/>
<rule ref="category/java/errorprone.xml/ImportFromSamePackage"/>
<rule ref="category/java/errorprone.xml/InstantiationToGetClass"/>
<rule ref="category/java/errorprone.xml/InvalidLogMessageFormat"/>
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>

View file

@ -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

View file

@ -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: <command>
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)

View file

@ -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)

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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?")

View file

@ -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 {

View file

@ -121,7 +121,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
@Throws(ModuleException::class)
fun getQuote(symbol: String, apiKey: String?): List<Message> {
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")) + ']'
)
)
}
}

View file

@ -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,

View file

@ -100,7 +100,8 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
@Throws(ModuleException::class)
fun getWeather(query: String, apiKey: String?): List<Message> {
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<Message>()
@ -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
)
)

View file

@ -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)

View file

@ -69,7 +69,7 @@ open class LocalProperties {
}
private fun keyToEnv(key: String): String {
return key.replace('-', '_').toUpperCase()
return key.replace('-', '_').uppercase()
}
}
}

View file

@ -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