Cleanup StockQuote module output formatting
This commit is contained in:
parent
da04d43ce8
commit
6967341514
4 changed files with 35 additions and 17 deletions
|
@ -14,12 +14,12 @@ import java.time.ZoneId
|
|||
*/
|
||||
object ReleaseInfo {
|
||||
const val PROJECT = "mobibot"
|
||||
const val VERSION = "0.8.0-rc+20250509175846"
|
||||
const val VERSION = "0.8.0-rc+20250509223055"
|
||||
|
||||
@JvmField
|
||||
@Suppress("MagicNumber")
|
||||
val BUILD_DATE: LocalDateTime = LocalDateTime.ofInstant(
|
||||
Instant.ofEpochMilli(1746838726462L), ZoneId.systemDefault()
|
||||
Instant.ofEpochMilli(1746855055425L), ZoneId.systemDefault()
|
||||
)
|
||||
|
||||
const val WEBSITE = "https://mobitopia.org/mobibot/"
|
||||
|
|
|
@ -98,8 +98,7 @@ class Info(private val tell: Tell, private val seen: Seen) : AbstractCommand() {
|
|||
} else if (isEmpty()) {
|
||||
return "0 second"
|
||||
}
|
||||
|
||||
return this.joinToString(" ")
|
||||
return joinToString(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ class StockQuote2 : AbstractModule() {
|
|||
|
||||
add(
|
||||
PublicMessage(
|
||||
"Symbol: $tickerSymbol"
|
||||
"Symbol: ${tickerSymbol.bold()}"
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -168,6 +168,16 @@ class StockQuote2 : AbstractModule() {
|
|||
"Price: ".padEnd(pad).prependIndent() + c
|
||||
)
|
||||
)
|
||||
add(
|
||||
PublicMessage(
|
||||
"Previous: ".padEnd(pad).prependIndent() + previous
|
||||
)
|
||||
)
|
||||
add(
|
||||
NoticeMessage(
|
||||
"Symbol: ${tickerSymbol.bold()}"
|
||||
)
|
||||
)
|
||||
add(
|
||||
NoticeMessage(
|
||||
"Change: ".padEnd(pad).prependIndent() + change + " [$changePercent%]"
|
||||
|
@ -188,11 +198,6 @@ class StockQuote2 : AbstractModule() {
|
|||
"Open: ".padEnd(pad).prependIndent() + open
|
||||
)
|
||||
)
|
||||
add(
|
||||
PublicMessage(
|
||||
"Previous: ".padEnd(pad).prependIndent() + previous
|
||||
)
|
||||
)
|
||||
add(
|
||||
NoticeMessage(
|
||||
"Latest: ".padEnd(pad).prependIndent() + latest
|
||||
|
@ -242,10 +247,15 @@ class StockQuote2 : AbstractModule() {
|
|||
val json = getJsonResponse(response, debugMessage)
|
||||
val count = json.getInt("count")
|
||||
if (count == 0) {
|
||||
add(ErrorMessage("Nothing found."))
|
||||
add(ErrorMessage("Nothing found for: ${keywords.bold()}"))
|
||||
return messages
|
||||
}
|
||||
|
||||
add(
|
||||
NoticeMessage(
|
||||
"Search results for: ${keywords.bold()}"
|
||||
)
|
||||
)
|
||||
val results = json.getJSONArray("result")
|
||||
|
||||
for (i in 0 until count) {
|
||||
|
@ -254,7 +264,7 @@ class StockQuote2 : AbstractModule() {
|
|||
val name = result.getString("description")
|
||||
|
||||
add(
|
||||
NoticeMessage("${symbol.bold()}: $name")
|
||||
NoticeMessage("${symbol.bold()}: $name".prependIndent())
|
||||
)
|
||||
|
||||
if (i >= 4) {
|
||||
|
|
|
@ -119,10 +119,10 @@ class StockQuote2Test : LocalProperties() {
|
|||
val messages = getSanitizedQuote(symbol, apiKey)
|
||||
assertThat(messages, "response not empty").isNotEmpty()
|
||||
assertThat(messages, "getQuote($symbol)").index(0).prop(Message::msg)
|
||||
.isEqualTo("Symbol: AAPL")
|
||||
.isEqualTo("Symbol: \u0002AAPL\u0002")
|
||||
assertThat(messages, "getQuote($symbol)").index(1).prop(Message::msg)
|
||||
.matches("\\s+Price:\\s+\\d+\\.\\d+.*".toRegex())
|
||||
assertThat(messages, "getQuote($symbol)").index(7).prop(Message::msg)
|
||||
assertThat(messages, "getQuote($symbol)").index(8).prop(Message::msg)
|
||||
.matches("\\s+Latest:\\s+\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2} UTC".toRegex())
|
||||
}
|
||||
|
||||
|
@ -156,12 +156,12 @@ class StockQuote2Test : LocalProperties() {
|
|||
val keywords = "alphabet inc"
|
||||
val messages = getSanitizedLookup(keywords, apiKey)
|
||||
assertThat(messages, "messages should not be empty").isNotEmpty()
|
||||
assertThat(messages, "lookup($keywords)").index(1).prop(Message::msg)
|
||||
.matches("\u0002\\w+\u0002: .*".toRegex())
|
||||
assertThat(messages, "lookup($keywords)").index(0).prop(Message::msg)
|
||||
.isEqualTo("Search results for: \u0002alphabet inc\u0002")
|
||||
|
||||
var hasGoog = false
|
||||
for (msg in messages) {
|
||||
if (msg.msg.matches("\u0002GOOG\u0002: .*".toRegex())) {
|
||||
if (msg.msg.matches("\\s+\u0002GOOG\u0002: .*".toRegex())) {
|
||||
hasGoog = true
|
||||
break
|
||||
}
|
||||
|
@ -179,5 +179,14 @@ class StockQuote2Test : LocalProperties() {
|
|||
.isEqualTo("Please specify at least one search term.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(ModuleException::class)
|
||||
fun `Lookup not found`() {
|
||||
val keywords = "foo motors"
|
||||
val messages = getSanitizedLookup(keywords, apiKey)
|
||||
assertThat(messages, "response not empty").isNotEmpty()
|
||||
assertThat(messages, "lookup($keywords)").index(0).prop(Message::msg)
|
||||
.isEqualTo("Nothing found for: \u0002foo motors\u0002")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue