]> cgit.babelmonkeys.de Git - mpdbot.git/blobdiff - src/mpdbot.m
Auto-confirm subscription requests
[mpdbot.git] / src / mpdbot.m
index d5273a8655c30547d6938924778d820e728b0763..1c7ab7d4ac18cdcee606e4230ada7da49953cd92 100644 (file)
@@ -49,7 +49,8 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        [conn setDelegate: self];
 
        if ([arguments count] != 3) {
-               of_log(@"Invalid count of command line arguments!");
+               [of_stdout writeFormat: @"Usage: %@ <server> <user> <passwd>\n",
+                   [OFApplication programName]];
                [OFApplication terminateWithStatus: 1];
        }
 
@@ -68,7 +69,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 
 - (void)connectionWasAuthenticated: (XMPPConnection*)conn
 {
-       of_log(@"Auth successful");
+       [of_stdout writeLine: @"Auth successful"];
 }
 
 - (void)connection: (XMPPConnection*)conn
@@ -77,7 +78,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        XMPPPresence *pres;
        XMPPIQ *disco;
 
-       of_log(@"Bound to JID: %@", [jid fullJID]);
+       [of_stdout writeFormat: @"Bound to JID: %@\n", [jid fullJID]];
 
        pres = [XMPPPresence presence];
        [pres addPriority: 0];
@@ -128,11 +129,17 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 -   (void)connection: (XMPPConnection*)conn
   didReceivePresence: (XMPPPresence*)pres
 {
-       of_log(@"Presence: %@", pres);
+       if ([pres.type isEqual: @"subscribe"]) {
+               XMPPPresence *answer;
+               answer = [XMPPPresence presenceWithType: @"subscribed"
+                                                    ID: pres.ID];
+               answer.to = [XMPPJID JIDWithString: [pres.from bareJID]];
+               [conn sendStanza: answer];
+       }
 }
 
 - (void)connectionWasClosed: (XMPPConnection*)conn
 {
-       of_log(@"Connection was closed!");
+       [of_stdout writeLine: @"Connection was closed!"];
 }
 @end