Compare commits

...

15 Commits

Author SHA1 Message Date
bel
6ea4d4700c whoops dont reuse not same uri 2022-01-18 06:40:55 -07:00
bel
451f741f5a wrap errs for easier read 2022-01-18 06:37:06 -07:00
bel
ecf22c3a3d todo 2022-01-17 22:04:57 -07:00
bel
ced1afff88 manual test new deleting stale crud 2022-01-17 22:00:23 -07:00
bel
ffa33ea299 when a job dies, delete images associated with it 2022-01-17 21:57:33 -07:00
bel
92b6019052 on job no longer in results, delete from matrix;; no backwards compatible 2022-01-17 21:29:56 -07:00
bel
6a2b2f38d0 on job send, record job+sentTS+matrixID in db 2022-01-17 20:10:10 -07:00
bel
d4c1e20230 SendTracked returns a string id for a send message, and Update can be used to change that message 2022-01-17 20:05:02 -07:00
bel
f2c9602d70 add uuid 2022-01-17 20:04:03 -07:00
bel
744365b9d3 verbose logs, mock ntg 2022-01-17 20:03:55 -07:00
bel
16bdc174d4 more debug, less stupid info log 2022-01-17 19:03:57 -07:00
bel
d3381749f7 gitignore 2022-01-17 19:00:32 -07:00
bel
55848d6c7d todo 2022-01-17 19:00:23 -07:00
bel
f9819350ad log sosf on panics from main 2022-01-17 18:55:11 -07:00
bel
7062094234 rm dev log 2022-01-17 18:54:27 -07:00
13 changed files with 256 additions and 94 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ cmd/cmd
cmd/cli cmd/cli
cmd/pttodo/pttodo cmd/pttodo/pttodo
/truckstop /truckstop
/exec-truckstop

View File

@@ -16,7 +16,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 {
@@ -29,12 +30,7 @@ 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 +49,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(

View File

@@ -93,7 +93,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID) key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID)
if b, err := db.Get(key); err != nil { if b, err := db.Get(key); err != nil {
} else if err := json.Unmarshal(b, &ntgJob.jobinfo); err == nil { } else if err := json.Unmarshal(b, &ntgJob.jobinfo); err == nil {
return ntgJob.jobinfo, nil return ntgJob.jobinfo, fmt.Errorf("failed to parse ntg job info from db: %w: %s", err, b)
} }
ntg := NewNTGVision() ntg := NewNTGVision()
ji, err := ntg.SearchJob(ntgJob.ID) ji, err := ntg.SearchJob(ntgJob.ID)
@@ -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
} }

View File

@@ -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",

View File

@@ -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"
} }

View File

@@ -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
View File

@@ -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

View File

@@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"strings" "strings"
"sync" "sync"
@@ -90,9 +89,10 @@ func logf(l Level, format string, args []interface{}) {
fmt.Fprintf(os.Stderr, format, args...) fmt.Fprintf(os.Stderr, format, args...)
} }
fmt.Fprintf(logger, format, args...) fmt.Fprintf(logger, format, args...)
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(fmt.Sprintf(format, args...)); err != nil {
Errorf("failed to SOS: %v", err)
}
} }
} }

91
main.go
View File

@@ -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,6 +282,10 @@ 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()
@@ -308,6 +319,52 @@ 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
}
if err := message.NewMatrix().Update(recorded.MatrixID, recorded.Job.FormatMultilineTextDead()); 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-- {
@@ -333,9 +390,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 +468,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
} }

View File

@@ -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) {

View File

@@ -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()
}

View File

@@ -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)
} }

View File

@@ -1,11 +1,10 @@
todo: todo:
- help() log on truckstop for stuff like perma 403 - TEST. Just like, refactor and test to shit.
- TEST its falling apart - try search ntg by autoinc?
- mark jobs no longer avail by modifying in matrix - test each !command callbacks to matrix
- write-as for clients so ma can write to pa by default - 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 +14,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