new mode on_with_recap
authorBernhard Tittelbach <xro@realraum.at>
Wed, 4 Sep 2013 23:50:25 +0000 (23:50 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Wed, 4 Sep 2013 23:50:25 +0000 (23:50 +0000)
r3-netstatus/r3xmppbot/r3xmppbot.go

index da99930..fc2b239 100644 (file)
@@ -74,6 +74,7 @@ const (
     R3NoChange R3JIDDesire = -1
     R3NeverInfo R3JIDDesire = iota // ignore first value by assigning to blank identifier
     R3OnlineOnlyInfo
     R3NoChange R3JIDDesire = -1
     R3NeverInfo R3JIDDesire = iota // ignore first value by assigning to blank identifier
     R3OnlineOnlyInfo
+    R3OnlineOnlyWithRecapInfo
     R3AlwaysInfo
     R3DebugInfo
 )
     R3AlwaysInfo
     R3DebugInfo
 )
@@ -175,7 +176,7 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc
                         last_status_msg = &pec.Msg
                     }
                     for to, jiddata := range botdata.realraum_jids_  {
                         last_status_msg = &pec.Msg
                     }
                     for to, jiddata := range botdata.realraum_jids_  {
-                        if  jiddata.Wants >= pec.DistributeLevel && ((jiddata.Wants == R3OnlineOnlyInfo && jiddata.Online) || jiddata.Wants > R3OnlineOnlyInfo) {
+                        if  jiddata.Wants >= pec.DistributeLevel && ((jiddata.Wants >= R3OnlineOnlyInfo && jiddata.Online) || jiddata.Wants >= R3AlwaysInfo) {
                             xmppout <-  botdata.makeXMPPMessage(to, pec.Msg, nil)
                         }
                     }
                             xmppout <-  botdata.makeXMPPMessage(to, pec.Msg, nil)
                         }
                     }
@@ -187,10 +188,10 @@ func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presenc
             simple_jid := removeJIDResource(je.JID)
             jid_data, jid_in_map := botdata.realraum_jids_[simple_jid]
             if jid_in_map {
             simple_jid := removeJIDResource(je.JID)
             jid_data, jid_in_map := botdata.realraum_jids_[simple_jid]
             if jid_in_map {
-                jid_data.Online = je.Online
-                if je.StatusNow && last_status_msg != nil {
+                if last_status_msg != nil && (je.StatusNow || (! jid_data.Online && je.Online && jid_data.Wants == R3OnlineOnlyWithRecapInfo) ) {
                     xmppout <-  botdata.makeXMPPMessage(je.JID, last_status_msg, nil)
                 }
                     xmppout <-  botdata.makeXMPPMessage(je.JID, last_status_msg, nil)
                 }
+                jid_data.Online = je.Online
                 if je.Wants > R3NoChange {
                     jid_data.Wants = je.Wants
                 }
                 if je.Wants > R3NoChange {
                     jid_data.Wants = je.Wants
                 }
@@ -218,7 +219,7 @@ func (botdata *XmppBot) isAuthenticated(jid string) bool {
 }
 
 const help_text_ string = "\n*auth*<password>* ...Enables you to use more commands.\n*time* ...Returns bot time."
 }
 
 const help_text_ string = "\n*auth*<password>* ...Enables you to use more commands.\n*time* ...Returns bot time."
-const help_text_auth string = "You are authorized to use the following commands:\n*on* ...You will be notified of r3 status changes.\n*off* ...You will no longer recieve notifications.\n*on_while_offline* ...You will be notified of r3 status changes even if you are offline.\n*status* ...Query current status.\n*time* ...Returns bot time.\n*bye* ...Logout."
+const help_text_auth string = "You are authorized to use the following commands:\n*off* ...You will no longer receive notifications.\n*on* ...You will be notified of r3 status changes.\n*on_with_recap* ...Like *on* but additionally you will receive the current r3 status when you come online.\n*on_while_offline* ...You will receive all r3 status changes, wether your are online or offline.\n*status* ...Use it to query the current status.\n*time* ...Returns bot time.\n*bye* ...Logout."
 
 //~ var re_msg_auth_    *regexp.Regexp     = regexp.MustCompile("auth\s+(\S+)")
 
 
 //~ var re_msg_auth_    *regexp.Regexp     = regexp.MustCompile("auth\s+(\S+)")
 
@@ -232,13 +233,16 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout
         switch bodytext {
             case "on", "*on*":
                 jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyInfo, false}
         switch bodytext {
             case "on", "*on*":
                 jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3OnlineOnlyInfo, false}
-                xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 information while online" , "Your New Status")
+                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}
             case "off", "*off*":
                 jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3NeverInfo, false}
-                xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Do not receive r3 information" , "Your New Status")
+                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}
             case "on_while_offline", "*on_while_offline*":
                 jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3AlwaysInfo, false}
-                xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Receive r3 information even while offline" , "Your New Status")
+                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 "debug":
                 jabber_events <- JabberEvent{inmsg.GetHeader().From, true, R3DebugInfo, false}
                 xmppout <- botdata.makeXMPPMessage(inmsg.GetHeader().From, "Debug mode enabled" , "Your New Status")
@@ -262,7 +266,7 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout
             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 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*":
+            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)
                 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)