X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=r3-netstatus%2Fr3xmppbot%2Fr3xmppbot.go;fp=r3-netstatus%2Fr3xmppbot%2Fr3xmppbot.go;h=b73445b7a80a798321b7c7a2d3acb8e19c849709;hb=3532254fdc34a8649a2894e8e746a4bf61947bde;hp=465ee951c7b5919bd4592e40a69d251294e6e3dd;hpb=6f78aae1eac804c1049def612920f9ddf9e189c8;p=svn42.git diff --git a/r3-netstatus/r3xmppbot/r3xmppbot.go b/r3-netstatus/r3xmppbot/r3xmppbot.go index 465ee95..b73445b 100644 --- a/r3-netstatus/r3xmppbot/r3xmppbot.go +++ b/r3-netstatus/r3xmppbot/r3xmppbot.go @@ -71,10 +71,12 @@ type JabberEvent struct { 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 @@ -135,7 +137,6 @@ func init() { 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 { @@ -148,7 +149,8 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc continue case string: msg = pec - case PresenceEvent: + debug_msg = true + case XMPPPresenceEvent: if pec.Present { presence_str = "Somebody is present !" } else { @@ -159,16 +161,15 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc } 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 @@ -180,9 +181,7 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc } 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: @@ -242,6 +241,8 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout 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") @@ -282,9 +283,7 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm } } -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) @@ -295,7 +294,7 @@ func NewStartedBot(loginjid, loginpwd, password string, insecuretls bool) (*Xmpp 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_) @@ -341,27 +340,3 @@ func (botdata *XmppBot) StopBot() { 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() -//~ }