xmpp_login_ struct {jid string; pass string}
xmpp_bot_authstring_ string
xmpp_state_save_dir_ string
+ button_press_timeout_ int64 = 3600
)
//-------
}()
var present, locked, shut bool = false, true, true
+ var last_buttonpress int64 = 0
var who string
button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)"
-
+ button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"}
+
+ xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe, "Nobody is here"}
+
for eventinterface := range(events) {
switch event := eventinterface.(type) {
case PresenceUpdate:
present = event.Present
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: true}
+ if present {
+ if time.Now().Unix() - last_buttonpress < button_press_timeout_ {
+ xmpp_presence_events_chan_ <- button_status
+ } else {
+ xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"}
+ }
+ } else {
+ xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"}
+ }
case DoorCommandEvent:
if len(event.Who) > 0 && len(event.Using) > 0 {
who = fmt.Sprintf("%s (%s)",event.Who, event.Using)
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: true}
case ButtonPressUpdate:
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo}
+ xmpp_presence_events_chan_ <- button_status
+ last_buttonpress = event.Ts
}
}
}
return &xmpp.Message{Header: xmppmsgheader , Subject: msgsubject, Body: msgbody, Thread: &xmpp.Generic{}}
}
-func (botdata *XmppBot) makeXMPPPresence(to, ptype string) *xmpp.Presence {
+func (botdata *XmppBot) makeXMPPPresence(to, ptype, show, status string) *xmpp.Presence {
xmppmsgheader := xmpp.Header{To: to,
From: botdata.my_jid_,
Id: <-xmpp.Id,
Innerxml: "",
Error: nil,
Nested: make([]interface{},0)}
- return &xmpp.Presence{Header: xmppmsgheader}
+ var gen_show, gen_status *xmpp.Generic
+ if len(show) == 0 {
+ gen_show = nil
+ } else {
+ gen_show = &xmpp.Generic{Chardata: show}
+ }
+ if len(status) == 0 {
+ gen_status = nil
+ } else {
+ gen_status = &xmpp.Generic{Chardata: status}
+ }
+ return &xmpp.Presence{Header: xmppmsgheader, Show: gen_show, Status: gen_status}
}
type R3JIDDesire int
R3DebugInfo
)
+const (
+ ShowOnline string = ""
+ ShowAway string = "away"
+ ShowNotAvailabe string = "xa"
+ ShowDoNotDisturb string = "dnd"
+ ShowFreeForChat string = "chat"
+)
+
type JidData struct {
Online bool
Wants R3JIDDesire
RememberAsStatus bool
}
+type XMPPStatusEvent struct {
+ Show string
+ Status string
+}
+
type RealraumXmppNotifierConfig map[string]JidData
type XmppBot struct {
xmppout <- botdata.makeXMPPMessage(to, pec, nil)
}
}
-
+
+ case XMPPStatusEvent:
+ xmppout <- botdata.makeXMPPPresence("", "", pec.Show, pec.Status)
+
case XMPPMsgEvent:
if pec.RememberAsStatus {
last_status_msg = &pec.Msg
}
switch stanza.GetHeader().Type {
case "subscribe":
- xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed")
+ xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed", "", "")
jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false}
- xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribe")
+ xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribe", "", "")
case "unsubscribe", "unsubscribed":
jabber_events <- JabberEvent{stanza.GetHeader().From, false, R3NeverInfo, false}
botdata.jid_lastauthtime_[stanza.GetHeader().From] = 0 //logout
- xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "unsubscribe")
+ xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "unsubscribe", "","")
case "unavailable":
jabber_events <- JabberEvent{stanza.GetHeader().From, false, R3NoChange, false}
botdata.jid_lastauthtime_[stanza.GetHeader().From] = 0 //logout
roster := xmpp.Roster(botdata.xmppclient_)
for _, entry := range roster {
if entry.Subscription == "from" {
- botdata.xmppclient_.Out <- botdata.makeXMPPPresence(entry.Jid, "subscribe")
+ botdata.xmppclient_.Out <- botdata.makeXMPPPresence(entry.Jid, "subscribe", "","")
}
if entry.Subscription == "none" {
delete(botdata.realraum_jids_, entry.Jid)