Add the ability to pass the bot token via env variable

This commit is contained in:
pyed 2017-04-09 00:33:21 +03:00
parent cf54f5d7f6
commit a47d0ac378

View File

@ -169,7 +169,7 @@ func (masters masterSlice) Contains(master string) bool {
// init flags
func init() {
// define arguments and parse them.
flag.StringVar(&BotToken, "token", "", "Telegram bot token")
flag.StringVar(&BotToken, "token", "", "Telegram bot token, Can be passed via environment variable 'TT_BOTT'")
flag.Var(&Masters, "master", "Your telegram handler, So the bot will only respond to you. Can specify more than one")
flag.StringVar(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
flag.StringVar(&Username, "username", "", "Transmission username")
@ -186,6 +186,13 @@ func init() {
flag.Parse()
// if we don't have BotToken passed, check the environment variable "TT_BOTT"
if BotToken == "" {
if token := os.Getenv("TT_BOTT"); len(token) > 1 {
BotToken = token
}
}
// make sure that we have the two madatory arguments: telegram token & master's handler.
if BotToken == "" ||
len(Masters) < 1 {