diff --git a/config.json b/config.json index ea75b84..8bfa7a7 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,5 @@ { -"Token": "546410284:AAHXKhEsAB5OZTrAXCFI4kiZSFjN5i0h_wk" +"Token": "546410284:AAHXKhEsAB5OZTrAXCFI4kiZSFjN5i0h_wk", +"SonarrAPIURL": "http://dvr.linuxrocker.com/tv/api/", +"SonarrAPIKey": "69e7a095a1c94f42b150380864a6c92a" } \ No newline at end of file diff --git a/go_telegram b/go_telegram index 266d3dd..ae5505c 100755 Binary files a/go_telegram and b/go_telegram differ diff --git a/main.go b/main.go index 239a4cb..bbefbe1 100644 --- a/main.go +++ b/main.go @@ -3,19 +3,75 @@ package main import ( "encoding/json" "flag" + "io/ioutil" "log" + "net/http" "os" - "time" - tb "gopkg.in/tucnak/telebot.v2" + "github.com/yanzay/tbot" ) -// Configuration - Specify what to look for in Config file -type Configuration struct { - Token string +// Config - Specify what to look for in Config file +var Config struct { + BotToken string + SonarrAPIURL string + SonarrAPIKey string + PlexPyAPIURL string + PlexPyAPIKey string + RadarrAPIURL string + RadarrAPIKey string + CouchPotatoAPIURL string + CouchPotatoAPIKey string + PlexAPIURL string + PlexAPIKey string } -// ReadConfig from file +func sonarrStatus(message *tbot.Message) { + response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) + + if err != nil { + log.Fatal(err) + os.Exit(1) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Fatal(err) + } + + message.Replyf("%s", responseData) + +} + +func sonarrVersion(message *tbot.Message) { + response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) + if err != nil { + log.Fatal(err) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Fatal(err) + } + + type Version struct { + Version string `json:"version"` + } + + version := Version{} + jsonErr := json.Unmarshal(responseData, &version) + if jsonErr != nil { + log.Fatal(jsonErr) + } + + message.Replyf("%s", version.Version) + +} + +// func activeSteamers(message *tbot.Message) { +// response, err := http.Get(Config.PlexAPIURL + "api/v2?apikey=" + Config.PlexAPIKey + "&cmd=") +// } + func main() { c := flag.String("c", "./config.json", "Specify the configuration file.") flag.Parse() @@ -25,27 +81,27 @@ func main() { } defer file.Close() decoder := json.NewDecoder(file) - Config := Configuration{} err = decoder.Decode(&Config) if err != nil { log.Fatal("can't decode config JSON: ", err) } - b, err := tb.NewBot(tb.Settings{ - Token: Config.Token, - Poller: &tb.LongPoller{Timeout: 10 * time.Second}, - }) - + bot, err := tbot.NewServer(Config.BotToken) if err != nil { log.Fatal(err) - return } - b.Handle("/ping", func(m *tb.Message) { - b.Send(m.Sender, "pong") - }) + whitelist := []string{"WARBIRD199"} + bot.AddMiddleware(tbot.NewAuth(whitelist)) - log.Print("Starting bot...") + bot.Handle("/ping", "pong!") + + bot.HandleFunc("/sonarr_status", sonarrStatus) + + bot.HandleFunc("/sonarr_version", sonarrVersion) + + // Start Listening + err = bot.ListenAndServe() + log.Fatal(err) - b.Start() }