Wants R3JIDDesire
}
-type PresenceEvent struct {
+type XMPPPresenceEvent struct {
Present bool
+ Who string
DoorLock bool
- DoorAjar bool
+ DoorShut bool
+ Button bool
}
type RealraumXmppNotifierConfig map[string]JidData
func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presence_events <- chan interface{}, jabber_events <- chan JabberEvent) {
var msg, presence_str, lock_str, ajar_str string
- last_presence := false
var debug_msg bool
for {
continue
case string:
msg = pec
- case PresenceEvent:
+ debug_msg = true
+ case XMPPPresenceEvent:
if pec.Present {
presence_str = "Somebody is present !"
} else {
} else {
lock_str = "unlocked"
}
- if pec.DoorAjar {
- ajar_str = "ajar"
- } else {
+ if pec.DoorShut {
ajar_str = "shut"
+ } else {
+ ajar_str = "ajar"
}
- msg = fmt.Sprintf("%s (Door is %s and %s)", presence_str, lock_str, ajar_str)
- if last_presence == pec.Present {
- debug_msg = true
+ if pec.Button {
+ msg = "The button has been pressed ! Propably someone is bored and need company ! ;-)"
} else {
- last_presence = pec.Present
+ msg = fmt.Sprintf("%s (Door is %s and %s and was last used by %s)", presence_str, lock_str, ajar_str, pec.Who)
}
default:
break
}
if (jiddata.Wants == R3NoOfflineInfo && jiddata.Online) || jiddata.Wants > R3NoOfflineInfo {
xmppout <- botdata.makeXMPPMessage(to, msg, nil)
- } //else {
- //~ fmt.Println("Not sending to ", to, jiddata)
- //~ }
+ }
}
case je := <-jabber_events:
case "bye", "Bye", "quit", "logout":
botdata.jid_lastauthtime_[inmsg.GetHeader().From] = 0
xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Bye Bye !" ,nil)
+ case "open","close":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Sorry, I can't operate the door for you." ,nil)
default:
//~ auth_match = re_msg_auth_.FindStringSubmatch(inmsg.Body.Chardata)
xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_, "Available Commands")
}
}
-var default_state_save_dir_ string = "/flash/var/lib/r3netstatus/"
-
-func NewStartedBot(loginjid, loginpwd, password string, insecuretls bool) (*XmppBot, chan interface{}, error) {
+func NewStartedBot(loginjid, loginpwd, password, state_save_dir string, insecuretls bool) (*XmppBot, chan interface{}, error) {
var err error
botdata := new(XmppBot)
botdata.my_login_password_ = loginpwd
botdata.auth_timeout_ = 1200
- botdata.config_file_ = path.Join(default_state_save_dir_, "r3xmpp."+removeJIDResource(loginjid)+".json")
+ botdata.config_file_ = path.Join(state_save_dir, "r3xmpp."+removeJIDResource(loginjid)+".json")
//~ log.Println(botdata.config_file_)
close(*botdata.presence_events_)
}
}
-
-//~ func main() {
- //~ bot, presence_events, err := NewStartedBot("realrauminfo@realraum.at/Tuer", "d7ynC6Dg", "r3alraumOLGAXMPPInfos", true)
-
- //~ if err != nil {
- //~ log.Println(err)
- //~ os.Exit(1)
- //~ }
-
- //~ presence_events <- PresenceEvent{true, true, true}
- //~ presence_events <- PresenceEvent{true, true, false}
- //~ presence_events <- PresenceEvent{true, false, false}
-
- //~ p := make([]byte, 1024)
- //~ for
- //~ {
- //~ nr, _ := os.Stdin.Read(p)
- //~ if nr == 0 {
- //~ break
- //~ }
- //~ }
-
- //~ bot.StopBot()
-//~ }