-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
52 lines (41 loc) · 935 Bytes
/
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
package main
import (
"github.com/QuarantineGameTeam/team2_qgame/api"
"github.com/QuarantineGameTeam/team2_qgame/config"
"github.com/QuarantineGameTeam/team2_qgame/game"
"log"
"time"
)
var (
client *api.Client
)
func main() {
// Setting up telegram bot client
var err error
log.Println("Connecting to bot api.")
client, err = api.NewClient(config.BotToken)
if err != nil {
log.Fatal(err)
}
log.Println("Successful.")
firstUpdate := 0
lastUpdate := 0
var update api.Update
for {
updates := client.GetUpdates(lastUpdate + 1)
if len(updates) != 0 {
update = updates[0]
if firstUpdate == 0 {
firstUpdate = updates[0].UpdateID
}
lastUpdate = updates[0].UpdateID
if update.UpdateID != 0 {
log.Println("Handling update: ", update)
// run handlers asynchronously
go game.HandleUpdate(client, update)
}
}
game.GameUpdate(client)
time.Sleep(time.Millisecond * 100)
}
}