Browse Source

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

change-name
phail 4 years ago committed by Gogs
parent
commit
808d9d2cd8
  1. 7
      matrix/matrix.go
  2. 9
      txt/txt.go
  3. 2
      xmpp/xmpp.go

7
matrix/matrix.go

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

9
txt/txt.go

@ -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.`

2
xmpp/xmpp.go

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