ccchatbot/schalter/main.go
2019-08-06 21:05:15 +02:00

45 lines
820 B
Go

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())
}