-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (71 loc) · 1.48 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
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
var (
version string
buildDate string
commitID string
)
func main() {
app := &cli.App{
Name: "telepush",
Usage: "Telegram Bot push tool",
Version: fmt.Sprintf("%s %s %s", version, commitID, buildDate),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "addr",
Usage: "Server listen address",
EnvVars: []string{"TELEPUSH_ADDRESS"},
Value: "0.0.0.0:8080",
},
&cli.StringFlag{
Name: "token",
Usage: "Server push token",
EnvVars: []string{"TELEPUSH_TOKEN"},
Required: true,
},
&cli.StringFlag{
Name: "bot-api",
Usage: "Telegram api address",
EnvVars: []string{"TELEPUSH_BOT_API"},
Value: "https://api.telegram.org",
},
&cli.StringFlag{
Name: "bot-token",
Usage: "Telegram api token",
EnvVars: []string{"TELEPUSH_BOT_TOKEN"},
Required: true,
},
},
Authors: []*cli.Author{
{
Name: "mritd",
Email: "[email protected]",
},
},
Action: func(c *cli.Context) error {
conf = Config{
Addr: c.String("addr"),
Token: c.String("token"),
BotApiAddr: c.String("bot-api"),
BotApiToken: c.String("bot-token"),
}
var err error
bot, err = NewTelegram(conf.BotApiAddr, conf.BotApiToken)
if err != nil {
return err
}
logger.Info("Telegram Bot init success...")
Serve()
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}