Included currencies in help response.

This commit is contained in:
Erik C. Thauvin 2021-05-04 11:05:23 -07:00
parent c99210f624
commit bd14a1e15e
3 changed files with 37 additions and 14 deletions

View file

@ -48,21 +48,38 @@ import java.net.URL
class Bitcoin(bot: Mobibot) : ThreadedModule(bot) { class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
// Currencies // Currencies
private val currencies = listOf( 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"); "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 <USD|GBP|EUR|...>",
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). * Returns the bitcoin market price from [Blockchain.info](https://blockchain.info/ticker).
*/ */
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
with(bot) { with(bot) {
val arg = args.trim().uppercase() val arg = args.trim().uppercase()
@Suppress("MagicNumber") @Suppress("MagicNumber")
if (!currencies.contains(arg)) { if (!currencies.contains(arg)) {
helpResponse(sender, isPrivate) helpResponse(sender, isPrivate)
send(sender, "The supported currencies are: ", isPrivate)
@Suppress("MagicNumber")
sendList(sender, currencies, 12, isPrivate, isIndent = true)
} else { } else {
try { try {
val messages = marketPrice(arg) val messages = marketPrice(arg)
@ -81,9 +98,15 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
// Blockchain Ticker URL // Blockchain Ticker URL
private const val TICKER_URL = "https://blockchain.info/ticker" private const val TICKER_URL = "https://blockchain.info/ticker"
// Quote command // Bitcoin command
private const val BITCOIN_CMD = "bitcoin" 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. * Retrieves the bitcoin market price.
*/ */
@ -98,7 +121,7 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
val bpi = json.getJSONObject(currency.trim().uppercase()) val bpi = json.getJSONObject(currency.trim().uppercase())
val symbol = bpi.getString("symbol"); val symbol = bpi.getString("symbol");
with(messages) { 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(" 15m: $symbol" + bpi.getBigDecimal("15m")))
add(NoticeMessage(" Buy: $symbol" + bpi.getBigDecimal("buy"))) add(NoticeMessage(" Buy: $symbol" + bpi.getBigDecimal("buy")))
add(NoticeMessage(" Sell: $symbol" + bpi.getBigDecimal("sell"))) add(NoticeMessage(" Sell: $symbol" + bpi.getBigDecimal("sell")))
@ -117,7 +140,7 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
init { init {
commands.add(BITCOIN_CMD) commands.add(BITCOIN_CMD)
help.add("To retrieve the bitcoin market price:") commands.add(BTC_CMD)
help.add(Utils.helpFormat("%c $BITCOIN_CMD <USD|GBP|EUR|...>")) commands.add(XBT_CMD)
} }
} }

View file

@ -45,11 +45,11 @@ class BitcoinTest : LocalProperties() {
fun testMarketPrice() { fun testMarketPrice() {
var messages = marketPrice("USD") var messages = marketPrice("USD")
assertThat(messages).`as`("not empty").isNotEmpty 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") assertThat(messages[1].msg).`as`("15m").contains("15m")
messages = marketPrice("GBP") 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") assertThat(messages[1].msg).`as`("GBP 15m").contains("15m")
} }
} }

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Tue May 04 01:01:14 PDT 2021 #Tue May 04 11:01:30 PDT 2021
version.buildmeta=606 version.buildmeta=610
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+606 version.semver=0.8.0-beta+610