-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
105 lines (90 loc) · 2.33 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/hamidteimouri/gommon/htenvier"
"log"
"strconv"
)
func main() {
bot, err := tgbotapi.NewBotAPI(htenvier.Env("BOT_TOKEN"))
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil { // ignore non-Message updates
continue
}
/*msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
switch update.Message.Text {
case "open":
msg.ReplyMarkup = numericKeyboard
case "close":
msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true)
}*/
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "")
if update.Message.IsCommand() {
// Extract the command from the Message.
switch update.Message.Command() {
case "start":
msg.Text = getMsgWelcome(update.Message.Chat.FirstName)
msg.ReplyMarkup = mainMenu
case "back":
msg.Text = "I understand /sayhi and /status."
msg.ReplyMarkup = mainMenu
case "sayhi":
msg.Text = "Hi :)"
default:
msg.Text = "در حال پیاده سازی"
}
} else {
// Extract the command from the Message.
switch update.Message.Text {
case BtnHome:
msg.Text = getMsgBackToHome()
msg.ReplyMarkup = mainMenu
case BtnTetherPrice:
msg.Text = getMsgTetherPrice()
msg.ReplyMarkup = mainMenuWithBack
case BtnCalculator:
msg.Text = getMsgSelectYourCoin()
msg.ReplyMarkup = coinsMenuWithBack
case BtnBalanceUsdtTrc20:
msg.Text = getMsgEnterYourWalletAddress()
msg.ReplyMarkup = coinsMenuWithBack
default:
msg.Text = "در حال پیاده سازی امکانات"
msg.ReplyMarkup = mainMenu
}
}
if _, err := bot.Send(msg); err != nil {
log.Panic(err)
}
}
}
func Format(n int64) string {
in := strconv.FormatInt(n, 10)
numOfDigits := len(in)
if n < 0 {
numOfDigits-- // First character is the - sign (not a digit)
}
numOfCommas := (numOfDigits - 1) / 3
out := make([]byte, len(in)+numOfCommas)
if n < 0 {
in, out[0] = in[1:], '-'
}
for i, j, k := len(in)-1, len(out)-1, 0; ; i, j = i-1, j-1 {
out[j] = in[i]
if i == 0 {
return string(out)
}
if k++; k == 3 {
j, k = j-1, 0
out[j] = ','
}
}
}