From 851f83a253ac8476e6bc9713221f7ee256827054 Mon Sep 17 00:00:00 2001 From: Abdulelah Alfuntukh Date: Fri, 29 Jul 2016 20:33:31 +0300 Subject: [PATCH] use the EnvVar for user:pass --- transmission-telegram.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/transmission-telegram.go b/transmission-telegram.go index 13abf07..cfb5be7 100644 --- a/transmission-telegram.go +++ b/transmission-telegram.go @@ -19,7 +19,7 @@ import ( ) const ( - VERSION = "1.0" + VERSION = "1.1" HELP = ` *list* or *li* @@ -68,13 +68,13 @@ const ( Takes one or more torrent's IDs to list more info about them. *stop* or *sp* - Takes one or more torrent's IDs to stop them. + Takes one or more torrent's IDs to stop them, or _all_ to stop all torrents. *start* or *st* - Takes one or more torrent's IDs to start them. + Takes one or more torrent's IDs to start them, or _all_ to start all torrents. *check* or *ck* - Takes one or more torrent's IDs to verify them. + Takes one or more torrent's IDs to verify them, or _all_ to verify all torrents. *del* Takes one or more torrent's IDs to delete them. @@ -98,6 +98,7 @@ const ( Shows version numbers. - Prefix commands with '/' if you want to talk to your bot in a group. + - report any issues [here](https://github.com/pyed/transmission-telegram) ` ) @@ -106,7 +107,7 @@ var ( // flags BotToken string Master string - RpcUrl string + RPCURL string Username string Password string LogFile string @@ -137,7 +138,7 @@ func init() { // define arguments and parse them. flag.StringVar(&BotToken, "token", "", "Telegram bot token") flag.StringVar(&Master, "master", "", "Your telegram handler, So the bot will only respond to you") - 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(&Password, "password", "", "Transmission password") flag.StringVar(&LogFile, "logfile", "", "Send logs to a file") @@ -169,12 +170,23 @@ func init() { } log.SetOutput(logf) } + + // if the `-username` flag isn't set, look into the environment variable 'TR_AUTH' + if Username == "" { + if values := strings.Split(os.Getenv("TR_AUTH"), ":"); len(values) > 1 { + Username, Password = values[0], values[1] + } + } + + // log the flags + log.Printf("[INFO] Token=%s\nMaster=%s\nURL=%s\nUSER=%s\nPASS=%s", + BotToken, Master, RPCURL, Username, Password) } // init transmission func init() { var err error - Client, err = transmission.New(RpcUrl, Username, Password) + Client, err = transmission.New(RPCURL, Username, Password) if err != nil { fmt.Fprintf(os.Stderr, "[ERROR] Transmission: Make sure you have the right URL, Username and Password") os.Exit(1)