support !help, find clints change to end of string

This commit is contained in:
Bel LaPointe
2022-01-12 23:23:30 -05:00
parent de80f11392
commit 72a474b50a
3 changed files with 48 additions and 16 deletions

27
main.go
View File

@@ -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 {