-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbalance.go
46 lines (39 loc) · 1.07 KB
/
balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
)
const (
balanceMessage = "👑 *Your balance:* %d sat"
balanceErrorMessage = "🚫 Error fetching your balance. Please try again later."
)
func (bot TipBot) balanceHandler(m *tb.Message) {
// check and print all commands
bot.anyTextHandler(m)
// reply only in private message
if m.Chat.Type != tb.ChatPrivate {
// delete message
NewMessage(m, WithDuration(0, bot.telegram))
}
// first check whether the user is initialized
fromUser, err := GetUser(m.Sender, bot)
if err != nil {
log.Errorf("[/balance] Error: %s", err)
return
}
if !fromUser.Initialized {
bot.startHandler(m)
return
}
usrStr := GetUserStr(m.Sender)
balance, err := bot.GetUserBalance(m.Sender)
if err != nil {
log.Errorf("[/balance] Error fetching %s's balance: %s", usrStr, err)
bot.trySendMessage(m.Sender, balanceErrorMessage)
return
}
log.Infof("[/balance] %s's balance: %d sat\n", usrStr, balance)
bot.trySendMessage(m.Sender, fmt.Sprintf(balanceMessage, balance))
return
}