-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (69 loc) · 1.8 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
package main
import (
"log"
"os"
"github.com/MidyMidy-MC/factorio-bot/tgbot"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
}
func main() {
flags := []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "config yaml file",
Aliases: []string{"c"},
Value: "config.yaml",
},
altsrc.NewStringFlag(&cli.StringFlag{
Name: "token",
Usage: "telegram bot token",
Aliases: []string{"t"},
EnvVars: []string{"TGBOT_TOKEN", "TOKEN"},
Required: true,
}),
altsrc.NewInt64Flag(&cli.Int64Flag{
Name: "group-id",
Usage: "telegram group ID, must less than 0",
Aliases: []string{"g"},
EnvVars: []string{"TG_GID"},
Required: true,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "rcon-address",
Usage: "address for factorio rcon",
Aliases: []string{"addr", "address", "r"},
EnvVars: []string{"RCON_ADDR"},
Required: true,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "rcon-password",
Usage: "password for factorio rcon",
Aliases: []string{"password", "p"},
EnvVars: []string{"RCON_PASSWORD", "PASSWORD"},
Required: true,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "tech-translation-file",
Usage: "key-value file for tech translation",
Value: "tech-translation.yaml",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "api-url",
Usage: "Telegram bot API URL",
Value: "https://api.telegram.org/bot%s/%s",
EnvVars: []string{"TG_API_URL"},
}),
}
app := &cli.App{
Name: "factorio-bot",
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("config")),
Flags: flags,
Action: tgbot.Run,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}