Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba2156133a | ||
|
|
60c88375ad | ||
|
|
a127d9fd25 | ||
|
|
8c6b55301d | ||
|
|
3c36948269 | ||
|
|
bc2efe928a | ||
|
|
e1b4460ebd | ||
|
|
9bb9929ff6 | ||
|
|
a6c1b8505a | ||
|
|
c755aa88fb | ||
|
|
b451ed93bf | ||
|
|
76b7211d6c | ||
|
|
31a608d7f8 | ||
|
|
0c3419a1fb | ||
|
|
6ea4d4700c | ||
|
|
451f741f5a | ||
|
|
ecf22c3a3d | ||
|
|
ced1afff88 | ||
|
|
ffa33ea299 | ||
|
|
92b6019052 | ||
|
|
6a2b2f38d0 | ||
|
|
d4c1e20230 | ||
|
|
f2c9602d70 | ||
|
|
744365b9d3 | ||
|
|
16bdc174d4 | ||
|
|
d3381749f7 | ||
|
|
55848d6c7d | ||
|
|
f9819350ad | ||
|
|
7062094234 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ cmd/cmd
|
|||||||
cmd/cli
|
cmd/cli
|
||||||
cmd/pttodo/pttodo
|
cmd/pttodo/pttodo
|
||||||
/truckstop
|
/truckstop
|
||||||
|
/exec-truckstop
|
||||||
|
|||||||
@@ -2,9 +2,15 @@ package broker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"local/storage"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"local/truckstop/logtr"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/cookiejar"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
@@ -20,9 +26,54 @@ type Broker interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func do(r *http.Request) (*http.Response, error) {
|
func do(r *http.Request) (*http.Response, error) {
|
||||||
|
return _do(config.Get().DB(), r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _do(db storage.DB, r *http.Request) (*http.Response, error) {
|
||||||
limiter.Wait(context.Background())
|
limiter.Wait(context.Background())
|
||||||
if strings.Contains(strings.ToLower(r.URL.Path), "login") {
|
if strings.Contains(strings.ToLower(r.URL.Path), "login") {
|
||||||
authlimiter.Wait(context.Background())
|
authlimiter.Wait(context.Background())
|
||||||
}
|
}
|
||||||
return http.DefaultClient.Do(r)
|
client := &http.Client{
|
||||||
|
Timeout: time.Hour,
|
||||||
|
}
|
||||||
|
newjar, err := cookiejar.New(&cookiejar.Options{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("failed to make a cookie jar: " + err.Error())
|
||||||
|
}
|
||||||
|
client.Jar = newjar
|
||||||
|
|
||||||
|
cookieJarKey := "cookies_" + r.URL.Host
|
||||||
|
cookies, err := getCookies(db, cookieJarKey)
|
||||||
|
if err != nil {
|
||||||
|
logtr.Errorf("failed to load cookies: %v", err)
|
||||||
|
} else {
|
||||||
|
client.Jar.SetCookies(r.URL, cookies)
|
||||||
|
}
|
||||||
|
resp, err := client.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := setCookies(db, cookieJarKey, client.Jar.Cookies(r.URL)); err != nil {
|
||||||
|
logtr.Errorf("failed to set cookies: %v", err)
|
||||||
|
}
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCookies(db storage.DB, host string) ([]*http.Cookie, error) {
|
||||||
|
b, err := db.Get(host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result []*http.Cookie
|
||||||
|
err = json.Unmarshal(b, &result)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func setCookies(db storage.DB, host string, cookies []*http.Cookie) error {
|
||||||
|
b, err := json.Marshal(cookies)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return db.Set(host, b)
|
||||||
}
|
}
|
||||||
|
|||||||
59
broker/broker_test.go
Normal file
59
broker/broker_test.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package broker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"local/storage"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/time/rate"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDoCookies(t *testing.T) {
|
||||||
|
limiter = rate.NewLimiter(rate.Limit(20.0), 1)
|
||||||
|
calls := 0
|
||||||
|
db := storage.NewMap()
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
calls += 1
|
||||||
|
if calls == 1 {
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: "name",
|
||||||
|
Value: "value",
|
||||||
|
Expires: time.Now().Add(time.Hour),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value") {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
t.Error("cookie not set on calls after first")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
req, _ := http.NewRequest(http.MethodGet, s.URL, nil)
|
||||||
|
|
||||||
|
if cookies, err := getCookies(db, "cookies_"+req.URL.Host); err == nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if len(cookies) != 0 {
|
||||||
|
t.Fatal(cookies)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
resp, err := _do(db, req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Fatal(resp.StatusCode)
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if cookies, err := getCookies(db, "cookies_"+req.URL.Host); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if len(cookies) == 0 {
|
||||||
|
t.Fatal(cookies)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package broker
|
package broker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
"local/truckstop/logtr"
|
"local/truckstop/logtr"
|
||||||
@@ -16,7 +17,8 @@ type Job struct {
|
|||||||
Weight int
|
Weight int
|
||||||
Miles int
|
Miles int
|
||||||
Meta string
|
Meta string
|
||||||
secrets func() interface{} `json:"-"`
|
Pays string
|
||||||
|
secrets func(j *Job) `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobLocation struct {
|
type JobLocation struct {
|
||||||
@@ -25,16 +27,23 @@ type JobLocation struct {
|
|||||||
State string
|
State string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j Job) UID() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"%v-%s-%s-%s-%s-%v",
|
||||||
|
j.ID,
|
||||||
|
j.Pickup.State,
|
||||||
|
base64.StdEncoding.EncodeToString([]byte(j.Pickup.City)),
|
||||||
|
j.Dropoff.State,
|
||||||
|
base64.StdEncoding.EncodeToString([]byte(j.Dropoff.City)),
|
||||||
|
j.Pickup.Date.Unix(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Job) Secrets() {
|
func (j *Job) Secrets() {
|
||||||
if j.secrets == nil {
|
if j.secrets == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v := j.secrets()
|
j.secrets(j)
|
||||||
j.secrets = nil
|
|
||||||
if v == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
j.Meta = fmt.Sprintf("%s %+v", j.Meta, v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j Job) String() string {
|
func (j Job) String() string {
|
||||||
@@ -53,6 +62,19 @@ func (j JobLocation) String() string {
|
|||||||
return fmt.Sprintf("%s, %s @ %s", j.City, j.State, j.Date.Format("Monday Jan 02"))
|
return fmt.Sprintf("%s, %s @ %s", j.City, j.State, j.Date.Format("Monday Jan 02"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j Job) FormatMultilineTextDead() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"no longer available: %s,%s => %s,%s for $%v @%s",
|
||||||
|
j.Pickup.City,
|
||||||
|
j.Pickup.State,
|
||||||
|
j.Dropoff.City,
|
||||||
|
j.Dropoff.State,
|
||||||
|
j.Pays,
|
||||||
|
j.URI,
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (j Job) FormatMultilineText() string {
|
func (j Job) FormatMultilineText() string {
|
||||||
foo := func(client string) string {
|
foo := func(client string) string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
|||||||
|
|
||||||
func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
|
func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
|
||||||
time.Sleep(config.Get().Interval.JobInfo.Get())
|
time.Sleep(config.Get().Interval.JobInfo.Get())
|
||||||
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf(config.Get().Brokers.NTG.LoadPageURIFormat, id), nil)
|
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf(config.Get().Brokers.NTG.LoadPageAPIURIFormat, id), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -143,13 +143,14 @@ func (ntgJob *ntgVisionJob) Job() Job {
|
|||||||
Miles: ntgJob.Miles,
|
Miles: ntgJob.Miles,
|
||||||
Weight: ntgJob.Weight,
|
Weight: ntgJob.Weight,
|
||||||
Meta: fmt.Sprintf("equipment:%s", ntgJob.Equipment),
|
Meta: fmt.Sprintf("equipment:%s", ntgJob.Equipment),
|
||||||
secrets: func() interface{} {
|
secrets: func(j *Job) {
|
||||||
jobInfo, err := ntgJob.JobInfo()
|
jobInfo, err := ntgJob.JobInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logtr.Errorf("failed to get jobinfo: %v", err)
|
logtr.Errorf("failed to get jobinfo: %v", err)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
return jobInfo.String()
|
j.Meta = jobInfo.String()
|
||||||
|
j.Pays = fmt.Sprint(jobInfo.PayUpTo)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,8 +175,15 @@ func (ntg NTGVision) SearchJob(id int64) (ntgVisionJobInfo, error) {
|
|||||||
return ntgVisionJobInfo{}, err
|
return ntgVisionJobInfo{}, err
|
||||||
}
|
}
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
b, err := ioutil.ReadAll(rc)
|
||||||
|
if err != nil {
|
||||||
|
return ntgVisionJobInfo{}, fmt.Errorf("failed to readall search job result: %w", err)
|
||||||
|
}
|
||||||
var result ntgVisionJobInfo
|
var result ntgVisionJobInfo
|
||||||
err = json.NewDecoder(rc).Decode(&result)
|
err = json.Unmarshal(b, &result)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("failed to parse job info: %w: %s", err, b)
|
||||||
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,12 +228,14 @@ func setNTGToken(token string) {
|
|||||||
|
|
||||||
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
||||||
if getNTGToken() == "" {
|
if getNTGToken() == "" {
|
||||||
|
logtr.Debugf("NTG token is empty, refreshing ntg auth")
|
||||||
if err := ntg.refreshAuth(); err != nil {
|
if err := ntg.refreshAuth(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc, err := ntg._search(states)
|
rc, err := ntg._search(states)
|
||||||
if err == ErrNoAuth {
|
if err == ErrNoAuth {
|
||||||
|
logtr.Debugf("err no auth on search, refreshing ntg auth")
|
||||||
if err := ntg.refreshAuth(); err != nil {
|
if err := ntg.refreshAuth(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -287,7 +297,11 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
request2, _ := ntg.newRequest(states)
|
||||||
|
requestb, _ := ioutil.ReadAll(request2.Body)
|
||||||
|
logtr.Debugf("ntg auth bad status: url=%s, status=%v, body=%s, headers=%+v, request=%+v, requestb=%s", request.URL.String(), resp.StatusCode, b, resp.Header, request2, requestb)
|
||||||
|
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
||||||
|
logtr.Debugf("ntg auth bad status: err no auth")
|
||||||
return nil, ErrNoAuth
|
return nil, ErrNoAuth
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("bad status searching ntg: %d: %s", resp.StatusCode, b)
|
return nil, fmt.Errorf("bad status searching ntg: %d: %s", resp.StatusCode, b)
|
||||||
@@ -297,7 +311,7 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
|||||||
|
|
||||||
func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
||||||
body, err := json.Marshal(map[string]interface{}{
|
body, err := json.Marshal(map[string]interface{}{
|
||||||
"OriginFromDate": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
|
"OriginFromDate": time.Now().Add(time.Hour * -24).UTC().Format("2006-01-02T15:04:05.000Z"),
|
||||||
"OriginToDate": time.Now().UTC().Add(time.Hour * 24 * 30).Format("2006-01-02T15:04:05.000Z"),
|
"OriginToDate": time.Now().UTC().Add(time.Hour * 24 * 30).Format("2006-01-02T15:04:05.000Z"),
|
||||||
"DestinationFromDate": nil,
|
"DestinationFromDate": nil,
|
||||||
"DestinationToDate": nil,
|
"DestinationToDate": nil,
|
||||||
|
|||||||
17
broker/testdata/ntgvision_response.json
vendored
17
broker/testdata/ntgvision_response.json
vendored
@@ -1,21 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"id": 4650337,
|
|
||||||
"sDate": "01/12/22",
|
|
||||||
"sCity": "Advance",
|
|
||||||
"sState": "NC",
|
|
||||||
"sdh": null,
|
|
||||||
"cDate": "01/13/22",
|
|
||||||
"cCity": "Sacramento",
|
|
||||||
"cState": "CA",
|
|
||||||
"cdh": null,
|
|
||||||
"stopCnt": 2,
|
|
||||||
"miles": 578,
|
|
||||||
"weight": 5000,
|
|
||||||
"equip": "Str Truck W/ Lift Gate",
|
|
||||||
"temp": "",
|
|
||||||
"alertReasons": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": 4650338,
|
"id": 4650338,
|
||||||
"sDate": "01/12/22",
|
"sDate": "01/12/22",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Log": {
|
"Log": {
|
||||||
"Path": "/tmp/truckstop.log",
|
"Path": "/tmp/truckstop.log",
|
||||||
"Level": "error",
|
"Level": "debug",
|
||||||
"SOSMatrix": {
|
"SOSMatrix": {
|
||||||
"ReceiveEnabled": true,
|
"ReceiveEnabled": true,
|
||||||
"Mock": false,
|
"Mock": false,
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"Pickup": false,
|
"Pickup": false,
|
||||||
"Dropoff": false,
|
"Dropoff": false,
|
||||||
"Pathed": {
|
"Pathed": {
|
||||||
"Enabled": false,
|
"Enabled": true,
|
||||||
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||||
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
|
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
|
||||||
"Zoom": {
|
"Zoom": {
|
||||||
@@ -69,12 +69,13 @@
|
|||||||
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Once": false,
|
"Once": true,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"JobInfo": true,
|
"JobInfo": true,
|
||||||
"Mock": false,
|
"Mock": true,
|
||||||
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
||||||
|
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId==%d",
|
||||||
"Username": "noeasyrunstrucking@gmail.com",
|
"Username": "noeasyrunstrucking@gmail.com",
|
||||||
"Password": "thumper1234"
|
"Password": "thumper1234"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,11 +65,12 @@ type Config struct {
|
|||||||
Once bool
|
Once bool
|
||||||
Brokers struct {
|
Brokers struct {
|
||||||
NTG struct {
|
NTG struct {
|
||||||
JobInfo bool
|
JobInfo bool
|
||||||
Mock bool
|
Mock bool
|
||||||
LoadPageURIFormat string
|
LoadPageURIFormat string
|
||||||
Username string
|
LoadPageAPIURIFormat string
|
||||||
Password string
|
Username string
|
||||||
|
Password string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -30,6 +30,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.2.0 // indirect
|
github.com/golang/protobuf v1.2.0 // indirect
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
github.com/gomodule/redigo v1.8.5 // indirect
|
github.com/gomodule/redigo v1.8.5 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||||
github.com/json-iterator/go v1.1.9 // indirect
|
github.com/json-iterator/go v1.1.9 // indirect
|
||||||
github.com/klauspost/compress v1.9.5 // indirect
|
github.com/klauspost/compress v1.9.5 // indirect
|
||||||
|
|||||||
13
logtr/log.go
13
logtr/log.go
@@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -83,16 +82,18 @@ func SetLevel(l Level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logf(l Level, format string, args []interface{}) {
|
func logf(l Level, format string, args []interface{}) {
|
||||||
format = fmt.Sprintf("%v: %v: %s\n", time.Now().Format("15:04:05"), l.String(), strings.TrimSpace(format))
|
format = fmt.Sprintf("%v: %v: %s\n", time.Now().Format("01-02T15:04:05"), l.String(), strings.TrimSpace(format))
|
||||||
|
logContent := strings.ReplaceAll(fmt.Sprintf(format, args...), "\n", "") + "\n"
|
||||||
cLevel := level
|
cLevel := level
|
||||||
cAnsoser := ansoser
|
cAnsoser := ansoser
|
||||||
if l >= cLevel {
|
if l >= cLevel {
|
||||||
fmt.Fprintf(os.Stderr, format, args...)
|
fmt.Fprint(os.Stderr, logContent)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(logger, format, args...)
|
fmt.Fprint(logger, logContent)
|
||||||
log.Printf("l==sos=%v, ansoser!=nil=%v", l == SOS, ansoser != nil)
|
|
||||||
if l == SOS && cAnsoser != nil {
|
if l == SOS && cAnsoser != nil {
|
||||||
cAnsoser.Send(fmt.Sprintf(format, args...))
|
if err := cAnsoser.Send(logContent); err != nil {
|
||||||
|
Errorf("failed to SOS: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
101
main.go
101
main.go
@@ -26,6 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
if config.Get().Message.Matrix.ReceiveEnabled {
|
if config.Get().Message.Matrix.ReceiveEnabled {
|
||||||
if err := matrixrecv(); err != nil {
|
if err := matrixrecv(); err != nil {
|
||||||
|
logtr.SOSf("failed to recv matrix on boot: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +48,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := _main(); err != nil {
|
if err := _main(); err != nil {
|
||||||
|
logtr.SOSf("failed _main: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
@@ -233,7 +235,7 @@ func _main() error {
|
|||||||
logtr.Errorf("failed _main: %v", err)
|
logtr.Errorf("failed _main: %v", err)
|
||||||
}
|
}
|
||||||
if config.Get().Once {
|
if config.Get().Once {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -265,6 +267,11 @@ func once() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
logtr.Debugf("once: update dead jobs: %+v", alljobs)
|
||||||
|
err = updateDeadJobs(alljobs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
logtr.Debugf("once: all jobs: %+v", alljobs)
|
logtr.Debugf("once: all jobs: %+v", alljobs)
|
||||||
newjobs, err := dropStaleJobs(alljobs)
|
newjobs, err := dropStaleJobs(alljobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -275,17 +282,22 @@ func once() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
logtr.Debugf("found jobs: %+v", jobs)
|
||||||
|
if len(jobs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
logtr.Debugf("once: loading job secrets: %+v", jobs)
|
logtr.Debugf("once: loading job secrets: %+v", jobs)
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
jobs[i].Secrets()
|
jobs[i].Secrets()
|
||||||
}
|
}
|
||||||
logtr.Infof("once: sending jobs: %+v", jobs)
|
logtr.Infof("once: sending jobs: %+v", jobs)
|
||||||
|
db := config.Get().DB()
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
if ok, err := sendJob(jobs[i]); err != nil {
|
if ok, err := sendJob(jobs[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ok {
|
} else if ok {
|
||||||
logtr.Debugf("sent job", jobs[i])
|
logtr.Debugf("sent job", jobs[i])
|
||||||
if err := config.Get().DB().Set(jobs[i].ID, []byte(`sent`)); err != nil {
|
if err := db.Set(jobs[i].UID(), []byte(`sent`)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,10 +320,61 @@ func getJobs() ([]broker.Job, error) {
|
|||||||
return jobs, nil
|
return jobs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type recordedJob struct {
|
||||||
|
Job broker.Job
|
||||||
|
SentNS int64
|
||||||
|
MatrixID string
|
||||||
|
MatrixImageIDs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateDeadJobs(jobs []broker.Job) error {
|
||||||
|
db := config.Get().DB()
|
||||||
|
list, err := db.List([]string{}, "sent_job_", "sent_job_}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, listEntry := range list {
|
||||||
|
wouldBe := strings.TrimPrefix(listEntry, "sent_job_")
|
||||||
|
found := false
|
||||||
|
for i := range jobs {
|
||||||
|
found = found || jobs[i].ID == wouldBe
|
||||||
|
}
|
||||||
|
logtr.Debugf("found job %s to be still alive==%v", wouldBe, found)
|
||||||
|
if !found {
|
||||||
|
logtr.Debugf("updating dead job %+v", listEntry)
|
||||||
|
b, err := db.Get(listEntry)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var recorded recordedJob
|
||||||
|
if err := json.Unmarshal(b, &recorded); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
/* // TODO this beeps on fluffychat
|
||||||
|
if err := message.NewMatrix().Update(recorded.MatrixID, recorded.Job.FormatMultilineTextDead()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if err := message.NewMatrix().Remove(recorded.MatrixID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := db.Set(listEntry, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, imageid := range recorded.MatrixImageIDs {
|
||||||
|
if err := message.NewMatrix().Remove(imageid); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func dropStaleJobs(jobs []broker.Job) ([]broker.Job, error) {
|
func dropStaleJobs(jobs []broker.Job) ([]broker.Job, error) {
|
||||||
db := config.Get().DB()
|
db := config.Get().DB()
|
||||||
for i := len(jobs) - 1; i >= 0; i-- {
|
for i := len(jobs) - 1; i >= 0; i-- {
|
||||||
if _, err := db.Get(jobs[i].ID); err == storage.ErrNotFound {
|
if _, err := db.Get(jobs[i].UID()); err == storage.ErrNotFound {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
@@ -333,9 +396,27 @@ func sendJob(job broker.Job) (bool, error) {
|
|||||||
if len(payload) == 0 {
|
if len(payload) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if err := sender.Send(payload); err != nil {
|
id, err := sender.SendTracked(payload)
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
recordedJob := recordedJob{
|
||||||
|
Job: job,
|
||||||
|
SentNS: time.Now().UnixNano(),
|
||||||
|
MatrixID: id,
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
db := config.Get().DB()
|
||||||
|
b, err := json.Marshal(recordedJob)
|
||||||
|
if err != nil {
|
||||||
|
logtr.Errorf("failed to marshal recorded job: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := db.Set("sent_job_"+job.ID, b); err != nil {
|
||||||
|
logtr.Errorf("failed to set recorded job: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
maps := config.Get().Maps
|
maps := config.Get().Maps
|
||||||
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
||||||
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
||||||
@@ -393,24 +474,30 @@ func sendJob(job broker.Job) (bool, error) {
|
|||||||
uri = fmt.Sprintf("%s&zoom=%d", uri, maps.Pathed.Zoom.Override)
|
uri = fmt.Sprintf("%s&zoom=%d", uri, maps.Pathed.Zoom.Override)
|
||||||
}
|
}
|
||||||
logtr.Debugf("sending pathed image: %s", uri)
|
logtr.Debugf("sending pathed image: %s", uri)
|
||||||
if err := sender.SendImage(uri); err != nil {
|
pathedid, err := sender.SendImageTracked(uri)
|
||||||
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
recordedJob.MatrixImageIDs = append(recordedJob.MatrixImageIDs, pathedid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if maps.Pickup {
|
if maps.Pickup {
|
||||||
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
|
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
|
||||||
logtr.Debugf("sending pickup image: %s", uri)
|
logtr.Debugf("sending pickup image: %s", uri)
|
||||||
if err := sender.SendImage(uri); err != nil {
|
pickupid, err := sender.SendImageTracked(uri)
|
||||||
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
recordedJob.MatrixImageIDs = append(recordedJob.MatrixImageIDs, pickupid)
|
||||||
}
|
}
|
||||||
if maps.Dropoff {
|
if maps.Dropoff {
|
||||||
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
|
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
|
||||||
logtr.Debugf("sending dropoff image: %s", uri)
|
logtr.Debugf("sending dropoff image: %s", uri)
|
||||||
if err := sender.SendImage(uri); err != nil {
|
dropid, err := sender.SendImageTracked(uri)
|
||||||
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
recordedJob.MatrixImageIDs = append(recordedJob.MatrixImageIDs, dropid)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||||||
logtr.Debugf("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk))
|
logtr.Debugf("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk))
|
||||||
m.continuation = result.End
|
m.continuation = result.End
|
||||||
for _, event := range result.Chunk {
|
for _, event := range result.Chunk {
|
||||||
|
logtr.Verbosef("matrix event: %+v", event)
|
||||||
if _, ok := matrixIDs[event.Sender]; !ok {
|
if _, ok := matrixIDs[event.Sender]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -124,50 +125,114 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||||||
return messages, nil
|
return messages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Matrix) Send(text string) error {
|
func (m Matrix) Remove(id string) error {
|
||||||
if m.mock {
|
if m.mock {
|
||||||
logtr.Infof("matrix.Send(%s)", text)
|
logtr.Infof("matrix.Remove(%s)", id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c, err := m.getclient()
|
c, err := m.getclient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = c.SendText(m.room, text)
|
_, err = c.RedactEvent(m.room, id, &gomatrix.ReqRedact{Reason: "stale"})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Matrix) Update(id, text string) error {
|
||||||
|
if m.mock {
|
||||||
|
logtr.Infof("matrix.Update(%s)", text)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
c, err := m.getclient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
type MRelatesTo struct {
|
||||||
|
EventID string `json:"event_id"`
|
||||||
|
RelType string `json:"rel_type"`
|
||||||
|
}
|
||||||
|
type NewContent struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
MsgType string `json:"msgtype"`
|
||||||
|
}
|
||||||
|
type RelatesToRoomMessage struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
MsgType string `json:"msgtype"`
|
||||||
|
MRelatesTo MRelatesTo `json:"m.relates_to"`
|
||||||
|
MNewContent NewContent `json:"m.new_content"`
|
||||||
|
}
|
||||||
|
_, err = c.SendMessageEvent(m.room, "m.room.message", RelatesToRoomMessage{
|
||||||
|
Body: "",
|
||||||
|
MsgType: "m.text",
|
||||||
|
MNewContent: NewContent{
|
||||||
|
Body: text,
|
||||||
|
MsgType: "m.text",
|
||||||
|
},
|
||||||
|
MRelatesTo: MRelatesTo{
|
||||||
|
EventID: id,
|
||||||
|
RelType: "m.replace",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Matrix) Send(text string) error {
|
||||||
|
_, err := m.SendTracked(text)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Matrix) SendTracked(text string) (string, error) {
|
||||||
|
if m.mock {
|
||||||
|
logtr.Infof("matrix.SendTracked(%s)", text)
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
c, err := m.getclient()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
resp, err := c.SendText(m.room, text)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return resp.EventID, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m Matrix) SendImage(uri string) error {
|
func (m Matrix) SendImage(uri string) error {
|
||||||
|
_, err := m.SendImageTracked(uri)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Matrix) SendImageTracked(uri string) (string, error) {
|
||||||
if m.mock {
|
if m.mock {
|
||||||
logtr.Infof("matrix.SendImage(%s)", uri)
|
logtr.Infof("matrix.SendImage(%s)", uri)
|
||||||
return nil
|
return "", nil
|
||||||
}
|
}
|
||||||
response, err := http.Get(uri)
|
response, err := http.Get(uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
b, _ := ioutil.ReadAll(response.Body)
|
b, _ := ioutil.ReadAll(response.Body)
|
||||||
response.Body.Close()
|
response.Body.Close()
|
||||||
return fmt.Errorf("failed to get %s: (%d) %s", uri, response.StatusCode, b)
|
return "", fmt.Errorf("failed to get %s: (%d) %s", uri, response.StatusCode, b)
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadAll(response.Body)
|
b, err := ioutil.ReadAll(response.Body)
|
||||||
response.Body.Close()
|
response.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
c, err := m.getclient()
|
c, err := m.getclient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
publicURI := mediaUpload.ContentURI
|
publicURI := mediaUpload.ContentURI
|
||||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||||
logtr.Debugf("sent image %s => %s: %+v", uri, publicURI, resp)
|
logtr.Debugf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||||
return err
|
return resp.EventID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetMatrixContinuation(continuation string) {
|
func SetMatrixContinuation(continuation string) {
|
||||||
|
|||||||
@@ -1,57 +1,65 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMatrixSend(t *testing.T) {
|
func TestMatrixSendDel(t *testing.T) {
|
||||||
if len(os.Getenv("INTEGRATION")) == 0 {
|
sender := testMatrix(t)
|
||||||
t.Skip("$INTEGRATION not set")
|
if id, err := sender.SendTracked("hello world from unittest"); err != nil {
|
||||||
}
|
|
||||||
var c config.Config
|
|
||||||
b, err := ioutil.ReadFile("../config.json")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if err := sender.Remove(id); err != nil {
|
||||||
if err := json.Unmarshal(b, &c); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
var sender Sender = &Matrix{
|
|
||||||
homeserver: c.Message.Matrix.Homeserver,
|
|
||||||
username: c.Message.Matrix.Username,
|
|
||||||
token: c.Message.Matrix.Token,
|
|
||||||
room: c.Message.Matrix.Room,
|
|
||||||
}
|
|
||||||
if err := sender.Send("hello world from unittest"); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixReceive(t *testing.T) {
|
func TestMatrixUpdate(t *testing.T) {
|
||||||
if len(os.Getenv("INTEGRATION")) == 0 {
|
// 19:32:34: VER: matrix event: {StateKey:<nil> Sender:@bot:m.bltrucks.top Type:m.room.message Timestamp:1642471594729 ID:$n0ln9TFZrko_cBNFXeh8YyICZ3fFm17Jhz3bmZcqig4 RoomID:!OYZqtInrBCn1cyz90D:m.bltrucks.top Redacts: Unsigned:map[transaction_id:go1642471594571852423] Content:map[body:hello world from unittest format: formatted_body: msgtype:m.text] PrevContent:map[]}
|
||||||
t.Skip("$INTEGRATION not set")
|
// func (m Matrix) Update(id, text string) error {
|
||||||
}
|
m := testMatrix(t)
|
||||||
var c config.Config
|
uid := uuid.New().String()[:3]
|
||||||
b, err := ioutil.ReadFile("../config.json")
|
id, err := m.SendTracked("hello, heheheh from test matrix update " + uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(b, &c); err != nil {
|
err = m.Update(id, "heheheh i updated from test matrix update "+uid)
|
||||||
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var sender Sender = &Matrix{
|
m.Receive()
|
||||||
homeserver: c.Message.Matrix.Homeserver,
|
}
|
||||||
username: c.Message.Matrix.Username,
|
|
||||||
token: c.Message.Matrix.Token,
|
func TestMatrixReceive(t *testing.T) {
|
||||||
room: c.Message.Matrix.Room,
|
sender := testMatrix(t)
|
||||||
}
|
|
||||||
if msgs, err := sender.Receive(); err != nil {
|
if msgs, err := sender.Receive(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
t.Logf("%+v", msgs)
|
t.Logf("%+v", msgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testMatrix(t *testing.T) Matrix {
|
||||||
|
if len(os.Getenv("INTEGRATION")) == 0 {
|
||||||
|
t.Skip("$INTEGRATION not set")
|
||||||
|
}
|
||||||
|
d := t.TempDir()
|
||||||
|
f := path.Join(d, "config.test.json")
|
||||||
|
b, err := ioutil.ReadFile("../config.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(f, b, os.ModePerm); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
os.Setenv("CONFIG", f)
|
||||||
|
if err := config.Refresh(nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return NewMatrix()
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import "time"
|
|||||||
|
|
||||||
type Sender interface {
|
type Sender interface {
|
||||||
Send(string) error
|
Send(string) error
|
||||||
|
SendTracked(string) (string, error)
|
||||||
|
Update(string, string) (string, error)
|
||||||
Receive() ([]Message, error)
|
Receive() ([]Message, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
todo.yaml
13
todo.yaml
@@ -1,11 +1,11 @@
|
|||||||
todo:
|
todo:
|
||||||
- help() log on truckstop for stuff like perma 403
|
- !states emits current state
|
||||||
- TEST its falling apart
|
- TEST. Just like, refactor and test to shit.
|
||||||
- mark jobs no longer avail by modifying in matrix
|
- try search ntg by autoinc?
|
||||||
- write-as for clients so ma can write to pa by default
|
- test each !command callbacks to matrix
|
||||||
|
- recv-as for clients so pa receives mas commands as writes
|
||||||
- continuation is garbo, but I can still do better client side to avoid get-set high level
|
- continuation is garbo, but I can still do better client side to avoid get-set high level
|
||||||
- no hard code jpeg or have it in multiple places
|
- no hard code jpeg or have it in multiple places
|
||||||
- test each !command callbacks to matrix
|
|
||||||
- change matrix so I test my custom logic even if I dont fetch remote
|
- change matrix so I test my custom logic even if I dont fetch remote
|
||||||
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
||||||
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
|
||||||
@@ -15,6 +15,9 @@ todo:
|
|||||||
- banlist criteria like vendors, brokers, metadata
|
- banlist criteria like vendors, brokers, metadata
|
||||||
- set up copy for caleb, broc
|
- set up copy for caleb, broc
|
||||||
done:
|
done:
|
||||||
|
- mark jobs no longer avail by modifying in matrix;; save matrix ID over dummy payload
|
||||||
|
- TEST its falling apart
|
||||||
|
- help() log on truckstop for stuff like perma 403
|
||||||
- figure out zoom on maps;; is there like an auto-zoom I can leverage?
|
- figure out zoom on maps;; is there like an auto-zoom I can leverage?
|
||||||
- mock is nigh useless
|
- mock is nigh useless
|
||||||
- mark consumed;; save scroll id for matrix
|
- mark consumed;; save scroll id for matrix
|
||||||
|
|||||||
Reference in New Issue
Block a user