support !help, find clints change to end of string
parent
de80f11392
commit
72a474b50a
23
config.json
23
config.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"Interval": {
|
||||
"Input": "10s..30s",
|
||||
"Input": "15s..20s",
|
||||
"OK": "6h0m0s..6h0m0s",
|
||||
"Error": "6h0m0s..6h0m0s"
|
||||
},
|
||||
|
|
@ -17,16 +17,18 @@
|
|||
},
|
||||
"Maps": {
|
||||
"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,
|
||||
"Dropoff": true
|
||||
"Pickup": false,
|
||||
"Dropoff": false
|
||||
},
|
||||
"Clients": {
|
||||
"bel": {
|
||||
"States": [],
|
||||
"States": [
|
||||
"GA"
|
||||
],
|
||||
"IDs": {
|
||||
"Matrix": "@breellocaldev:matrix.org"
|
||||
},
|
||||
"Available": 5642452800
|
||||
"Available": 1641013200
|
||||
},
|
||||
"broc": {
|
||||
"States": [
|
||||
|
|
@ -49,7 +51,7 @@
|
|||
},
|
||||
"pa": {
|
||||
"States": [
|
||||
"OH"
|
||||
"OK"
|
||||
],
|
||||
"IDs": {
|
||||
"Matrix": "@belandbroc:matrix.org"
|
||||
|
|
@ -58,20 +60,21 @@
|
|||
}
|
||||
},
|
||||
"Storage": [
|
||||
"map"
|
||||
"files",
|
||||
"/tmp/play"
|
||||
],
|
||||
"Message": {
|
||||
"Matrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": true,
|
||||
"Mock": false,
|
||||
"Homeserver": "https://matrix-client.matrix.org",
|
||||
"Username": "@breellocaldev:matrix.org",
|
||||
"Token": "syt_YnJlZWxsb2NhbGRldg_HTewKMMePdEcLvceAKEz_2fHsHa",
|
||||
"Device": "TGNIOGKATZ",
|
||||
"Room": "!ySKxwGHQPzPfVAldfJ:matrix.org"
|
||||
"Room": "!hmZLTAfvaizaGquCGM:matrix.org"
|
||||
}
|
||||
},
|
||||
"Once": true,
|
||||
"Once": false,
|
||||
"Brokers": {
|
||||
"NTG": {
|
||||
"Mock": true,
|
||||
|
|
|
|||
27
main.go
27
main.go
|
|
@ -56,6 +56,31 @@ func matrixrecv() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func() {
|
||||
log.Printf("looking for help")
|
||||
printed := false
|
||||
for _, msg := range messages {
|
||||
if !strings.HasPrefix(msg.Content, "!help") {
|
||||
continue
|
||||
}
|
||||
if !printed {
|
||||
key := fmt.Sprintf("help_%d", msg.Timestamp.Unix())
|
||||
db := config.Get().DB()
|
||||
if _, err := db.Get(key); err == storage.ErrNotFound {
|
||||
log.Printf("sending help")
|
||||
help := fmt.Sprintf("commands:\n\t!help\tprint this help\n\t!state nc NC nC Nc\tset states for self\n\t!available 2022-12-31\tset date self is available for work\n\nrun a command for someone else: `!state ga @caleb`")
|
||||
if err := sender.Send(help); err != nil {
|
||||
log.Printf("failed to send help: %v", err)
|
||||
} else {
|
||||
printed = true
|
||||
if err := db.Set(key, []byte{'k'}); err != nil {
|
||||
log.Printf("failed to mark help given @%s: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
func() {
|
||||
log.Printf("looking for states")
|
||||
states := map[string]map[config.State]struct{}{}
|
||||
|
|
@ -98,10 +123,10 @@ func matrixrecv() error {
|
|||
}
|
||||
|
||||
func setNewPauses(pauses map[string]time.Time) {
|
||||
log.Printf("set new pauses: %+v", pauses)
|
||||
if len(pauses) == 0 {
|
||||
return
|
||||
}
|
||||
log.Printf("set new pauses: %+v", pauses)
|
||||
conf := *config.Get()
|
||||
changed := map[string]time.Time{}
|
||||
for client, pause := range pauses {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,10 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
log.Printf("matrix.Receive()")
|
||||
messages := make([]Message, 0)
|
||||
for k := range config.Get().Clients {
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "OH"})
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!state OH"})
|
||||
if k == "bel" {
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!help"})
|
||||
}
|
||||
if k == "broc" {
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!available 2148-10-" + fmt.Sprint(time.Now().Unix()%28)})
|
||||
}
|
||||
|
|
@ -62,6 +65,9 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
messages := make([]Message, 0)
|
||||
result, err := c.Messages(m.room, "", "", 'b', 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, event := range result.Chunk {
|
||||
if _, ok := matrixIDs[event.Sender]; !ok {
|
||||
continue
|
||||
|
|
@ -74,10 +80,7 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clientChange := regexp.MustCompile("^@[a-z]+")
|
||||
clientChange := regexp.MustCompile("@[a-z]+$")
|
||||
for i := range messages {
|
||||
if found := clientChange.FindString(messages[i].Content); found != "" {
|
||||
messages[i].Content = strings.TrimSpace(strings.ReplaceAll(messages[i].Content, found, ""))
|
||||
|
|
@ -89,6 +92,7 @@ func (m Matrix) Receive() ([]Message, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
messages[i].Content = strings.TrimSpace(messages[i].Content)
|
||||
}
|
||||
return messages, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue