[Gd-chatter] r11100 - in trunk/libraries/network: koala/sources/examples/buddha xmpp xmpp-bot

hannes at gwydiondylan.org hannes at gwydiondylan.org
Fri Dec 22 04:36:58 CET 2006


Author: hannes
Date: Fri Dec 22 04:36:55 2006
New Revision: 11100

Modified:
   trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan
   trunk/libraries/network/xmpp-bot/module.dylan
   trunk/libraries/network/xmpp-bot/xmpp-bot.dylan
   trunk/libraries/network/xmpp/client.dylan
Log:
Bug: 7257
xmpp: some exception handlers
xmpp-bot: export more stuff, unicast, ping
buddha: list online users, send every 30s a ping

Modified: trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan	(original)
+++ trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan	Fri Dec 22 04:36:55 2006
@@ -98,6 +98,7 @@
 define page add end;
 define page admin end;
 
+define page online-users end;
 define page ipv4-network-detail end;
 define page ipv6-network-detail end;
 define page ipv4-subnet-detail end;
@@ -155,7 +156,8 @@
           li { a("Hosts", href => "/host") },
           li { a("Networks", href => "/network") },
           li { a("Subnets", href => "/subnet") },
-          li { a("Changes", href => "/changes") }
+          li { a("Changes", href => "/changes") },
+          li { a("Online Users", href => "/online-users") }
         }
       },
       div (id => "buddha-edit") {
@@ -209,6 +211,20 @@
          end; }
 end;
 
+define method respond-to-get (page == #"online-users",
+                              request :: <request>,
+                              response :: <response>,
+                              #key errors)
+  let out = output-stream(response);
+  with-buddha-template(out, "Online Users")
+    collect(with-xml()
+              div(id => "content") {
+                h2("Online Jabber users"),
+                ul { do(map(method(x) with-xml() li(x) end end,
+                            *xmpp-bot*.online-users)) } }
+              end);
+  end;
+end;
 define method respond-to-get (page == #"admin",
                               request :: <request>,
                               response :: <response>,
@@ -1171,7 +1187,8 @@
       unless (*xmpp-bot*)
         *xmpp-bot* := make(<xmpp-bot>, jid: "buddha at jabber.berlin.ccc.de/serva", password: "fnord");
       end;
-      sleep(23345);
+      ping(*xmpp-bot*);
+      sleep(30);
     exception (e :: <condition>)
       *xmpp-bot* := #f
     end;

Modified: trunk/libraries/network/xmpp-bot/module.dylan
==============================================================================
--- trunk/libraries/network/xmpp-bot/module.dylan	(original)
+++ trunk/libraries/network/xmpp-bot/module.dylan	Fri Dec 22 04:36:55 2006
@@ -13,5 +13,5 @@
   use xml-parser;
 
   // Add binding exports here.
-  export <xmpp-bot>, broadcast-message;
+  export <xmpp-bot>, broadcast-message, unicast-message, ping, online-users;
 end module xmpp-bot;

Modified: trunk/libraries/network/xmpp-bot/xmpp-bot.dylan
==============================================================================
--- trunk/libraries/network/xmpp-bot/xmpp-bot.dylan	(original)
+++ trunk/libraries/network/xmpp-bot/xmpp-bot.dylan	Fri Dec 22 04:36:55 2006
@@ -43,8 +43,16 @@
 end;
 
 define method broadcaster (xmpp-bot, client, message)
-  if (message.body & ~(subsequence-position(as(<string>, message.body), "?OTR")))
-    broadcast-message(xmpp-bot, concatenate(as(<string>, message.from), " wrote: ", as(<string>, message.body)));
+  block()
+    if (message.body & ~(subsequence-position(as(<string>, message.body), "?OTR")))
+      let old-msg = choose(method(x) name-with-proper-capitalization(x) = "body" end, message.node-children)[0];
+      let new-foo = make(<char-string>, text: concatenate(as(<string>, message.from), " wrote: "));
+      old-msg.node-children := reverse(add(old-msg.node-children, new-foo));
+      broadcast-message(xmpp-bot, old-msg);
+    end;
+  exception (e :: <condition>)
+    format-out("received exception %=\n", e);
+    //ignore me!
   end;
 end;
 define method auto-subscriber (xmpp-bot, client, presence)
@@ -101,3 +109,17 @@
      end, bot.online-users);
 end;
 
+define method unicast-message (bot :: <xmpp-bot>, message :: <string>, username :: <string>)
+  send(bot.client,
+       make(<message>,
+            type: #"chat",
+            body: message,
+            to: username));
+end;
+
+define method ping (bot :: <xmpp-bot>)
+  send(bot.client,
+       make(<message>,
+            type: #"chat",
+            to: "me"))
+end;

Modified: trunk/libraries/network/xmpp/client.dylan
==============================================================================
--- trunk/libraries/network/xmpp/client.dylan	(original)
+++ trunk/libraries/network/xmpp/client.dylan	Fri Dec 22 04:36:55 2006
@@ -87,7 +87,11 @@
     end if;
   end);
 
-  parse(parser);
+  block()
+    parse(parser);
+  exception (e :: <condition>)
+   //just catch all errors and ignore them
+  end;
 end method listen;
 
 define method disconnect (client :: <xmpp-client>)



More information about the chatter mailing list