diff --git a/README.md b/README.md index 0b06034..64b3fe5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # BibleBot +Written by GeneralHurricane and GPT-CHAT (any errors are the fault of GPT-CHAT) + +## Info + +BibleBot regularly scans posts and comments for things that look like Bible refences `(?P\w*?)? *(?P[a-zA-Z]+?)\s?(?P\d{1,3})(?::(?P\d{1,3})(?:-(?P\d{1,3})?)?)`, then supplies them from the MariaDb container. It supports World English Bible by default, but has options for KJV, ASV, and a few more public domain translations. ## Setup @@ -19,5 +24,7 @@ MARIADB_PASSWORD=mysafeadminpassword MARIADB_DATABASE=bible BIBLEDB_HOST=bibledb BIBLEBOT_ID= +PUSHBULLET_KEY= +PUSHBULLET_DEVICE_ID= ``` -Fill in your `RDRAMA_API_TOKEN` and `BIBLEBOT_ID`. You can change the user and password. +Fill in your `RDRAMA_API_TOKEN` and `BIBLEBOT_ID`. You can change the user and password for the MARIADB - both containers will pick up the same config. Optionally add a Pushbullet key and device ID if you want to get a notification when BibleBot inevitably crashes. It sorta uses backoff and retry on failed API calls, but not enough really. Feel free to open a PR! diff --git a/go.mod b/go.mod index 7f5910e..654d583 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module fsdfsd.net/GeneralHurricane/BibleBot go 1.15 -require github.com/go-sql-driver/mysql v1.7.0 +require ( + github.com/go-sql-driver/mysql v1.7.0 + github.com/xconstruct/go-pushbullet v0.0.0-20171206132031-67759df45fbb // indirect +) diff --git a/go.sum b/go.sum index 7109e4c..985fc1b 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/xconstruct/go-pushbullet v0.0.0-20171206132031-67759df45fbb h1:m+CPNoRrlFVxLKZeodSyEc9cc1GBWYJutHO/eOByUo8= +github.com/xconstruct/go-pushbullet v0.0.0-20171206132031-67759df45fbb/go.mod h1:OdGNyFi3/K/Fl/3pZu3lAGKMBhTQDl9Lgjn08LSA95Q= diff --git a/main.go b/main.go index c9b3f96..6e75312 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "time" _ "github.com/go-sql-driver/mysql" + "github.com/xconstruct/go-pushbullet" ) const NAME string = "Tʜᴇ Lᴏʀᴅ" @@ -133,7 +134,8 @@ func main() { } } else { ERRCOUNT = ERRCOUNT + 1 - time.Sleep(ONE_SEC) + time.Sleep(WAIT_TIME) + now = time.Now() continue } @@ -177,14 +179,23 @@ func main() { } } else { + fmt.Println(err) ERRCOUNT = ERRCOUNT + 1 - if ERRCOUNT > 4 { - log.Fatal(err) - } } time.Sleep(WAIT_TIME) now = time.Now() } + + // tell pushbullet that Biblebot failed + pushbullet_key := os.Getenv("PUSHBULLET_KEY") + pushbullet_device := os.Getenv("PUSHBULLET_DEVICE_ID") + if pushbullet_key != "" && pushbullet_device != "" { + pb := pushbullet.New(pushbullet_key) + err = pb.PushNote(pushbullet_device, "Biblebot shut down due to error", err.Error()) + if err != nil { + fmt.Println("Pushbullet error reporting failed") + } + } } func handleAndReply(text string, parent_fullname string) { diff --git a/rdrama.go b/rdrama.go index 4c12e7e..86829c9 100644 --- a/rdrama.go +++ b/rdrama.go @@ -44,7 +44,9 @@ func (c *RDramaClient) makeRequest(method, path string, body string, response in defer resp.Body.Close() if !(resp.StatusCode >= 200 && resp.StatusCode < 300) { - fmt.Println("request:\n", req) + fmt.Println("Status code: ", resp.StatusCode) + fmt.Println(method, ": ", url) + fmt.Println(body) return fmt.Errorf("unexpected status code: %d", resp.StatusCode) } @@ -53,10 +55,10 @@ func (c *RDramaClient) makeRequest(method, path string, body string, response in } // fmt.Println("reponse: ") // _, err = io.Copy(os.Stdout, resp.Body) - if err != nil { - fmt.Println("Error copyng response body: ", err) + //if err != nil { + // fmt.Println("Error copyng response body: ", err) // handle the error - } + //} return nil }