- if inmsg.Body == nil || inmsg.GetHeader() == nil {
- return
- }
- bodytext :=inmsg.Body.Chardata
- if botdata.isAuthenticated(inmsg.GetHeader().From) {
- switch bodytext {
- case "on", "*on*":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyInfo, false}
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 status updates while online." , "Your New Status")
- case "off", "*off*":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3NeverInfo, false}
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Do not receive anything." , "Your New Status")
- case "on_with_recap", "*on_with_recap*":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyWithRecapInfo, false}
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 status updates while and current status on coming, online." , "Your New Status")
- case "on_while_offline", "*on_while_offline*":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3AlwaysInfo, false}
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive all r3 status updates, even if you are offline." , "Your New Status")
- case "debug":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3DebugInfo, false}
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Debug mode enabled" , "Your New Status")
- case "bye", "Bye", "quit", "logout", "*bye*":
- 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)
- case "status", "*status*":
- jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3NoChange, true}
- case "time", "*time*":
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, time.Now().String() , nil)
- default:
- //~ auth_match = re_msg_auth_.FindStringSubmatch(inmsg.Body.Chardata)
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_auth, nil)
- }
- } else {
- switch bodytext {
- case "Hilfe","hilfe","help","Help","?","hallo","Hallo","Yes","yes","ja","ja bitte","bitte","sowieso":
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_, "Available Commands")
- case botdata.auth_cmd_, botdata.auth_cmd2_:
- botdata.jid_lastauthtime_[inmsg.GetHeader().From] = time.Now().Unix()
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_auth, nil)
- case "status", "*status*", "off", "*off*", "on", "*on*", "on_while_offline", "*on_while_offline*", "on_with_recap", "*on_with_recap*":
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Sorry, you need to be authorized to do that." , nil)
- case "time", "*time*":
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, time.Now().String() , nil)
- default:
- //~ auth_match = re_msg_auth_.FindStringSubmatch(inmsg.Body.Chardata)
- xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "A nice day to you too !\nDo you need \"help\" ?", nil)
- }
- }
+ if inmsg.Body == nil || inmsg.GetHeader() == nil {
+ return
+ }
+ bodytext_args := strings.Split(strings.Replace(inmsg.Body.Chardata, "*", " ", -1), " ")
+ for len(bodytext_args) > 1 && len(bodytext_args[0]) == 0 {
+ bodytext_args = bodytext_args[1:len(bodytext_args)] //get rid of empty first strings resulting from " text"
+ }
+ bodytext_lc_cmd := strings.ToLower(bodytext_args[0])
+ if botdata.isAuthenticated(inmsg.GetHeader().From) {
+ switch bodytext_lc_cmd {
+ case "on":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyInfo, false}
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 status updates while online.", "Your New Status")
+ case "off":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3NeverInfo, false}
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Do not receive anything.", "Your New Status")
+ case "on_with_recap":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyWithRecapInfo, false}
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 status updates while and current status on coming, online.", "Your New Status")
+ case "on_while_offline":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3AlwaysInfo, false}
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive all r3 status updates, even if you are offline.", "Your New Status")
+ case "debug":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3DebugInfo, false}
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Debug mode enabled", "Your New Status")
+ case "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'm just weak software, not strong enough to operate the door for you.", nil)
+ case "status":
+ jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3NoChange, true}
+ case "time":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, time.Now().String(), nil)
+ case "ping":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Pong with auth", nil)
+ default:
+ //~ auth_match = re_msg_auth_.FindStringSubmatch(inmsg.Body.Chardata)
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_auth, nil)
+ }
+ } else {
+ switch bodytext_lc_cmd {
+ case "hilfe", "help", "?", "hallo", "yes", "ja", "ja bitte", "bitte", "sowieso":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_, "Available Commands")
+ case "auth":
+ authindex := 1
+ for len(bodytext_args) > authindex && len(bodytext_args[authindex]) == 0 {
+ authindex++
+ }
+ if len(bodytext_args) > authindex && bodytext_args[authindex] == botdata.password_ {
+ botdata.jid_lastauthtime_[inmsg.GetHeader().From] = time.Now().Unix()
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, help_text_auth, nil)
+ }
+ case "status", "off", "on", "on_while_offline", "on_with_recap":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Sorry, you need to be authorized to do that.", nil)
+ case "time":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, time.Now().String(), nil)
+ case "ping":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Pong", nil)
+ case "":
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "You're a quiet one, aren't you?", nil)
+ default:
+ //~ auth_match = re_msg_auth_.FindStringSubmatch(inmsg.Body.Chardata)
+ xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "A nice day to you too !\nDo you need \"help\" ?", nil)
+ }
+ }