Browse Source

Add "!close" command and implement preliminary help function (#1)

change-name
phail 1 year ago
parent
commit
808d9d2cd8
3 changed files with 11 additions and 7 deletions
  1. +5
    -2
      matrix/matrix.go
  2. +5
    -4
      txt/txt.go
  3. +1
    -1
      xmpp/xmpp.go

+ 5
- 2
matrix/matrix.go View File

@@ -60,6 +60,10 @@ func Listener(storage *spaceapi.Storage, homeServer, userID, token, room string)
}

switch body {
case txt.CommandHelp:
if _, err := cli.SendText(room, txt.HelpMessage); err != nil {
log.Printf("Error sending message: %s", err)
}
case txt.CommandState:
state := storage.Status().State
msg := txt.StateUnknown
@@ -76,13 +80,12 @@ func Listener(storage *spaceapi.Storage, homeServer, userID, token, room string)
if _, err := cli.SendText(room, msg); err != nil {
log.Printf("Error sending message: %s", err)
}
case txt.CommandClose:
case txt.CommandClose, txt.CommandClosed:
storage.Modify(func(status *spaceapi.SpaceStatus) {
open := false
status.State.Open = &open
})
}
// TODO react to events
})

go func() {

+ 5
- 4
txt/txt.go View File

@@ -1,9 +1,10 @@
package txt

const (
CommandHelp = "!help"
CommandState = "!state"
CommandClose = "!closed"
CommandHelp = "!help"
CommandState = "!state"
CommandClose = "!close"
CommandClosed = "!closed"

StateUnknown = "Ich weiß leider nicht ob der Space offen ist."
StateOpen = "Space ist OFFEN."
@@ -16,7 +17,7 @@ const (

!help - Diese Nachricht.
!state - Ist der Space offen?
!closed - Space ist zu.
!close - Space ist zu.

Gern geschehen.`


+ 1
- 1
xmpp/xmpp.go View File

@@ -129,7 +129,7 @@ func handleMessage(storage *spaceapi.Storage, client *xmpp.Client, target string
if err := sendFunc(client, replyTarget, msg); err != nil {
return fmt.Errorf("error sending reply: %s", err)
}
case txt.CommandClose:
case txt.CommandClose, txt.CommandClosed:
if chat.Type != "groupchat" {
if err := sendMessage(client, chat.Remote, txt.ErrorNonPublic); err != nil {
return fmt.Errorf("error sending reply: %s", err)

Loading…
Cancel
Save