add schalter
This commit is contained in:
parent
40ef257672
commit
10f1fae475
|
@ -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"]
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue