accept !radius for miles radius search
parent
eab73aec04
commit
0120fdd0e2
|
|
@ -77,11 +77,11 @@
|
||||||
"Once": false,
|
"Once": false,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"UseZips": true,
|
"UseZips": true,
|
||||||
"RadiusMiles": 300,
|
"RadiusMiles": 200,
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Enabled": true,
|
"Enabled": false,
|
||||||
"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",
|
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId=%d",
|
||||||
"Username": "noeasyrunstrucking@gmail.com",
|
"Username": "noeasyrunstrucking@gmail.com",
|
||||||
|
|
@ -89,7 +89,7 @@
|
||||||
},
|
},
|
||||||
"FastExact": {
|
"FastExact": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"Mock": false,
|
"Mock": true,
|
||||||
"Username": "birdman",
|
"Username": "birdman",
|
||||||
"Password": "166647"
|
"Password": "166647"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
57
main.go
57
main.go
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -84,9 +85,9 @@ func matrixrecv() error {
|
||||||
logtr.Debugf("sending help")
|
logtr.Debugf("sending help")
|
||||||
locationHelp := "`!state nc NC nC Nc` set states for self"
|
locationHelp := "`!state nc NC nC Nc` set states for self"
|
||||||
if config.Get().Brokers.UseZips {
|
if config.Get().Brokers.UseZips {
|
||||||
locationHelp = "`!zip 27006 84058` to set zip codes for self"
|
locationHelp = "...`!zip 27006 84058` to set zip codes for self\n...`!radius 100` to set miles radius to 100, 200, or 300"
|
||||||
}
|
}
|
||||||
help := fmt.Sprintf("commands:\n...`!help` print this help\n...%s\n\nrun a command for someone else: `!zip 2022-12-31 @caleb`", locationHelp)
|
help := fmt.Sprintf("commands:\n...`!help` print this help\n%s\n\nrun a command for someone else: `!zip 2022-12-31 @caleb`", locationHelp)
|
||||||
if err := sender.Send(help); err != nil {
|
if err := sender.Send(help); err != nil {
|
||||||
logtr.Errorf("failed to send help: %v", err)
|
logtr.Errorf("failed to send help: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -151,6 +152,31 @@ func matrixrecv() error {
|
||||||
}
|
}
|
||||||
setNewStates(states)
|
setNewStates(states)
|
||||||
}()
|
}()
|
||||||
|
func() {
|
||||||
|
logtr.Verbosef("looking for radius")
|
||||||
|
db := config.Get().DB()
|
||||||
|
var radius *int
|
||||||
|
for _, msg := range messages {
|
||||||
|
key := fmt.Sprintf("radius_%d", msg.Timestamp.Unix())
|
||||||
|
if !strings.HasPrefix(msg.Content, "!radius ") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||||
|
cmd := msg.Content
|
||||||
|
for strings.HasPrefix(cmd, "!radius ") {
|
||||||
|
cmd = strings.TrimPrefix(cmd, "!radius ")
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(strings.TrimSpace(cmd))
|
||||||
|
if err == nil {
|
||||||
|
radius = &n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||||
|
logtr.Errorf("failed to mark radius gathered @%s: %v", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setNewRadius(radius)
|
||||||
|
}()
|
||||||
func() {
|
func() {
|
||||||
logtr.Verbosef("looking for pauses")
|
logtr.Verbosef("looking for pauses")
|
||||||
db := config.Get().DB()
|
db := config.Get().DB()
|
||||||
|
|
@ -183,6 +209,33 @@ func matrixrecv() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setNewRadius(radius *int) {
|
||||||
|
if radius == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sender := message.NewMatrix()
|
||||||
|
logtr.Debugf("set new radius: %d", *radius)
|
||||||
|
acceptable := map[int]struct{}{
|
||||||
|
100: struct{}{},
|
||||||
|
200: struct{}{},
|
||||||
|
300: struct{}{},
|
||||||
|
}
|
||||||
|
if _, ok := acceptable[*radius]; !ok {
|
||||||
|
sender.Send(fmt.Sprintf("radius of %v is not among acceptable %+v", *radius, acceptable))
|
||||||
|
logtr.Debugf("bad radius, not setting: %d", *radius)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf := *config.Get()
|
||||||
|
if conf.Brokers.RadiusMiles == *radius {
|
||||||
|
logtr.Debugf("noop radius, not setting: %d", *radius)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf.Brokers.RadiusMiles = *radius
|
||||||
|
logtr.Infof("updating config new pauses: %+v", conf)
|
||||||
|
config.Set(conf)
|
||||||
|
sender.Send(fmt.Sprintf("now using radius of %d mi for zip code search", *radius))
|
||||||
|
}
|
||||||
|
|
||||||
func setNewPauses(pauses map[string]time.Time) {
|
func setNewPauses(pauses map[string]time.Time) {
|
||||||
if len(pauses) == 0 {
|
if len(pauses) == 0 {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue