add failure logging :(

master
GeneralHurricane 2022-12-19 16:04:45 -06:00
parent 9d62be0869
commit a3d0908e19
5 changed files with 35 additions and 10 deletions

View File

@ -1,4 +1,9 @@
# BibleBot # 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<prefix>\w*?)? *(?P<book>[a-zA-Z]+?)\s?(?P<chapter>\d{1,3})(?::(?P<startverse>\d{1,3})(?:-(?P<endverse>\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 ## Setup
@ -19,5 +24,7 @@ MARIADB_PASSWORD=mysafeadminpassword
MARIADB_DATABASE=bible MARIADB_DATABASE=bible
BIBLEDB_HOST=bibledb BIBLEDB_HOST=bibledb
BIBLEBOT_ID= 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!

5
go.mod
View File

@ -2,4 +2,7 @@ module fsdfsd.net/GeneralHurricane/BibleBot
go 1.15 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
)

2
go.sum
View File

@ -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 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= 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=

19
main.go
View File

@ -11,6 +11,7 @@ import (
"time" "time"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/xconstruct/go-pushbullet"
) )
const NAME string = "Tʜᴇ Lʀᴅ" const NAME string = "Tʜᴇ Lʀᴅ"
@ -133,7 +134,8 @@ func main() {
} }
} else { } else {
ERRCOUNT = ERRCOUNT + 1 ERRCOUNT = ERRCOUNT + 1
time.Sleep(ONE_SEC) time.Sleep(WAIT_TIME)
now = time.Now()
continue continue
} }
@ -177,14 +179,23 @@ func main() {
} }
} else { } else {
fmt.Println(err)
ERRCOUNT = ERRCOUNT + 1 ERRCOUNT = ERRCOUNT + 1
if ERRCOUNT > 4 {
log.Fatal(err)
}
} }
time.Sleep(WAIT_TIME) time.Sleep(WAIT_TIME)
now = time.Now() 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) { func handleAndReply(text string, parent_fullname string) {

View File

@ -44,7 +44,9 @@ func (c *RDramaClient) makeRequest(method, path string, body string, response in
defer resp.Body.Close() defer resp.Body.Close()
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) { 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) 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: ") // fmt.Println("reponse: ")
// _, err = io.Copy(os.Stdout, resp.Body) // _, err = io.Copy(os.Stdout, resp.Body)
if err != nil { //if err != nil {
fmt.Println("Error copyng response body: ", err) // fmt.Println("Error copyng response body: ", err)
// handle the error // handle the error
} //}
return nil return nil
} }