add schalter

This commit is contained in:
Martin/Geno 2019-08-06 21:05:15 +02:00
parent 40ef257672
commit 10f1fae475
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
4 changed files with 60 additions and 2 deletions

View File

@ -8,4 +8,4 @@ password = "test"
[schalter] [schalter]
url = "https://schalter.ccchb.de/spaceapi.json" url = "https://schalter.ccchb.de/spaceapi.json"
muc = ["ffhb_events@conference.chat.sum7.eu","#ccchb@irc.hackint.org"] mucs = ["ffhb_events@conference.chat.sum7.eu","#ccchb@irc.hackint.org"]

View File

@ -14,7 +14,7 @@ func (s *Schalter) HandleBotMessage(c xmpp.Sender, msg stanza.Message) error {
Attrs: stanza.Attrs{Type: msg.Type, Attrs: stanza.Attrs{Type: msg.Type,
To: msg.From, To: msg.From,
}, },
Body: s.StateString(), Body: s.stateString(),
} }
if msg.Type == stanza.MessageTypeGroupchat { if msg.Type == stanza.MessageTypeGroupchat {
reply.To = jid.Bare() reply.To = jid.Bare()

45
schalter/main.go Normal file
View File

@ -0,0 +1,45 @@
package schalter
import (
"github.com/bdlm/log"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
"dev.sum7.eu/ccchb/ccchatbot/runtime"
)
type Schalter struct {
URL string `toml:"url"`
Path string `toml:"path"`
Nickname string `toml:"nickname"`
Users []string `toml:"users"`
MUCs []string `toml:"mucs"`
state bool
spaceName string
}
func (s *Schalter) updatePresence(c xmpp.Sender) {
pres := stanza.Presence{
Show: stanza.PresenceShowChat,
Status: s.stateString(),
}
if s.state {
pres.Show = stanza.PresenceShowXA
}
c.Send(pres)
}
func (s *Schalter) Run(c xmpp.Sender) {
if s.Nickname == "" {
s.Nickname = "ccchalter"
}
s.fetchState()
s.updatePresence(c)
for _, m := range s.MUCs {
runtime.JoinMUC(c, m, s.Nickname)
}
log.Infof("started schalter with state: %s", s.stateString())
}

13
schalter/state.go Normal file
View File

@ -0,0 +1,13 @@
package schalter
import "fmt"
func (s *Schalter) stateString() string {
if s.state {
return fmt.Sprintf("%s is open", s.spaceName)
}
return fmt.Sprintf("%s is closed", s.spaceName)
}
func (s *Schalter) fetchState() bool {
return false
}