From 5c3eaf232d7117ab6fcd992341e158c2b2f592b0 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 10 May 2025 05:15:10 -0700 Subject: [PATCH 1/2] Update webpage with the StockQuote module commands using Finnhub --- website/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/index.html b/website/index.html index 370c3cf..a2d52b3 100644 --- a/website/index.html +++ b/website/index.html @@ -94,9 +94,9 @@
  • Performing DNS lookups
    mobibot: lookup www.apple.com
  • -
  • Retrieving stock quotes from Alpha Avantage +
  • Retrieving stock quotes from Finnhub
    mobibot: stock GOOG
    -
    mobibot: stock google
    +
    mobibot: stock lookup alphabet inc
  • Displaying the time in various time zones
    mobibot: time UK
    From 066e3f81e98cdd5a8d5742f64cdd25cf7ca56137 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 10 May 2025 05:16:44 -0700 Subject: [PATCH 2/2] Round stock change percent value --- .../kotlin/net/thauvin/erik/mobibot/modules/StockQuote2.kt | 6 ++++-- .../net/thauvin/erik/mobibot/modules/StockQuote2Test.kt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2.kt index eadc64c..f651612 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2.kt @@ -46,6 +46,7 @@ import org.pircbotx.hooks.types.GenericMessageEvent import org.slf4j.Logger import org.slf4j.LoggerFactory import java.io.IOException +import java.math.RoundingMode import java.net.URL import java.time.Instant import java.time.ZoneId @@ -180,7 +181,8 @@ class StockQuote2 : AbstractModule() { ) add( NoticeMessage( - "Change: ".padEnd(pad).prependIndent() + change + " [$changePercent%]" + "Change: ".padEnd(pad).prependIndent() + change + + " [${changePercent.setScale(2, RoundingMode.DOWN)}%]" ) ) add( @@ -264,7 +266,7 @@ class StockQuote2 : AbstractModule() { val name = result.getString("description") add( - NoticeMessage("${symbol.bold()}: $name".prependIndent()) + NoticeMessage("${symbol.bold().padEnd(10)} $name".prependIndent()) ) if (i >= 4) { diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2Test.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2Test.kt index 73d80de..c4a3245 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2Test.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuote2Test.kt @@ -161,7 +161,7 @@ class StockQuote2Test : LocalProperties() { var hasGoog = false for (msg in messages) { - if (msg.msg.matches("\\s+\u0002GOOG\u0002: .*".toRegex())) { + if (msg.msg.matches("\\s+\u0002GOOG\u0002\\s+.*".toRegex())) { hasGoog = true break }