-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (44 loc) · 986 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
package main
import (
"flag"
"log"
"os"
"strings"
"time"
)
func main() {
// Get API key from command line
apiKey := ""
cmdKey := flag.String("token", "", "Telegram API token")
flag.Parse()
if cmdKey != nil && *cmdKey != "" {
apiKey = *cmdKey
} else {
// Get API Key from environment
for _, key := range os.Environ() {
if strings.HasPrefix(key, "IPBOT_API_KEY=") {
apiKey = strings.SplitN(key, "=", 2)[1]
break
}
}
}
if apiKey == "" {
log.Fatal("You must provide Telegram token (-token <telegram token> or environment variable IPBOT_API_KEY)")
}
for {
// Build the bot
bot, err := NewBot(apiKey)
if err != nil {
log.Println("Failed to create bot (", err, "), retrying in 30 seconds...")
time.Sleep(30 * time.Second)
continue
}
// Register handlers
interfaces := RegisterIP(bot)
RegisterVLAN(bot, interfaces)
// Loop
bot.Loop()
log.Print("Loop exited, retrying in 30 seconds...")
time.Sleep(30 * time.Second)
}
}