Format cryptoprice as currency.
This commit is contained in:
parent
43615f253c
commit
05b7ca8a41
4 changed files with 16 additions and 7 deletions
|
@ -3,12 +3,12 @@ plugins {
|
||||||
id 'checkstyle'
|
id 'checkstyle'
|
||||||
id 'com.github.ben-manes.versions' version '0.38.0'
|
id 'com.github.ben-manes.versions' version '0.38.0'
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'io.gitlab.arturbosch.detekt' version '1.17.0'
|
id 'io.gitlab.arturbosch.detekt' version '1.17.1'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
|
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.5.0'
|
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
|
||||||
id 'org.jetbrains.kotlin.kapt' version '1.5.0'
|
id 'org.jetbrains.kotlin.kapt' version '1.5.10'
|
||||||
id 'org.sonarqube' version '3.2.0'
|
id 'org.sonarqube' version '3.2.0'
|
||||||
id 'pmd'
|
id 'pmd'
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
<ID>NestedBlockDepth:WorldTime.kt$WorldTime$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )</ID>
|
<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 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>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<Message></ID>
|
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$ @JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message></ID>
|
||||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$ @JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message></ID>
|
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$ @JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message></ID>
|
||||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>
|
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>
|
||||||
|
|
|
@ -38,6 +38,9 @@ import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||||
import net.thauvin.erik.mobibot.msg.PublicMessage
|
import net.thauvin.erik.mobibot.msg.PublicMessage
|
||||||
|
|
||||||
|
import java.text.NumberFormat
|
||||||
|
import java.util.Currency
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Cryptocurrency Prices module.
|
* The Cryptocurrency Prices module.
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +54,12 @@ class CryptoPrices(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
if (args.matches("\\w+( [a-zA-Z]{3}+)?".toRegex())) {
|
if (args.matches("\\w+( [a-zA-Z]{3}+)?".toRegex())) {
|
||||||
try {
|
try {
|
||||||
val price = currentPrice(args.split(' '))
|
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) {
|
} catch (e: CryptoException) {
|
||||||
if (logger.isWarnEnabled) logger.warn("$debugMessage => ${e.statusCode}", e)
|
if (logger.isWarnEnabled) logger.warn("$debugMessage => ${e.statusCode}", e)
|
||||||
send(e.message)
|
send(e.message)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Wed May 19 19:28:39 PDT 2021
|
#Tue May 25 18:01:58 PDT 2021
|
||||||
version.buildmeta=842
|
version.buildmeta=848
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=beta
|
version.prerelease=beta
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-beta+842
|
version.semver=0.8.0-beta+848
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue