numeric_input.go 423 B

123456789101112131415161718
  1. package tgbot
  2. // updateNumericInput applies one key from the shared inline number pad.
  3. // Key -2 clears the value, -1 removes the last decimal digit, and 0..9 append
  4. // a digit. Callers retain their own validation and keyboard labels.
  5. func updateNumericInput(value, key int) int {
  6. switch key {
  7. case -2:
  8. return 0
  9. case -1:
  10. if value > 0 {
  11. return value / 10
  12. }
  13. return value
  14. default:
  15. return value*10 + key
  16. }
  17. }