job has multiline formatter

master
Bel LaPointe 2022-01-10 23:00:45 -05:00
parent 2791ba6763
commit ec2b514a9f
3 changed files with 18 additions and 9 deletions

View File

@ -34,3 +34,16 @@ func (j Job) String() string {
func (j JobLocation) String() string { 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) FormatMultilineText() string {
return fmt.Sprintf(
"--- %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
j.Pickup.State,
j.Dropoff.State,
j.Pickup.String(),
j.Dropoff.String(),
j.Weight,
j.Miles,
j.Meta,
)
}

View File

@ -8,6 +8,7 @@ import (
"local/storage" "local/storage"
"local/truckstop/broker" "local/truckstop/broker"
"local/truckstop/config" "local/truckstop/config"
"local/truckstop/message"
"log" "log"
"regexp" "regexp"
"strings" "strings"
@ -153,7 +154,6 @@ func dropBanlistJobs(jobs []broker.Job) ([]broker.Job, error) {
} }
func sendJob(job broker.Job) error { func sendJob(job broker.Job) error {
// TODO sender := message.NewMatrix()
log.Printf("found job: %s", job) return sender.Send(job.FormatMultilineText())
return nil
} }

View File

@ -1,7 +1,6 @@
package message package message
import ( import (
"fmt"
"local/truckstop/config" "local/truckstop/config"
"github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrix"
@ -33,9 +32,6 @@ func (m Matrix) Send(text string) error {
if err != nil { if err != nil {
return err return err
} }
resp, err := c.SendText(m.room, text) _, err = c.SendText(m.room, text)
if err != nil { return err
return err
}
return fmt.Errorf("%+v", resp)
} }