Add the ability to pass the bot token via env variable
This commit is contained in:
parent
cf54f5d7f6
commit
a47d0ac378
9
main.go
9
main.go
@ -169,7 +169,7 @@ func (masters masterSlice) Contains(master string) bool {
|
|||||||
// init flags
|
// init flags
|
||||||
func init() {
|
func init() {
|
||||||
// define arguments and parse them.
|
// 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.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(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
|
||||||
flag.StringVar(&Username, "username", "", "Transmission username")
|
flag.StringVar(&Username, "username", "", "Transmission username")
|
||||||
@ -186,6 +186,13 @@ func init() {
|
|||||||
|
|
||||||
flag.Parse()
|
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.
|
// make sure that we have the two madatory arguments: telegram token & master's handler.
|
||||||
if BotToken == "" ||
|
if BotToken == "" ||
|
||||||
len(Masters) < 1 {
|
len(Masters) < 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user