diff --git a/config.toml b/config.toml index cef33f5..1825865 100644 --- a/config.toml +++ b/config.toml @@ -8,4 +8,4 @@ password = "test" [schalter] 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"] diff --git a/schalter/bot.go b/schalter/bot.go index 754c72f..2f143d0 100644 --- a/schalter/bot.go +++ b/schalter/bot.go @@ -14,7 +14,7 @@ func (s *Schalter) HandleBotMessage(c xmpp.Sender, msg stanza.Message) error { Attrs: stanza.Attrs{Type: msg.Type, To: msg.From, }, - Body: s.StateString(), + Body: s.stateString(), } if msg.Type == stanza.MessageTypeGroupchat { reply.To = jid.Bare() diff --git a/schalter/main.go b/schalter/main.go new file mode 100644 index 0000000..4fd947d --- /dev/null +++ b/schalter/main.go @@ -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()) +} diff --git a/schalter/state.go b/schalter/state.go new file mode 100644 index 0000000..c8d79ce --- /dev/null +++ b/schalter/state.go @@ -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 +}