Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2c1ea369 | ||
|
|
55b6f48314 | ||
|
|
442e8c2992 | ||
|
|
cf421e414c | ||
|
|
c1cdc6dc0c | ||
|
|
003388c847 | ||
|
|
800f14a355 | ||
|
|
a6ae4b9617 | ||
|
|
edf95d292a | ||
|
|
aeda3c3324 | ||
|
|
8f5ebecee8 | ||
|
|
84217c75e8 | ||
|
|
b2d97e6cef | ||
|
|
9cd01d0d10 | ||
|
|
04a2cb01ef | ||
|
|
05a981344d | ||
|
|
ebe777e989 | ||
|
|
6704b23bf1 | ||
|
|
aa1a2373ab | ||
|
|
32d09dbac6 | ||
|
|
e2cd24a39f | ||
|
|
48da446e83 | ||
|
|
cc379c52ad | ||
|
|
2a93e52b0b | ||
|
|
2102259ba4 | ||
|
|
9552df9281 | ||
|
|
1cdb399dda | ||
|
|
6bc85d0ab7 | ||
|
|
874de44a47 | ||
|
|
a07a7d5a00 | ||
|
|
65e43f8d2a | ||
|
|
e8b76d07e2 | ||
|
|
63ef1f206b | ||
|
|
373e9ff3c3 | ||
|
|
d3fff1519b | ||
|
|
2b6acc51fb | ||
|
|
fade4467d6 | ||
|
|
c8800c010e | ||
|
|
266ccb5f98 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ todo-server-yaml
|
|||||||
cmd/cmd
|
cmd/cmd
|
||||||
cmd/cli
|
cmd/cli
|
||||||
cmd/pttodo/pttodo
|
cmd/pttodo/pttodo
|
||||||
|
/truckstop
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import (
|
|||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
ID string
|
ID string
|
||||||
|
URI string
|
||||||
Pickup JobLocation
|
Pickup JobLocation
|
||||||
Dropoff JobLocation
|
Dropoff JobLocation
|
||||||
Weight int
|
Weight int
|
||||||
Miles int
|
Miles int
|
||||||
Meta string
|
Meta string
|
||||||
|
secrets func() interface{} `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobLocation struct {
|
type JobLocation struct {
|
||||||
@@ -23,14 +25,27 @@ type JobLocation struct {
|
|||||||
State string
|
State string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Job) Secrets() {
|
||||||
|
if j.secrets == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := j.secrets()
|
||||||
|
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 {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
`%s => %s (%d miles), Weight:%d, Notes:%s`,
|
`%s => %s (%d miles), Weight:%d, Notes:%s Link:%s`,
|
||||||
j.Pickup.String(),
|
j.Pickup.String(),
|
||||||
j.Dropoff.String(),
|
j.Dropoff.String(),
|
||||||
j.Miles,
|
j.Miles,
|
||||||
j.Weight,
|
j.Weight,
|
||||||
j.Meta,
|
j.Meta,
|
||||||
|
j.URI,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,15 +56,10 @@ func (j JobLocation) String() string {
|
|||||||
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(
|
||||||
"--- %s: %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
|
"--- %s: %s => %s ---",
|
||||||
client,
|
client,
|
||||||
j.Pickup.State,
|
j.Pickup.State,
|
||||||
j.Dropoff.State,
|
j.Dropoff.State,
|
||||||
j.Pickup.String(),
|
|
||||||
j.Dropoff.String(),
|
|
||||||
j.Weight,
|
|
||||||
j.Miles,
|
|
||||||
j.Meta,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
out := ""
|
out := ""
|
||||||
@@ -58,10 +68,22 @@ func (j Job) FormatMultilineText() string {
|
|||||||
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
|
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
|
||||||
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
|
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
|
||||||
if len(out) > 0 {
|
if len(out) > 0 {
|
||||||
out += "\n\n"
|
out += "\n"
|
||||||
}
|
}
|
||||||
out += foo(k)
|
out += foo(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(out) > 0 {
|
||||||
|
out = fmt.Sprintf(
|
||||||
|
"%s\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s\n%s",
|
||||||
|
out,
|
||||||
|
j.Pickup.String(),
|
||||||
|
j.Dropoff.String(),
|
||||||
|
j.Weight,
|
||||||
|
j.Miles,
|
||||||
|
j.Meta,
|
||||||
|
j.URI,
|
||||||
|
)
|
||||||
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -32,13 +33,108 @@ type ntgVisionJob struct {
|
|||||||
Weight int `json:"weight"`
|
Weight int `json:"weight"`
|
||||||
Equipment string `json:"equip"`
|
Equipment string `json:"equip"`
|
||||||
Temp string `json:"temp"`
|
Temp string `json:"temp"`
|
||||||
|
jobinfo ntgVisionJobInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ntgJob ntgVisionJob) Job() Job {
|
type ntgVisionJobInfo struct {
|
||||||
|
StopsInfo []struct {
|
||||||
|
StopHours string `json:"stopHours"`
|
||||||
|
AppointmentTime string `json:"appointmentTime"`
|
||||||
|
Instructions string `json:"instructions"`
|
||||||
|
IsDropTrailer bool `json:"isDropTrailer"`
|
||||||
|
} `json:"stopinfos"`
|
||||||
|
PayUpTo float32 `json:"payUpTo"`
|
||||||
|
LoadState string `json:"loadStatus"`
|
||||||
|
//CanBidNow bool `json:"canBidNow"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ji ntgVisionJobInfo) IsZero() bool {
|
||||||
|
return len(ji.StopsInfo) == 0 && ji.PayUpTo == 0 && ji.LoadState == ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ji ntgVisionJobInfo) String() string {
|
||||||
|
if ji.IsZero() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
out := ""
|
||||||
|
if ji.PayUpTo != 0 {
|
||||||
|
out = fmt.Sprintf("\nPAYS:%v\n%s", ji.PayUpTo, out)
|
||||||
|
}
|
||||||
|
if ji.LoadState != "" {
|
||||||
|
out = fmt.Sprintf("%s Auction:%s", out, ji.LoadState)
|
||||||
|
}
|
||||||
|
if len(ji.StopsInfo) != 2 {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"%s Pickup:{Hours:%s Notes:%s, DropTrailer:%v} Dropoff:{Appointment:%s Notes:%s}",
|
||||||
|
out,
|
||||||
|
ji.StopsInfo[0].StopHours,
|
||||||
|
ji.StopsInfo[0].Instructions,
|
||||||
|
ji.StopsInfo[0].IsDropTrailer,
|
||||||
|
ji.StopsInfo[1].AppointmentTime,
|
||||||
|
ji.StopsInfo[1].Instructions,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
||||||
|
if !config.Get().Brokers.NTG.JobInfo {
|
||||||
|
return ntgJob.jobinfo, nil
|
||||||
|
}
|
||||||
|
if !ntgJob.jobinfo.IsZero() {
|
||||||
|
return ntgJob.jobinfo, nil
|
||||||
|
}
|
||||||
|
db := config.Get().DB()
|
||||||
|
key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID)
|
||||||
|
if b, err := db.Get(key); err != nil {
|
||||||
|
} else if err := json.Unmarshal(b, &ntgJob.jobinfo); err == nil {
|
||||||
|
return ntgJob.jobinfo, nil
|
||||||
|
}
|
||||||
|
ji, err := ntgJob.jobInfo()
|
||||||
|
if err == ErrNoAuth {
|
||||||
|
if err := NewNTGVision().refreshAuth(); err != nil {
|
||||||
|
return ntgVisionJobInfo{}, err
|
||||||
|
}
|
||||||
|
ji, err = ntgJob.jobInfo()
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
ntgJob.jobinfo = ji
|
||||||
|
b, err := json.Marshal(ntgJob.jobinfo)
|
||||||
|
if err == nil {
|
||||||
|
db.Set(key, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ji, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ntgJob *ntgVisionJob) jobInfo() (ntgVisionJobInfo, error) {
|
||||||
|
time.Sleep(config.Get().Interval.JobInfo.Get())
|
||||||
|
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf(`https://ntgvision.com/api/v1/load/LoadDetails?loadId=%v`, ntgJob.ID), nil)
|
||||||
|
if err != nil {
|
||||||
|
return ntgVisionJobInfo{}, err
|
||||||
|
}
|
||||||
|
setNTGHeaders(request)
|
||||||
|
resp, err := do(request)
|
||||||
|
if err != nil {
|
||||||
|
return ntgVisionJobInfo{}, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
log.Printf("fetch ntg job info %+v: %d: %s", request, resp.StatusCode, b)
|
||||||
|
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
||||||
|
return ntgVisionJobInfo{}, ErrNoAuth
|
||||||
|
}
|
||||||
|
var result ntgVisionJobInfo
|
||||||
|
err = json.Unmarshal(b, &result)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ntgJob *ntgVisionJob) Job() Job {
|
||||||
pickup, _ := time.ParseInLocation("01/02/06", ntgJob.PickupDate, time.Local)
|
pickup, _ := time.ParseInLocation("01/02/06", ntgJob.PickupDate, time.Local)
|
||||||
dropoff, _ := time.ParseInLocation("01/02/06", ntgJob.DropoffDate, time.Local)
|
dropoff, _ := time.ParseInLocation("01/02/06", ntgJob.DropoffDate, time.Local)
|
||||||
return Job{
|
return Job{
|
||||||
ID: fmt.Sprintf("ntg-%d", ntgJob.ID),
|
ID: fmt.Sprintf("ntg-%d", ntgJob.ID),
|
||||||
|
URI: fmt.Sprintf(config.Get().Brokers.NTG.LoadPageURIFormat, ntgJob.ID),
|
||||||
Pickup: JobLocation{
|
Pickup: JobLocation{
|
||||||
Date: pickup,
|
Date: pickup,
|
||||||
City: ntgJob.PickupCity,
|
City: ntgJob.PickupCity,
|
||||||
@@ -52,6 +148,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{} {
|
||||||
|
jobInfo, err := ntgJob.JobInfo()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to get jobinfo: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return jobInfo.String()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,8 +177,15 @@ func (ntg NTGVision) Search(states []config.State) ([]Job, error) {
|
|||||||
}
|
}
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(rc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("ntg search for %+v: %s", states, b)
|
||||||
|
|
||||||
var ntgjobs []ntgVisionJob
|
var ntgjobs []ntgVisionJob
|
||||||
err = json.NewDecoder(rc).Decode(&ntgjobs)
|
err = json.Unmarshal(b, &ntgjobs)
|
||||||
|
|
||||||
jobs := make([]Job, len(ntgjobs))
|
jobs := make([]Job, len(ntgjobs))
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
@@ -83,8 +194,23 @@ func (ntg NTGVision) Search(states []config.State) ([]Job, error) {
|
|||||||
return jobs, err
|
return jobs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getNTGTokenKey() string {
|
||||||
|
return "brokers_ntg_token"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNTGToken() string {
|
||||||
|
db := config.Get().DB()
|
||||||
|
b, _ := db.Get(getNTGTokenKey())
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setNTGToken(token string) {
|
||||||
|
db := config.Get().DB()
|
||||||
|
db.Set(getNTGTokenKey(), []byte(token))
|
||||||
|
}
|
||||||
|
|
||||||
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
||||||
if config.Get().Brokers.NTG.Token == "" {
|
if getNTGToken() == "" {
|
||||||
if err := ntg.refreshAuth(); err != nil {
|
if err := ntg.refreshAuth(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -100,6 +226,7 @@ func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ntg NTGVision) refreshAuth() error {
|
func (ntg NTGVision) refreshAuth() error {
|
||||||
|
log.Printf("refreshing ntg auth...")
|
||||||
b, _ := json.Marshal(map[string]string{
|
b, _ := json.Marshal(map[string]string{
|
||||||
"username": config.Get().Brokers.NTG.Username,
|
"username": config.Get().Brokers.NTG.Username,
|
||||||
"password": config.Get().Brokers.NTG.Password,
|
"password": config.Get().Brokers.NTG.Password,
|
||||||
@@ -127,9 +254,7 @@ func (ntg NTGVision) refreshAuth() error {
|
|||||||
if len(v.Token) == 0 {
|
if len(v.Token) == 0 {
|
||||||
return errors.New("failed to get token from login call")
|
return errors.New("failed to get token from login call")
|
||||||
}
|
}
|
||||||
conf := config.Get()
|
setNTGToken(v.Token)
|
||||||
conf.Brokers.NTG.Token = v.Token
|
|
||||||
config.Set(*conf)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +303,7 @@ func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
setNTGHeaders(request)
|
setNTGHeaders(request)
|
||||||
request.Header.Set("Authorization", "Bearer "+config.Get().Brokers.NTG.Token)
|
request.Header.Set("Authorization", "Bearer "+getNTGToken())
|
||||||
|
|
||||||
return request, nil
|
return request, nil
|
||||||
}
|
}
|
||||||
@@ -189,7 +314,7 @@ func setNTGHeaders(request *http.Request) {
|
|||||||
request.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
request.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
||||||
request.Header.Set("Accept-Encoding", "gzip, deflate, br")
|
request.Header.Set("Accept-Encoding", "gzip, deflate, br")
|
||||||
request.Header.Set("Content-Type", "application/json;charset=utf-8")
|
request.Header.Set("Content-Type", "application/json;charset=utf-8")
|
||||||
//request.Header.Set("Authorization", "Bearer "+config.Get().Brokers.NTG.Token)
|
//request.Header.Set("Authorization", "Bearer "+getNTGToken())
|
||||||
request.Header.Set("Origin", "https://ntgvision.com")
|
request.Header.Set("Origin", "https://ntgvision.com")
|
||||||
request.Header.Set("DNT", "1")
|
request.Header.Set("DNT", "1")
|
||||||
request.Header.Set("Connection", "keep-alive")
|
request.Header.Set("Connection", "keep-alive")
|
||||||
|
|||||||
44
config.json
44
config.json
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"Interval": {
|
"Interval": {
|
||||||
"Input": "15s..20s",
|
"Input": "5s..10s",
|
||||||
"OK": "6h0m0s..6h0m0s",
|
"OK": "6h0m0s..6h0m0s",
|
||||||
"Error": "6h0m0s..6h0m0s"
|
"Error": "6h0m0s..6h0m0s",
|
||||||
|
"JobInfo": "10s..20s"
|
||||||
},
|
},
|
||||||
"Images": {
|
"Images": {
|
||||||
"ClientID": "d9ac7cabe813d10",
|
"ClientID": "d9ac7cabe813d10",
|
||||||
@@ -12,23 +13,26 @@
|
|||||||
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
||||||
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
||||||
"RefreshMethod": "POST",
|
"RefreshMethod": "POST",
|
||||||
"UploadURI": "https://api.imgur.com/3/image",
|
"UploadURI": "https://api.imgur.com/3/image?name=something.jpeg",
|
||||||
"UploadMethod": "POST"
|
"UploadMethod": "POST"
|
||||||
},
|
},
|
||||||
"Maps": {
|
"Maps": {
|
||||||
|
"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\u0026zoom=5",
|
||||||
"URIFormat": "https://maps.googleapis.com/maps/api/staticmap?center=%s\u0026markers=label=A|%s\u0026zoom=5\u0026size=250x250\u0026scale=1\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
"URIFormat": "https://maps.googleapis.com/maps/api/staticmap?center=%s\u0026markers=label=A|%s\u0026zoom=5\u0026size=250x250\u0026scale=1\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||||
"Pickup": true,
|
"Pathed": false,
|
||||||
|
"Pickup": false,
|
||||||
"Dropoff": false
|
"Dropoff": false
|
||||||
},
|
},
|
||||||
"Clients": {
|
"Clients": {
|
||||||
"bel": {
|
"bel": {
|
||||||
"States": [
|
"States": [
|
||||||
"NC"
|
"IL"
|
||||||
],
|
],
|
||||||
"IDs": {
|
"IDs": {
|
||||||
"Matrix": "@bel:synapse.home.blapointe.com"
|
"Matrix": "@bel:m.bltrucks.top"
|
||||||
},
|
},
|
||||||
"Available": 1612328400
|
"Available": 1512328400
|
||||||
},
|
},
|
||||||
"broc": {
|
"broc": {
|
||||||
"States": [
|
"States": [
|
||||||
@@ -36,25 +40,16 @@
|
|||||||
"NC"
|
"NC"
|
||||||
],
|
],
|
||||||
"IDs": {
|
"IDs": {
|
||||||
"Matrix": "@belandbroc:matrix.org"
|
"Matrix": "@broc:m.bltrucks.top"
|
||||||
},
|
},
|
||||||
"Available": 5642452800
|
"Available": 5642452800
|
||||||
},
|
},
|
||||||
"caleb": {
|
|
||||||
"States": [
|
|
||||||
"FL"
|
|
||||||
],
|
|
||||||
"IDs": {
|
|
||||||
"Matrix": "@belandbroc:matrix.org"
|
|
||||||
},
|
|
||||||
"Available": -62135596800
|
|
||||||
},
|
|
||||||
"pa": {
|
"pa": {
|
||||||
"States": [
|
"States": [
|
||||||
"NC"
|
"NC"
|
||||||
],
|
],
|
||||||
"IDs": {
|
"IDs": {
|
||||||
"Matrix": "@belandbroc:matrix.org"
|
"Matrix": "@ron:m.bltrucks.top"
|
||||||
},
|
},
|
||||||
"Available": -62135596800
|
"Available": -62135596800
|
||||||
}
|
}
|
||||||
@@ -67,18 +62,19 @@
|
|||||||
"Matrix": {
|
"Matrix": {
|
||||||
"ReceiveEnabled": true,
|
"ReceiveEnabled": true,
|
||||||
"Mock": false,
|
"Mock": false,
|
||||||
"Homeserver": "https://synapse.home.blapointe.com",
|
"Homeserver": "https://m.bltrucks.top",
|
||||||
"Username": "@bel:synapse.home.blapointe.com",
|
"Username": "@bot.m.bltrucks.top",
|
||||||
"Token": "MDAyOGxvY2F0aW9uIHN5bmFwc2UuaG9tZS5ibGFwb2ludGUuY29tCjAwMTNpZGVudGlmaWVyIGtleQowMDEwY2lkIGdlbiA9IDEKMDAzMmNpZCB1c2VyX2lkID0gQGJlbDpzeW5hcHNlLmhvbWUuYmxhcG9pbnRlLmNvbQowMDE2Y2lkIHR5cGUgPSBhY2Nlc3MKMDAyMWNpZCBub25jZSA9IFpXTTtCaTNBODdtSTpsZkAKMDAyZnNpZ25hdHVyZSBX37kStY2wt_ftMfEYPfk1ADMJ6ZVfZsro9ic3weZ25Ao",
|
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",
|
||||||
"Device": "TGNIOGKATZ",
|
"Device": "TGNIOGKATZ",
|
||||||
"Room": "!WbawbZxHqnxxfhvcSj:synapse.home.blapointe.com"
|
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Once": false,
|
"Once": true,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"NTG": {
|
"NTG": {
|
||||||
|
"JobInfo": true,
|
||||||
"Mock": true,
|
"Mock": true,
|
||||||
"Token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzMTAyOSIsInVuaXF1ZV9uYW1lIjoibm9lYXN5cnVuc3RydWNraW5nQGdtYWlsLmNvbSIsImp0aSI6IjFmYzhmNjk1LTQzNTYtNGYzZS05NWY1LWZkNWVjMDJlMDkxNyIsImlhdCI6IjEvMTAvMjAyMiAxMTo1OTozNiBQTSIsIm50Z3ZSb2xlIjoiQ2FycmllckFwcHJvdmVkIiwidXNlckNhcnJpZXJzIjoiMTUzNDIzIiwib3RyVXNlciI6IkZhbHNlIiwibmJmIjoxNjQxODU5MTc2LCJleHAiOjE2NDE5NDE5NzYsImlzcyI6Ik5URyBTZWN1cml0eSBUb2tlbiBTZXJ2aWNlIiwiYXVkIjoiTlRHIn0.kpHOBTtcQhbdloAw7xEjnkzfxf4ToMgidrLCMomZmnmKQHlD_7OQuI8nQiCTHc_ntuGtt8Ui92kwWWUiLwN_2tT2vC7Jy6m9IjwqgbAzsgTLi4jAbIwITD-awiDh4FUKDwGq3XpEjs-i7XM3rI7tTk7jg9QSDId8EF3Pt5fJq6QhztC6y7-JaSFQZLMtkSCAWmOQx_TgKgVoVbgMeiqhHbZ2hhoA7TtpEIIL5Gnfq46t3E18ExdrsO96ZCGQGcBw5x8J1ustq2cwdlFKeg4ULNWAAd1ay1hojRa7jCHs98AcoJ3Nts9-o7yEMuN2rrfpK_nm68nciwFtF-ke1KoiBg",
|
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
||||||
"Username": "noeasyrunstrucking@gmail.com",
|
"Username": "noeasyrunstrucking@gmail.com",
|
||||||
"Password": "thumper123"
|
"Password": "thumper123"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Interval struct {
|
Interval struct {
|
||||||
Input Duration
|
Input Duration
|
||||||
OK Duration
|
OK Duration
|
||||||
Error Duration
|
Error Duration
|
||||||
|
JobInfo Duration
|
||||||
}
|
}
|
||||||
Images struct {
|
Images struct {
|
||||||
ClientID string
|
ClientID string
|
||||||
@@ -27,9 +28,12 @@ type Config struct {
|
|||||||
UploadMethod string
|
UploadMethod string
|
||||||
}
|
}
|
||||||
Maps struct {
|
Maps struct {
|
||||||
URIFormat string
|
DirectionsURIFormat string
|
||||||
Pickup bool
|
PathedURIFormat string
|
||||||
Dropoff bool
|
URIFormat string
|
||||||
|
Pathed bool
|
||||||
|
Pickup bool
|
||||||
|
Dropoff bool
|
||||||
}
|
}
|
||||||
Clients map[string]Client
|
Clients map[string]Client
|
||||||
Storage []string
|
Storage []string
|
||||||
@@ -47,10 +51,11 @@ type Config struct {
|
|||||||
Once bool
|
Once bool
|
||||||
Brokers struct {
|
Brokers struct {
|
||||||
NTG struct {
|
NTG struct {
|
||||||
Mock bool
|
JobInfo bool
|
||||||
Token string
|
Mock bool
|
||||||
Username string
|
LoadPageURIFormat string
|
||||||
Password string
|
Username string
|
||||||
|
Password string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
118
main.go
118
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
"local/truckstop/message"
|
"local/truckstop/message"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -23,8 +24,10 @@ func main() {
|
|||||||
if err := config.Refresh(); err != nil {
|
if err := config.Refresh(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := matrixrecv(); err != nil {
|
if config.Get().Message.Matrix.ReceiveEnabled {
|
||||||
panic(err)
|
if err := matrixrecv(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lock := &sync.Mutex{}
|
lock := &sync.Mutex{}
|
||||||
go func() {
|
go func() {
|
||||||
@@ -69,7 +72,7 @@ func matrixrecv() error {
|
|||||||
if !printed {
|
if !printed {
|
||||||
if _, err := db.Get(key); err == storage.ErrNotFound {
|
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||||
log.Printf("sending help")
|
log.Printf("sending help")
|
||||||
help := fmt.Sprintf("commands:\n...`!help`...print this help\n...`!state nc NC nC Nc`...set states for self\n...`!available 2022-12-31`...set date self is available for work\n\nrun a command for someone else: `!state ga @caleb`")
|
help := fmt.Sprintf("commands:\n...`!help` print this help\n...`!state nc NC nC Nc` set states for self\n...`!available 2022-12-31` set date self is available for work\n\nrun a command for someone else: `!state ga @caleb`")
|
||||||
if err := sender.Send(help); err != nil {
|
if err := sender.Send(help); err != nil {
|
||||||
log.Printf("failed to send help: %v", err)
|
log.Printf("failed to send help: %v", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -88,42 +91,57 @@ func matrixrecv() error {
|
|||||||
}()
|
}()
|
||||||
func() {
|
func() {
|
||||||
log.Printf("looking for states")
|
log.Printf("looking for states")
|
||||||
|
db := config.Get().DB()
|
||||||
states := map[string]map[config.State]struct{}{}
|
states := map[string]map[config.State]struct{}{}
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
|
key := fmt.Sprintf("states_%d", msg.Timestamp.Unix())
|
||||||
if !strings.HasPrefix(msg.Content, "!state") {
|
if !strings.HasPrefix(msg.Content, "!state") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := states[msg.Sender]; ok {
|
if _, ok := states[msg.Sender]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
states[msg.Sender] = map[config.State]struct{}{}
|
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||||
for _, state := range parseOutStates([]byte(msg.Content)) {
|
states[msg.Sender] = map[config.State]struct{}{}
|
||||||
states[msg.Sender][state] = struct{}{}
|
for _, state := range parseOutStates([]byte(msg.Content)) {
|
||||||
|
states[msg.Sender][state] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||||
|
log.Printf("failed to mark state gathered @%s: %v", key, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNewStates(states)
|
setNewStates(states)
|
||||||
}()
|
}()
|
||||||
func() {
|
func() {
|
||||||
log.Printf("looking for pauses")
|
log.Printf("looking for pauses")
|
||||||
|
db := config.Get().DB()
|
||||||
pauses := map[string]time.Time{}
|
pauses := map[string]time.Time{}
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
|
key := fmt.Sprintf("pauses_%d", msg.Timestamp.Unix())
|
||||||
if !strings.HasPrefix(msg.Content, "!available ") {
|
if !strings.HasPrefix(msg.Content, "!available ") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := pauses[msg.Sender]; ok {
|
if _, ok := pauses[msg.Sender]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t, err := time.ParseInLocation(
|
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||||
"2006-01-02",
|
t, err := time.ParseInLocation(
|
||||||
strings.TrimSpace(strings.TrimPrefix(msg.Content, "!available ")),
|
"2006-01-02",
|
||||||
time.Local,
|
strings.TrimSpace(strings.TrimPrefix(msg.Content, "!available ")),
|
||||||
)
|
time.Local,
|
||||||
if err == nil {
|
)
|
||||||
pauses[msg.Sender] = t
|
if err == nil {
|
||||||
|
pauses[msg.Sender] = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||||
|
log.Printf("failed to mark state gathered @%s: %v", key, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNewPauses(pauses)
|
setNewPauses(pauses)
|
||||||
}()
|
}()
|
||||||
|
message.SetMatrixContinuation(sender.Continuation())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,21 +263,29 @@ func once() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: all jobs: %+v", alljobs)
|
||||||
newjobs, err := dropStaleJobs(alljobs)
|
newjobs, err := dropStaleJobs(alljobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: new jobs: %+v", newjobs)
|
||||||
jobs, err := dropBanlistJobs(newjobs)
|
jobs, err := dropBanlistJobs(newjobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: loading job secrets: %+v", jobs)
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
if err := sendJob(jobs[i]); err != nil {
|
jobs[i].Secrets()
|
||||||
return err
|
}
|
||||||
}
|
log.Printf("once: sending jobs: %+v", jobs)
|
||||||
log.Println("sent job", jobs[i])
|
for i := range jobs {
|
||||||
if err := config.Get().DB().Set(jobs[i].ID, []byte(`sent`)); err != nil {
|
if ok, err := sendJob(jobs[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if ok {
|
||||||
|
log.Println("sent job", jobs[i])
|
||||||
|
if err := config.Get().DB().Set(jobs[i].ID, []byte(`sent`)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -301,33 +327,73 @@ func dropBanlistJobs(jobs []broker.Job) ([]broker.Job, error) {
|
|||||||
return jobs, nil
|
return jobs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendJob(job broker.Job) error {
|
func sendJob(job broker.Job) (bool, error) {
|
||||||
sender := message.NewMatrix()
|
sender := message.NewMatrix()
|
||||||
payload := job.FormatMultilineText()
|
payload := job.FormatMultilineText()
|
||||||
|
log.Printf("once: send job %s if nonzero: %s", job.String(), payload)
|
||||||
if len(payload) == 0 {
|
if len(payload) == 0 {
|
||||||
return nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if err := sender.Send(payload); err != nil {
|
if err := sender.Send(payload); err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
maps := config.Get().Maps
|
maps := config.Get().Maps
|
||||||
|
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)
|
||||||
|
if maps.Pathed {
|
||||||
|
directionsURI := fmt.Sprintf(maps.DirectionsURIFormat, pickup, dropoff)
|
||||||
|
resp, err := http.Get(directionsURI)
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return true, fmt.Errorf("bad status getting path: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
var directionsResp struct {
|
||||||
|
Routes []struct {
|
||||||
|
Legs []struct {
|
||||||
|
Steps []struct {
|
||||||
|
StartLocation struct {
|
||||||
|
Lat float32 `json:"lat"`
|
||||||
|
Lng float32 `json:"lng"`
|
||||||
|
} `json:"start_location"`
|
||||||
|
} `json:"steps"`
|
||||||
|
} `json:"legs"`
|
||||||
|
} `json:"routes"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&directionsResp); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
if len(directionsResp.Routes) < 1 || len(directionsResp.Routes[0].Legs) < 1 || len(directionsResp.Routes[0].Legs[0].Steps) < 1 {
|
||||||
|
} else {
|
||||||
|
latLngPath := make([]string, 0)
|
||||||
|
for _, v := range directionsResp.Routes[0].Legs[0].Steps {
|
||||||
|
latLngPath = append(latLngPath, fmt.Sprintf("%.9f,%.9f", v.StartLocation.Lat, v.StartLocation.Lng))
|
||||||
|
}
|
||||||
|
pathQuery := strings.Join(latLngPath, "|")
|
||||||
|
uri := fmt.Sprintf(maps.PathedURIFormat, pathQuery, pickup, dropoff)
|
||||||
|
log.Printf("sending pathed image: %s", uri)
|
||||||
|
if err := sender.SendImage(uri); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if maps.Pickup {
|
if maps.Pickup {
|
||||||
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
|
||||||
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
|
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
|
||||||
log.Printf("sending pickup image: %s", uri)
|
log.Printf("sending pickup image: %s", uri)
|
||||||
if err := sender.SendImage(uri); err != nil {
|
if err := sender.SendImage(uri); err != nil {
|
||||||
return err
|
return true, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if maps.Dropoff {
|
if maps.Dropoff {
|
||||||
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
|
||||||
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
|
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
|
||||||
log.Printf("sending dropoff image: %s", uri)
|
log.Printf("sending dropoff image: %s", uri)
|
||||||
if err := sender.SendImage(uri); err != nil {
|
if err := sender.SendImage(uri); err != nil {
|
||||||
return err
|
return true, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNewStates(client string, states []config.State) error {
|
func sendNewStates(client string, states []config.State) error {
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,9 +32,17 @@ func refreshToken() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uploadImage(b []byte) (string, error) {
|
func uploadImage(b []byte) (string, error) {
|
||||||
|
images := config.Get().Images
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
writer := multipart.NewWriter(buff)
|
writer := multipart.NewWriter(buff)
|
||||||
part, err := writer.CreateFormFile("image", "name")
|
name := "name"
|
||||||
|
if u, err := url.Parse(images.UploadURI); err != nil {
|
||||||
|
} else if s, ok := u.Query()["name"]; !ok {
|
||||||
|
} else {
|
||||||
|
name = s[0]
|
||||||
|
log.Printf("found name in upload uri: %s", name)
|
||||||
|
}
|
||||||
|
part, err := writer.CreateFormFile("image", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -43,7 +53,6 @@ func uploadImage(b []byte) (string, error) {
|
|||||||
}
|
}
|
||||||
writer.Close()
|
writer.Close()
|
||||||
|
|
||||||
images := config.Get().Images
|
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
images.UploadMethod,
|
images.UploadMethod,
|
||||||
images.UploadURI,
|
images.UploadURI,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
@@ -14,21 +15,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Matrix struct {
|
type Matrix struct {
|
||||||
mock bool
|
mock bool
|
||||||
homeserver string
|
homeserver string
|
||||||
username string
|
username string
|
||||||
token string
|
token string
|
||||||
room string
|
room string
|
||||||
|
continuation string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMatrix() Matrix {
|
func NewMatrix() Matrix {
|
||||||
conf := config.Get().Message.Matrix
|
conf := config.Get().Message.Matrix
|
||||||
return Matrix{
|
return Matrix{
|
||||||
homeserver: conf.Homeserver,
|
homeserver: conf.Homeserver,
|
||||||
username: conf.Username,
|
username: conf.Username,
|
||||||
token: conf.Token,
|
token: conf.Token,
|
||||||
room: conf.Room,
|
room: conf.Room,
|
||||||
mock: conf.Mock,
|
mock: conf.Mock,
|
||||||
|
continuation: GetMatrixContinuation(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +39,11 @@ func (m Matrix) getclient() (*gomatrix.Client, error) {
|
|||||||
return gomatrix.NewClient(m.homeserver, m.username, m.token)
|
return gomatrix.NewClient(m.homeserver, m.username, m.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Matrix) Receive() ([]Message, error) {
|
func (m Matrix) Continuation() string {
|
||||||
|
return m.continuation
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Matrix) Receive() ([]Message, error) {
|
||||||
if m.mock {
|
if m.mock {
|
||||||
log.Printf("matrix.Receive()")
|
log.Printf("matrix.Receive()")
|
||||||
messages := make([]Message, 0)
|
messages := make([]Message, 0)
|
||||||
@@ -64,11 +71,14 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
messages := make([]Message, 0)
|
messages := make([]Message, 0)
|
||||||
result, err := c.Messages(m.room, "", "", 'b', 50)
|
result, err := c.Messages(m.room, "999999999999999999", m.Continuation(), 'b', 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
log.Printf("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk))
|
||||||
|
m.continuation = result.End
|
||||||
for _, event := range result.Chunk {
|
for _, event := range result.Chunk {
|
||||||
|
//log.Printf("%+v", event)
|
||||||
if _, ok := matrixIDs[event.Sender]; !ok {
|
if _, ok := matrixIDs[event.Sender]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -81,6 +91,7 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
clientChange := regexp.MustCompile("@[a-z]+$")
|
clientChange := regexp.MustCompile("@[a-z]+$")
|
||||||
|
log.Printf("rewriting messages based on @abc")
|
||||||
for i := range messages {
|
for i := range messages {
|
||||||
if found := clientChange.FindString(messages[i].Content); found != "" {
|
if found := clientChange.FindString(messages[i].Content); found != "" {
|
||||||
messages[i].Content = strings.TrimSpace(strings.ReplaceAll(messages[i].Content, found, ""))
|
messages[i].Content = strings.TrimSpace(strings.ReplaceAll(messages[i].Content, found, ""))
|
||||||
@@ -94,6 +105,14 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||||||
}
|
}
|
||||||
messages[i].Content = strings.TrimSpace(messages[i].Content)
|
messages[i].Content = strings.TrimSpace(messages[i].Content)
|
||||||
}
|
}
|
||||||
|
log.Printf("rewriting messages based on ! CoMmAnD ...")
|
||||||
|
for i := range messages {
|
||||||
|
if strings.HasPrefix(messages[i].Content, "!") {
|
||||||
|
messages[i].Content = "!" + strings.TrimSpace(messages[i].Content[1:])
|
||||||
|
splits := strings.Split(messages[i].Content, " ")
|
||||||
|
messages[i].Content = strings.ToLower(splits[0]) + " " + strings.Join(splits, " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
return messages, nil
|
return messages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,15 +148,34 @@ func (m Matrix) SendImage(uri string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
publicURI, err := UploadImage(b)
|
|
||||||
if err != nil {
|
|
||||||
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)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
publicURI := mediaUpload.ContentURI
|
||||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||||
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetMatrixContinuation(continuation string) {
|
||||||
|
db := config.Get().DB()
|
||||||
|
db.Set(getMatrixContinuationKey(), []byte(continuation))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMatrixContinuation() string {
|
||||||
|
db := config.Get().DB()
|
||||||
|
b, _ := db.Get(getMatrixContinuationKey())
|
||||||
|
if b == nil {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMatrixContinuationKey() string {
|
||||||
|
return "matrix_continuation"
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func TestMatrixSend(t *testing.T) {
|
|||||||
if err := json.Unmarshal(b, &c); err != nil {
|
if err := json.Unmarshal(b, &c); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var sender Sender = Matrix{
|
var sender Sender = &Matrix{
|
||||||
homeserver: c.Message.Matrix.Homeserver,
|
homeserver: c.Message.Matrix.Homeserver,
|
||||||
username: c.Message.Matrix.Username,
|
username: c.Message.Matrix.Username,
|
||||||
token: c.Message.Matrix.Token,
|
token: c.Message.Matrix.Token,
|
||||||
@@ -43,7 +43,7 @@ func TestMatrixReceive(t *testing.T) {
|
|||||||
if err := json.Unmarshal(b, &c); err != nil {
|
if err := json.Unmarshal(b, &c); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var sender Sender = Matrix{
|
var sender Sender = &Matrix{
|
||||||
homeserver: c.Message.Matrix.Homeserver,
|
homeserver: c.Message.Matrix.Homeserver,
|
||||||
username: c.Message.Matrix.Username,
|
username: c.Message.Matrix.Username,
|
||||||
token: c.Message.Matrix.Token,
|
token: c.Message.Matrix.Token,
|
||||||
|
|||||||
3
testdata/routed_map.sh
vendored
Normal file
3
testdata/routed_map.sh
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
poly="${poly:-"$(curl 'https://maps.googleapis.com/maps/api/directions/json?origin=advance,nc&destination=winston-salem,nc&mode=driving&key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg' | jq -c .routes[0].legs[0].steps[] | jq -c .start_location | jq -r '(.lat|tostring) + "," + (.lng|tostring)' | tr '\n' '|' | sed 's/.$//')"}"; curl "https://maps.googleapis.com/maps/api/staticmap?size=250x250&path=$(urlencode "$poly")&format=jpeg&maptype=roadmap&key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg&size=600x400&sensor=false" > /tmp/f.jpg ; open /tmp/f.jpg
|
||||||
19
todo.yaml
19
todo.yaml
@@ -1,4 +1,9 @@
|
|||||||
todo:
|
todo:
|
||||||
|
- mark jobs no longer avail by modifying
|
||||||
|
- write-as for clients so ma can write to pa by default
|
||||||
|
- 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
|
||||||
|
- TEST its falling apart
|
||||||
- test each !command callbacks to matrix
|
- 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
|
||||||
@@ -9,6 +14,20 @@ 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 consumed;; save scroll id for matrix
|
||||||
|
- todo: switch house to selfhosted for rate limit
|
||||||
|
tags: now
|
||||||
|
- todo: details from ntg; stophours for pickup, appointmenttime/facitlyhours for dest
|
||||||
|
details: |
|
||||||
|
curl 'https://ntgvision.com/api/v1/load/LoadDetails?loadId=5088453' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzgyMSIsInVuaXF1ZV9uYW1lIjoiYmlyZGNvbXBhbnlsb2dpc3RpY3NAZ21haWwuY29tIiwianRpIjoiYTFiMjkxM2YtN2RjZS00ZDQ0LWEzMDYtMTRjMTBlYjQ2MmE1IiwiaWF0IjoiMS8xMy8yMDIyIDI6MTE6NTUgUE0iLCJudGd2Um9sZSI6IkNhcnJpZXJBcHByb3ZlZCIsImxvY2tVc2VyIjoiRmFsc2UiLCJvdmVycmlkZUJsYWNrbGlzdCI6IkZhbHNlIiwic2hvd1JhdGVzIjoiRmFsc2UiLCJ1c2VyQ2FycmllcnMiOiIxMTQxOTMiLCJvdHJVc2VyIjoiRmFsc2UiLCJuYmYiOjE2NDIwODMxMTUsImV4cCI6MTY0MjE2NTkxNSwiaXNzIjoiTlRHIFNlY3VyaXR5IFRva2VuIFNlcnZpY2UiLCJhdWQiOiJOVEcifQ.eDE2Jfok79b7oD1deP_00h9g8zZ3AnY60McnJ1hfS-8YJ12L3Bl-CJeN0eBos0aj2FXHv5MrqOJ6MFCaatqjIddPJl2MvtSByGUCLBzih67O20mkCowCmZfGjSnKvUu7DHFxjzo_y4_a3cjjGPYNc2LSCVJxV9NYzSXIuXG3WvXeE3dv8ml23bJFFhMWZzhSAfWBOW4kR61sibS6BpRD8dpkKoqUfXInq_7o8jz9_PsEhPBdJydqbXwg8ifQHkaPNAojsIr2rnJ3Tf_iQpom-6oAEUAOd2D3fK1XuWtRrysnD8s41YDthmqKpni2WOk72L-sKzRxD4KX2t_gyEb3Fw' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Cookie: cookiesession1=678A3E1398901234BCDEFGHIJKLMA492; _uiq_id.711119701.3d83=516d3e744ebe2d9a.1641792415.0.1642083653..; NTGAuthToken=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzgyMSIsInVuaXF1ZV9uYW1lIjoiYmlyZGNvbXBhbnlsb2dpc3RpY3NAZ21haWwuY29tIiwianRpIjoiYTFiMjkxM2YtN2RjZS00ZDQ0LWEzMDYtMTRjMTBlYjQ2MmE1IiwiaWF0IjoiMS8xMy8yMDIyIDI6MTE6NTUgUE0iLCJudGd2Um9sZSI6IkNhcnJpZXJBcHByb3ZlZCIsImxvY2tVc2VyIjoiRmFsc2UiLCJvdmVycmlkZUJsYWNrbGlzdCI6IkZhbHNlIiwic2hvd1JhdGVzIjoiRmFsc2UiLCJ1c2VyQ2FycmllcnMiOiIxMTQxOTMiLCJvdHJVc2VyIjoiRmFsc2UiLCJuYmYiOjE2NDIwODMxMTUsImV4cCI6MTY0MjE2NTkxNSwiaXNzIjoiTlRHIFNlY3VyaXR5IFRva2VuIFNlcnZpY2UiLCJhdWQiOiJOVEcifQ.eDE2Jfok79b7oD1deP_00h9g8zZ3AnY60McnJ1hfS-8YJ12L3Bl-CJeN0eBos0aj2FXHv5MrqOJ6MFCaatqjIddPJl2MvtSByGUCLBzih67O20mkCowCmZfGjSnKvUu7DHFxjzo_y4_a3cjjGPYNc2LSCVJxV9NYzSXIuXG3WvXeE3dv8ml23bJFFhMWZzhSAfWBOW4kR61sibS6BpRD8dpkKoqUfXInq_7o8jz9_PsEhPBdJydqbXwg8ifQHkaPNAojsIr2rnJ3Tf_iQpom-6oAEUAOd2D3fK1XuWtRrysnD8s41YDthmqKpni2WOk72L-sKzRxD4KX2t_gyEb3Fw' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'
|
||||||
|
{"headerSummary":"Washington, NC to Abilene, TX","loadId":5088453,"miles":1481,"weight":6000,"temp":null,"equipment":"Str Truck W/ Lift Gate","categoryName":"Lighting / Lighting Fixtures","categoryLabel":"Product Category","cargoInformation":["Store Fixtures - 6000 lbs"],"loadRequirements":["Straight Truck with lift gate required"],"stopInfos":[{"loadInfoIds":[5431607],"stopDateTime":"0001-01-01T00:00:00","isPickup":true,"location":"Washington, NC","stopDate":"Friday, 01/14/22","stopHours":"10:00 - 12:00","appointmentTime":"","appointmentType":"FCFS","instructions":"***LIFTGATE, PALLET JACK, DRIVER ASSIST***--MUST DELIVER ONLY ON APPT TIME-- CANNOT DELIVER EARLY OR LATE \r\n","isDropTrailer":false,"shipperName":"IDX NORTH CAROLINA","processedStopDate":""},{"loadInfoIds":[5431607],"stopDateTime":"0001-01-01T00:00:00","isPickup":false,"location":"Abilene, TX","stopDate":"Monday, 01/17/22","stopHours":"09:00 - 10:00","appointmentTime":"09:00","appointmentType":"APPT","instructions":"***LIFTGATE, PALLET JACK, DRIVER ASSIST***--MUST DELIVER ONLY ON APPT TIME-- CANNOT DELIVER EARLY OR LATE \r\n","isDropTrailer":false,"shipperName":"hibbett sports","processedStopDate":""}],"drayStopInfos":null,"rateInfo":null,"isDray":false,"equipmentGroupId":8,"totalCarrierRate":2600.00,"payUpTo":2700.00,"firstLoadInfoId":5431607,"loadStatus":"ACTIVE","hasBlockingAlert":false,"customerLoadBlocked":false,"canSeeRate":false,"canBookNow":false,"canBidNow":true,"buttonData":{"useBidDialog":false,"lastBidAmount":null,"remainingBids":1,"carrierPhoneNumber":null,"carrierPhoneExtension":null},"stopData":[{"addr":"IDX NORTH CAROLINA","city":"Washington","state":"NC","zip":"27889"},{"addr":"hibbett sports","city":"Abilene","state":"TX","zip":"79606"}]}
|
||||||
|
|
||||||
|
- tokens in db, not in config
|
||||||
|
- cache on disk jobinfo
|
||||||
|
- link to view more
|
||||||
|
- map with to-from line
|
||||||
|
- TO CONFLUENT.RS OR W/E
|
||||||
|
- rm get-set stuff for matrix now that it has continuation
|
||||||
- setup ma on element !!fluffychat
|
- setup ma on element !!fluffychat
|
||||||
- !help,
|
- !help,
|
||||||
- !states optional but explicit option
|
- !states optional but explicit option
|
||||||
|
|||||||
Reference in New Issue
Block a user