Included currencies in help response.
This commit is contained in:
parent
c99210f624
commit
bd14a1e15e
3 changed files with 37 additions and 14 deletions
|
@ -51,6 +51,26 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
|
|||
"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 <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).
|
||||
*/
|
||||
|
@ -60,9 +80,6 @@ class Bitcoin(bot: Mobibot) : ThreadedModule(bot) {
|
|||
@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 <USD|GBP|EUR|...>"))
|
||||
commands.add(BTC_CMD)
|
||||
commands.add(XBT_CMD)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue