impl matrix continuation so i can get rid of per-msg get-set
parent
65e43f8d2a
commit
a07a7d5a00
|
|
@ -23,6 +23,7 @@
|
|||
"Clients": {
|
||||
"bel": {
|
||||
"States": [
|
||||
"GA",
|
||||
"NC"
|
||||
],
|
||||
"IDs": {
|
||||
|
|
@ -67,6 +68,7 @@
|
|||
"Matrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": false,
|
||||
"Continuation": "s2783_0_0_0_0_0_0_0_0",
|
||||
"Homeserver": "https://synapse.home.blapointe.com",
|
||||
"Username": "@bel:synapse.home.blapointe.com",
|
||||
"Token": "MDAyOGxvY2F0aW9uIHN5bmFwc2UuaG9tZS5ibGFwb2ludGUuY29tCjAwMTNpZGVudGlmaWVyIGtleQowMDEwY2lkIGdlbiA9IDEKMDAzMmNpZCB1c2VyX2lkID0gQGJlbDpzeW5hcHNlLmhvbWUuYmxhcG9pbnRlLmNvbQowMDE2Y2lkIHR5cGUgPSBhY2Nlc3MKMDAyMWNpZCBub25jZSA9IFpXTTtCaTNBODdtSTpsZkAKMDAyZnNpZ25hdHVyZSBX37kStY2wt_ftMfEYPfk1ADMJ6ZVfZsro9ic3weZ25Ao",
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ type Config struct {
|
|||
Matrix struct {
|
||||
ReceiveEnabled bool
|
||||
Mock bool
|
||||
Continuation string
|
||||
Homeserver string
|
||||
Username string
|
||||
Token string
|
||||
|
|
|
|||
11
main.go
11
main.go
|
|
@ -23,8 +23,10 @@ func main() {
|
|||
if err := config.Refresh(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := matrixrecv(); err != nil {
|
||||
panic(err)
|
||||
if config.Get().Message.Matrix.ReceiveEnabled {
|
||||
if err := matrixrecv(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
lock := &sync.Mutex{}
|
||||
go func() {
|
||||
|
|
@ -138,6 +140,11 @@ func matrixrecv() error {
|
|||
}
|
||||
setNewPauses(pauses)
|
||||
}()
|
||||
conf := *config.Get()
|
||||
if conf.Message.Matrix.Continuation != sender.Continuation() {
|
||||
conf.Message.Matrix.Continuation = sender.Continuation()
|
||||
config.Set(conf)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,21 +15,23 @@ import (
|
|||
)
|
||||
|
||||
type Matrix struct {
|
||||
mock bool
|
||||
homeserver string
|
||||
username string
|
||||
token string
|
||||
room string
|
||||
mock bool
|
||||
homeserver string
|
||||
username string
|
||||
token string
|
||||
room string
|
||||
continuation string
|
||||
}
|
||||
|
||||
func NewMatrix() Matrix {
|
||||
conf := config.Get().Message.Matrix
|
||||
return Matrix{
|
||||
homeserver: conf.Homeserver,
|
||||
username: conf.Username,
|
||||
token: conf.Token,
|
||||
room: conf.Room,
|
||||
mock: conf.Mock,
|
||||
homeserver: conf.Homeserver,
|
||||
username: conf.Username,
|
||||
token: conf.Token,
|
||||
room: conf.Room,
|
||||
mock: conf.Mock,
|
||||
continuation: conf.Continuation,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +39,11 @@ func (m Matrix) getclient() (*gomatrix.Client, error) {
|
|||
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 {
|
||||
log.Printf("matrix.Receive()")
|
||||
messages := make([]Message, 0)
|
||||
|
|
@ -65,11 +71,14 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
return nil, err
|
||||
}
|
||||
messages := make([]Message, 0)
|
||||
result, err := c.Messages(m.room, "", "", 'b', 50)
|
||||
result, err := c.Messages(m.room, "", m.continuation, 'b', 50)
|
||||
if err != nil {
|
||||
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.Start
|
||||
for _, event := range result.Chunk {
|
||||
//log.Printf("%+v", event)
|
||||
if _, ok := matrixIDs[event.Sender]; !ok {
|
||||
continue
|
||||
}
|
||||
|
|
@ -82,6 +91,7 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
}
|
||||
clientChange := regexp.MustCompile("@[a-z]+$")
|
||||
log.Printf("rewriting messages based on @abc")
|
||||
for i := range messages {
|
||||
if found := clientChange.FindString(messages[i].Content); found != "" {
|
||||
messages[i].Content = strings.TrimSpace(strings.ReplaceAll(messages[i].Content, found, ""))
|
||||
|
|
@ -95,6 +105,14 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func TestMatrixSend(t *testing.T) {
|
|||
if err := json.Unmarshal(b, &c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var sender Sender = Matrix{
|
||||
var sender Sender = &Matrix{
|
||||
homeserver: c.Message.Matrix.Homeserver,
|
||||
username: c.Message.Matrix.Username,
|
||||
token: c.Message.Matrix.Token,
|
||||
|
|
@ -43,7 +43,7 @@ func TestMatrixReceive(t *testing.T) {
|
|||
if err := json.Unmarshal(b, &c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var sender Sender = Matrix{
|
||||
var sender Sender = &Matrix{
|
||||
homeserver: c.Message.Matrix.Homeserver,
|
||||
username: c.Message.Matrix.Username,
|
||||
token: c.Message.Matrix.Token,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
todo:
|
||||
- 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_PsEhPBdJydqbXwg8ifQHkaPNAojsIr2rnJ3T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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"}]}
|
||||
|
||||
- no hard code jpeg or have it in multiple places
|
||||
- todo: switch house to selfhosted for rate limit
|
||||
tags: now
|
||||
|
|
|
|||
Loading…
Reference in New Issue