more data!

This commit is contained in:
Matt Burchett 2018-07-19 11:03:25 -05:00
parent 974e92a96d
commit 5a0d49cde6
4 changed files with 56 additions and 29 deletions

7
config-example.json Normal file
View File

@ -0,0 +1,7 @@
{
"BotToken": "your_bot_token",
"SonarrAPIURL": "http://example.com/tv/api/",
"SonarrAPIKey": "your key",
"PlexPyAPIURL": "http://example.com/plexpy/api/v2",
"PlexPyAPIKey": "your key"
}

View File

@ -1,5 +0,0 @@
{
"Token": "546410284:AAHXKhEsAB5OZTrAXCFI4kiZSFjN5i0h_wk",
"SonarrAPIURL": "http://dvr.linuxrocker.com/tv/api/",
"SonarrAPIKey": "69e7a095a1c94f42b150380864a6c92a"
}

Binary file not shown.

73
main.go
View File

@ -13,43 +13,43 @@ import (
// 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
BotToken string
SonarrAPIURL string
SonarrAPIKey string
PlexPyAPIURL string
PlexPyAPIKey string
// RadarrAPIURL string
// RadarrAPIKey string
// CouchPotatoAPIURL string
// CouchPotatoAPIKey string
// PlexAPIURL string
// PlexAPIKey string
}
func sonarrStatus(message *tbot.Message) {
response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey)
r, 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)
rd, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
message.Replyf("%s", responseData)
message.Replyf("%s", rd)
}
func sonarrVersion(message *tbot.Message) {
response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey)
r, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey)
if err != nil {
log.Fatal(err)
}
responseData, err := ioutil.ReadAll(response.Body)
rd, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
@ -58,19 +58,42 @@ func sonarrVersion(message *tbot.Message) {
Version string `json:"version"`
}
version := Version{}
jsonErr := json.Unmarshal(responseData, &version)
if jsonErr != nil {
log.Fatal(jsonErr)
v := Version{}
jv := json.Unmarshal(rd, &v)
if jv != nil {
log.Fatal(jv)
}
message.Replyf("%s", version.Version)
message.Replyf("%s", v.Version)
}
// func activeSteamers(message *tbot.Message) {
// response, err := http.Get(Config.PlexAPIURL + "api/v2?apikey=" + Config.PlexAPIKey + "&cmd=")
// }
func activeSteamers(message *tbot.Message) {
r, err := http.Get(Config.PlexPyAPIURL + "?apikey=" + Config.PlexPyAPIKey + "&cmd=get_activity")
if err != nil {
log.Fatal(err)
}
rd, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
type Activity struct {
StreamCount int `json:"stream_count"`
StreamCountDirectPlay int `json:"stream_count_direct_play"`
StreamCountDirectStream int `json:"stream_count_direct_stream"`
StreamCountTranscode int `json:"stream_count_transcode"`
}
a := Activity{}
ja := json.Unmarshal(rd, &a)
if ja != nil {
log.Fatal(ja)
}
message.Replyf("Stream Count: %v \nStream Count (Direct Play): %v \nStream Count (Direct Stream): %v \nStream Count (Transcode): %v", a.StreamCount, a.StreamCountDirectPlay, a.StreamCountDirectStream, a.StreamCountTranscode)
}
func main() {
c := flag.String("c", "./config.json", "Specify the configuration file.")
@ -100,6 +123,8 @@ func main() {
bot.HandleFunc("/sonarr_version", sonarrVersion)
bot.HandleFunc("/activity", activeSteamers)
// Start Listening
err = bot.ListenAndServe()
log.Fatal(err)