Format cryptoprice as currency.

This commit is contained in:
Erik C. Thauvin 2021-05-25 16:33:17 -07:00
parent 43615f253c
commit 05b7ca8a41
4 changed files with 16 additions and 7 deletions

View file

@ -3,12 +3,12 @@ plugins {
id 'checkstyle'
id 'com.github.ben-manes.versions' version '0.38.0'
id 'idea'
id 'io.gitlab.arturbosch.detekt' version '1.17.0'
id 'io.gitlab.arturbosch.detekt' version '1.17.1'
id 'jacoco'
id 'java'
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
id 'org.jetbrains.kotlin.jvm' version '1.5.0'
id 'org.jetbrains.kotlin.kapt' version '1.5.0'
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
id 'org.jetbrains.kotlin.kapt' version '1.5.10'
id 'org.sonarqube' version '3.2.0'
id 'pmd'
}

View file

@ -39,6 +39,7 @@
<ID>NestedBlockDepth:WorldTime.kt$WorldTime$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )</ID>
<ID>ReturnCount:Addons.kt$Addons$ fun exec(sender: String, login: String, cmd: String, args: String, isOp: Boolean, isPrivate: Boolean): Boolean</ID>
<ID>ReturnCount:Addons.kt$Addons$ fun help(sender: String, topic: String, isOp: Boolean, isPrivate: Boolean): Boolean</ID>
<ID>SwallowedException:CryptoPrices.kt$CryptoPrices$catch (e: IllegalArgumentException) { price.amount }</ID>
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$ @JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List&lt;Message&gt;</ID>
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$ @JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</ID>
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>

View file

@ -38,6 +38,9 @@ import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.msg.PublicMessage
import java.text.NumberFormat
import java.util.Currency
/**
* The Cryptocurrency Prices module.
*/
@ -51,7 +54,12 @@ class CryptoPrices(bot: Mobibot) : ThreadedModule(bot) {
if (args.matches("\\w+( [a-zA-Z]{3}+)?".toRegex())) {
try {
val price = currentPrice(args.split(' '))
send(sender, PublicMessage("${price.base}: ${price.amount} [${price.currency}]"))
val amount = try {
price.toCurrency()
} catch (e: IllegalArgumentException) {
price.amount
}
send(sender, PublicMessage("${price.base}: $amount [${price.currency}]"))
} catch (e: CryptoException) {
if (logger.isWarnEnabled) logger.warn("$debugMessage => ${e.statusCode}", e)
send(e.message)

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
#Wed May 19 19:28:39 PDT 2021
version.buildmeta=842
#Tue May 25 18:01:58 PDT 2021
version.buildmeta=848
version.major=0
version.minor=8
version.patch=0
version.prerelease=beta
version.project=mobibot
version.semver=0.8.0-beta+842
version.semver=0.8.0-beta+848