accept !radius for miles radius search
parent
c40b99a8d8
commit
5d4677ab5c
|
|
@ -77,11 +77,11 @@
|
|||
"Once": false,
|
||||
"Brokers": {
|
||||
"UseZips": true,
|
||||
"RadiusMiles": 300,
|
||||
"RadiusMiles": 200,
|
||||
"NTG": {
|
||||
"Enabled": true,
|
||||
"Enabled": false,
|
||||
"JobInfo": true,
|
||||
"Mock": false,
|
||||
"Mock": true,
|
||||
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",
|
||||
"LoadPageAPIURIFormat": "https://ntgvision.com/api/v1/load/LoadDetails?loadId=%d",
|
||||
"Username": "noeasyrunstrucking@gmail.com",
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
},
|
||||
"FastExact": {
|
||||
"Enabled": true,
|
||||
"Mock": false,
|
||||
"Mock": true,
|
||||
"Username": "birdman",
|
||||
"Password": "166647"
|
||||
}
|
||||
|
|
|
|||
57
main.go
57
main.go
|
|
@ -13,6 +13,7 @@ import (
|
|||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -84,9 +85,9 @@ func matrixrecv() error {
|
|||
logtr.Debugf("sending help")
|
||||
locationHelp := "`!state nc NC nC Nc` set states for self"
|
||||
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 {
|
||||
logtr.Errorf("failed to send help: %v", err)
|
||||
} else {
|
||||
|
|
@ -151,6 +152,31 @@ func matrixrecv() error {
|
|||
}
|
||||
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() {
|
||||
logtr.Verbosef("looking for pauses")
|
||||
db := config.Get().DB()
|
||||
|
|
@ -183,6 +209,33 @@ func matrixrecv() error {
|
|||
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) {
|
||||
if len(pauses) == 0 {
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue