From bd14a1e15ed2c0febd3243f4def62f9f2b476571 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 4 May 2021 11:05:23 -0700 Subject: [PATCH] Included currencies in help response. --- .../thauvin/erik/mobibot/modules/Bitcoin.kt | 41 +++++++++++++++---- .../erik/mobibot/modules/BitcoinTest.kt | 4 +- version.properties | 6 +-- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Bitcoin.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Bitcoin.kt index 0289bf2..428917d 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Bitcoin.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Bitcoin.kt @@ -48,21 +48,38 @@ import java.net.URL class Bitcoin(bot: Mobibot) : ThreadedModule(bot) { // Currencies private val currencies = listOf( - "USD", "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "DKK", "EUR", "GBP", "HKD", "INR", "ISK", "JPY", "KRW", + "USD", "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "DKK", "EUR", "GBP", "HKD", "INR", "ISK", "JPY", "KRW", "NZD", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD"); + override fun helpResponse(sender: String, isPrivate: Boolean): Boolean { + with(bot) { + send(sender, "To retrieve the bitcoin market price:", isPrivate) + send( + sender, + Utils.helpFormat( + Utils.buildCmdSyntax( + "%c $BITCOIN_CMD ", + nick, + isPrivateMsgEnabled) + ), + isPrivate + ) + send(sender, "The supported currencies are: ", isPrivate) + @Suppress("MagicNumber") + sendList(sender, currencies, 12, isPrivate, isIndent = true) + } + return true + } + /** * Returns the bitcoin market price from [Blockchain.info](https://blockchain.info/ticker). */ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { with(bot) { - val arg = args.trim().uppercase() + val arg = args.trim().uppercase() @Suppress("MagicNumber") if (!currencies.contains(arg)) { helpResponse(sender, isPrivate) - send(sender, "The supported currencies are: ", isPrivate) - @Suppress("MagicNumber") - sendList(sender, currencies, 12, isPrivate, isIndent = true) } else { try { val messages = marketPrice(arg) @@ -81,9 +98,15 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) { // Blockchain Ticker URL private const val TICKER_URL = "https://blockchain.info/ticker" - // Quote command + // Bitcoin command private const val BITCOIN_CMD = "bitcoin" + // BTC command + private const val BTC_CMD = "btc" + + // XBT command + private const val XBT_CMD = "xbt" + /** * Retrieves the bitcoin market price. */ @@ -98,7 +121,7 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) { val bpi = json.getJSONObject(currency.trim().uppercase()) val symbol = bpi.getString("symbol"); with(messages) { - add(PublicMessage("BTC: $symbol" + bpi.getBigDecimal("last") + " [$currency]")) + add(PublicMessage("BITCOIN: $symbol" + bpi.getBigDecimal("last") + " [$currency]")) add(NoticeMessage(" 15m: $symbol" + bpi.getBigDecimal("15m"))) add(NoticeMessage(" Buy: $symbol" + bpi.getBigDecimal("buy"))) add(NoticeMessage(" Sell: $symbol" + bpi.getBigDecimal("sell"))) @@ -117,7 +140,7 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) { init { commands.add(BITCOIN_CMD) - help.add("To retrieve the bitcoin market price:") - help.add(Utils.helpFormat("%c $BITCOIN_CMD ")) + commands.add(BTC_CMD) + commands.add(XBT_CMD) } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/BitcoinTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/BitcoinTest.kt index 8453420..31f7ede 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/BitcoinTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/BitcoinTest.kt @@ -45,11 +45,11 @@ class BitcoinTest : LocalProperties() { fun testMarketPrice() { var messages = marketPrice("USD") assertThat(messages).`as`("not empty").isNotEmpty - assertThat(messages[0].msg).`as`("btc & $").startsWith("BTC").contains("$") + assertThat(messages[0].msg).`as`("bitcoin & $").startsWith("BITCOIN").contains("$") assertThat(messages[1].msg).`as`("15m").contains("15m") messages = marketPrice("GBP") - assertThat(messages[0].msg).`as`("BPB btc & £").startsWith("BTC").contains("£") + assertThat(messages[0].msg).`as`("£").contains("£").contains("GBP") assertThat(messages[1].msg).`as`("GBP 15m").contains("15m") } } diff --git a/version.properties b/version.properties index dcde182..cb3f1db 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Tue May 04 01:01:14 PDT 2021 -version.buildmeta=606 +#Tue May 04 11:01:30 PDT 2021 +version.buildmeta=610 version.major=0 version.minor=8 version.patch=0 version.prerelease=beta version.project=mobibot -version.semver=0.8.0-beta+606 +version.semver=0.8.0-beta+610