-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (67 loc) · 1.7 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
package main
import (
"github.com/fatih/color"
"github.com/joho/godotenv"
"github.com/than-os/sentinel-bot/constants"
"github.com/than-os/sentinel-bot/dbo"
"github.com/than-os/sentinel-bot/handlers"
"github.com/than-os/sentinel-bot/helpers"
"gopkg.in/telegram-bot-api.v4"
"log"
"os"
)
func init() {
if err := godotenv.Load(); err != nil {
log.Fatal("error while reading ENV config. shutting down bot now.")
}
}
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv("BOT_API_KEY"))
if err != nil {
log.Fatalf("error in instantiating the bot: %v", err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
color.Red("error while receiving messages: %s", err)
}
color.Green("started %s successfully", bot.Self.UserName)
db, nodes, err := dbo.NewDB()
if err != nil {
log.Fatal(err)
}
for update := range updates {
if update.Message == nil {
continue
}
if update.Message.From.IsBot {
return
}
// handle the commands for the bot
if update.Message.IsCommand() {
switch update.Message.Command() {
case "mynode":
handlers.ShowMyNode(bot, update, db)
case "start":
handlers.Greet(bot, update, db)
case "restart":
handlers.Restart(bot, update, db)
case "info":
handlers.ShowMyInfo(bot, update, db)
case "eth":
handlers.ShowEthWallet(bot, update, db)
case "refund":
handlers.ClaimRefund(bot, update, db)
case "about":
handlers.AboutSentinel(bot, update)
default:
return
}
}
// handle the app flow for bot
handlers.MainHandler(bot, update, db, *nodes)
TMState := helpers.GetState(bot, update, constants.TMState, db)
color.Green("******* APP STATE = %d *******", TMState)
}
}