Skip to content

Commit

Permalink
Mark key words in bold on new tx (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaBernstein authored Sep 10, 2022
1 parent 4325466 commit 2c504c0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
21 changes: 11 additions & 10 deletions bot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,7 @@ func (bc *BotController) commandCreateSimpleTx(m *tb.Message) {
return
}
hint := tx.NextHint(bc.Repo, m)
_, err = bc.Bot.Send(Recipient(m), hint.Prompt, ReplyKeyboard(hint.KeyboardOptions))
if err != nil {
bc.Logf(ERROR, m, "Sending bot message failed: %s", err.Error())
}
bc.sendNextTxHint(hint, m)
}

func (bc *BotController) commandAddComment(m *tb.Message) {
Expand Down Expand Up @@ -660,12 +657,7 @@ func (bc *BotController) handleTextState(m *tb.Message) {
return
}
hint := tx.NextHint(bc.Repo, m)
replyKeyboard := ReplyKeyboard(hint.KeyboardOptions)
bc.Logf(TRACE, m, "Sending hints for next step: %v", hint.KeyboardOptions)
_, err = bc.Bot.Send(Recipient(m), hint.Prompt, replyKeyboard)
if err != nil {
bc.Logf(ERROR, m, "Sending bot message failed: %s", err.Error())
}
bc.sendNextTxHint(hint, m)
return
} else if state == ST_TPL {
if bc.processNewTemplateResponse(m, bc.State.tplStates[chatId(m.Chat.ID)]) {
Expand All @@ -677,6 +669,15 @@ func (bc *BotController) handleTextState(m *tb.Message) {
"Are there new state types not maintained yet?")
}

func (bc *BotController) sendNextTxHint(hint *Hint, m *tb.Message) {
replyKeyboard := ReplyKeyboard(hint.KeyboardOptions)
bc.Logf(TRACE, m, "Sending hints for next step: %v", hint.KeyboardOptions)
_, err := bc.Bot.Send(Recipient(m), escapeCharacters(hint.Prompt, "(", ")", "."), replyKeyboard, tb.ModeMarkdownV2)
if err != nil {
bc.Logf(ERROR, m, "Sending bot message failed: %s", err.Error())
}
}

func clearKeyboard() *tb.ReplyMarkup {
return &tb.ReplyMarkup{ReplyKeyboardRemove: true}
}
Expand Down
8 changes: 4 additions & 4 deletions bot/transactionBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func CreateSimpleTx(suggestedCur, template string) (Tx, error) {
stepDetails: make(map[command]Input),
template: template,
}).
addStep("amount", fmt.Sprintf("Please enter the amount of money (e.g. '12.34' or '12.34 %s')", suggestedCur), HandleFloat).
addStep("from", "Please enter the account the money came from (or select one from the list)", HandleRaw).
addStep("to", "Please enter the account the money went to (or select one from the list)", HandleRaw).
addStep("description", "Please enter a description (or select one from the list)", HandleRaw)
addStep("amount", fmt.Sprintf("Please enter the *amount* of money (e.g. '12.34' or '12.34 %s')", suggestedCur), HandleFloat).
addStep("from", "Please enter the *account* the money came *from* (or select one from the list)", HandleRaw).
addStep("to", "Please enter the *account* the money went *to* (or select one from the list)", HandleRaw).
addStep("description", "Please enter a *description* (or select one from the list)", HandleRaw)
return tx, nil
}

Expand Down
1 change: 1 addition & 0 deletions scenarioTests/features/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Feature: List transactions
And I create a simple tx with amount 1.23 and accFrom someFromAccount and accTo someToAccount and desc Test Tx
And I wait 0.1 seconds
When I send the message "/list dated"
And I wait 0.1 seconds
Then 1 messages should be sent back
And the response should include the message "; recorded on $today "

Expand Down
4 changes: 2 additions & 2 deletions scenarioTests/features/templates.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Feature: Templates
When I send the message "/t my"
Then 2 messages should be sent back
And the response should include the message "Creating a new transaction from your template 'mytpl'"
And the response should include the message "Please enter the amount"
And the response should include the message "Please enter the *amount*"
When I send the message "15,15"
Then 1 messages should be sent back
And the response should include the message "Please enter a description"
And the response should include the message "Please enter a **description**"
When I send the message "some description"
Then 1 messages should be sent back
And the response should include the message "Successfully recorded your transaction."
Expand Down
6 changes: 3 additions & 3 deletions scenarioTests/features/transactions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Feature: Transactions
When I send the message "12.34"
Then 2 messages should be sent back
And the response should include the message "created a new transaction for you"
And the response should include the message "enter the account the money came from"
And the response should include the message "enter the **account** the money came **from**"
When I send the message "FromAccount"
Then 1 messages should be sent back
And the response should include the message "enter the account the money went to"
And the response should include the message "enter the **account** the money went **to**"
When I send the message "ToAccount"
Then 1 messages should be sent back
And the response should include the message "enter a description"
And the response should include the message "enter a **description**"
When I send the message "any random tx description"
Then 1 messages should be sent back
And the response should include the message "Successfully recorded your transaction."
Expand Down
2 changes: 1 addition & 1 deletion scenarioTests/steps/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def step_impl(context, same, message):
try:
assert message in response.text
except AssertionError:
print("substring", message, "could not be found in", response.text)
print("substring '", message, "' could not be found in '", response.text, "'")
assert False

@then('the response should have a keyboard with {position} entry being "{keyboardEntry}"')
Expand Down

0 comments on commit 2c504c0

Please sign in to comment.