[Gd-chatter] r10790 - in trunk/libraries: koala/sources/examples/wiki registry/generic xml-parser xmpp xmpp-bot

hannes at gwydiondylan.org hannes at gwydiondylan.org
Thu Jun 8 02:27:38 CEST 2006


Author: hannes
Date: Thu Jun  8 02:27:35 2006
New Revision: 10790

Added:
   trunk/libraries/registry/generic/xmpp-bot   (contents, props changed)
   trunk/libraries/xmpp-bot/
   trunk/libraries/xmpp-bot/library.dylan   (contents, props changed)
   trunk/libraries/xmpp-bot/module.dylan   (contents, props changed)
   trunk/libraries/xmpp-bot/xmpp-bot.dylan   (contents, props changed)
   trunk/libraries/xmpp-bot/xmpp-bot.hdp   (contents, props changed)
Modified:
   trunk/libraries/koala/sources/examples/wiki/classes.dylan
   trunk/libraries/koala/sources/examples/wiki/library.dylan
   trunk/libraries/koala/sources/examples/wiki/wiki.dylan
   trunk/libraries/xml-parser/stream-parser.dylan
   trunk/libraries/xmpp/presence.dylan
Log:
Bug: 7219
*added support for a jabber bot reflecting wiki changes to online subscribers

Modified: trunk/libraries/koala/sources/examples/wiki/classes.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/wiki/classes.dylan	(original)
+++ trunk/libraries/koala/sources/examples/wiki/classes.dylan	Thu Jun  8 02:27:35 2006
@@ -42,6 +42,13 @@
   res;
 end;
 
+define method save (diff :: <wiki-page-diff>) => ()
+  next-method();
+  let text = concatenate(diff.wiki-page-content.page-title, " (http://wiki.opendylan.org/wiki/view.dsp?title=", diff.wiki-page-content.page-title, ")",
+                         " [version ", integer-to-string(diff.page-version), "] ",
+                         "was changed by ", diff.author, " comment was ", diff.comment);
+  broadcast-message(*xmpp-bot*, text);
+end;
 
 define method save-page (title, content, #key comment = "")
   let page = find-page(title);

Modified: trunk/libraries/koala/sources/examples/wiki/library.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/wiki/library.dylan	(original)
+++ trunk/libraries/koala/sources/examples/wiki/library.dylan	Thu Jun  8 02:27:35 2006
@@ -19,6 +19,7 @@
   use xml-parser;
   use collection-extensions, import: { sequence-diff };
   use string-extensions, import: { substring-search };
+  use xmpp-bot;
   //use meta;
   export wiki;
 end;
@@ -45,6 +46,7 @@
   use storage;
   use sequence-diff;
   use substring-search;
+  use xmpp-bot;
 end;
 
 

Modified: trunk/libraries/koala/sources/examples/wiki/wiki.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/wiki/wiki.dylan	(original)
+++ trunk/libraries/koala/sources/examples/wiki/wiki.dylan	Thu Jun  8 02:27:35 2006
@@ -594,6 +594,7 @@
     source: "wiki/admin.dsp")
 end;
 
+define variable *xmpp-bot* = #f;
 define function main
     () => ()
   let config-file =
@@ -602,6 +603,7 @@
     end;
   //register-url("/wiki/wiki.css", maybe-serve-static-file);
   dumper();
+  *xmpp-bot* := make(<xmpp-bot>, jid: "dylanbot at jabber.berlin.ccc.de/here", password: "fnord");
   start-server(config-file: config-file);
 end;
 

Added: trunk/libraries/registry/generic/xmpp-bot
==============================================================================
--- (empty file)
+++ trunk/libraries/registry/generic/xmpp-bot	Thu Jun  8 02:27:35 2006
@@ -0,0 +1 @@
+abstract://dylan/xmpp-bot/xmpp-bot.hdp

Modified: trunk/libraries/xml-parser/stream-parser.dylan
==============================================================================
--- trunk/libraries/xml-parser/stream-parser.dylan	(original)
+++ trunk/libraries/xml-parser/stream-parser.dylan	Thu Jun  8 02:27:35 2006
@@ -22,7 +22,7 @@
 define method monitor (parser :: <xml-stream-parser>, event :: one-of(#"start-element", #"end-element", #"characters"), handler :: <function>)
   parser.handlers[event] := handler;
 end method monitor;
-  
+
 define method parse (parser :: <xml-stream-parser>)
   while (~ stream-at-end?(parser.stream))
     let received = read-element(parser.stream);

Added: trunk/libraries/xmpp-bot/library.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/xmpp-bot/library.dylan	Thu Jun  8 02:27:35 2006
@@ -0,0 +1,14 @@
+Module:    dylan-user
+Author:    Hannes Mehnert
+Copyright: (C) 2006,  All rights reserved.
+
+define library xmpp-bot
+  use common-dylan;
+  use io;
+  use system;
+  use xmpp;
+  use xml-parser, import: { simple-xml };
+
+  // Add any more module exports here.
+  export xmpp-bot;
+end library xmpp-bot;

Added: trunk/libraries/xmpp-bot/module.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/xmpp-bot/module.dylan	Thu Jun  8 02:27:35 2006
@@ -0,0 +1,16 @@
+Module:    dylan-user
+Author:    Hannes Mehnert
+Copyright: (C) 2006,  All rights reserved.
+
+define module xmpp-bot
+  use common-dylan;
+  use threads;
+  use format;
+  use format-out;
+  use standard-io;
+  use xmpp;
+  use simple-xml;
+
+  // Add binding exports here.
+  export <xmpp-bot>, broadcast-message;
+end module xmpp-bot;

Added: trunk/libraries/xmpp-bot/xmpp-bot.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/xmpp-bot/xmpp-bot.dylan	Thu Jun  8 02:27:35 2006
@@ -0,0 +1,95 @@
+Module:    xmpp-bot
+Author:    Hannes Mehnert
+Copyright: (C) 2006,  All rights reserved.
+
+
+define variable *online-users* = make(<list>);
+
+define class <xmpp-bot> (<object>)
+  slot online-users :: <list> = make(<list>);
+  slot client :: <xmpp-client>, init-keyword: client:;
+  slot password :: <string>, required-init-keyword: password:;
+end;
+
+define method make (class == <xmpp-bot>,
+                    #next next-method,
+                    #rest rest,
+                    #key jid,
+                    #all-keys) => (xmpp-bot :: <xmpp-bot>)
+  let args = rest;
+  if (jid)
+    if (instance?(jid, <string>))
+      jid := as(<jid>, jid);
+    end;
+    let client = make(<xmpp-client>, jid: jid);
+    args := add!(args, #"client");
+    args := add!(args, client);
+  end;
+  apply(next-method, class, args);
+end;
+
+define method initialize (xmpp-bot :: <xmpp-bot>,
+                          #rest rest, #key, #all-keys)
+  let subscription-callback = make(<callback>, reference: #"default", priority: 3, handler: curry(auto-subscriber, xmpp-bot));
+  add-callback(xmpp-bot.client, <presence>, subscription-callback);
+  if (~ connect(xmpp-bot.client))
+    exit-application(1);
+  end if;
+  authenticate(xmpp-bot.client, xmpp-bot.password, #f);
+  send(xmpp-bot.client, make(<presence>, priority: 23));
+end;
+
+define method auto-subscriber (xmpp-bot, client, presence)
+  if (presence.type)
+    select (presence.type)
+      #"subscribe" => begin
+                        send(client, make(<presence>,
+                                          to: presence.from,
+                                          type: #"subscribed"));
+                        send(client, make(<presence>,
+                                          to: presence.from,
+                                          type: #"subscribe"));
+                        
+                      end;
+      #"unsubscribe" =>
+                        begin
+                          send(client, make(<presence>,
+                                            to: presence.from,
+                                            type: #"unsubscribed"));
+                          send(client, make(<presence>,
+                                            to: presence.from,
+                                            type: #"unavailable"));
+                          send(client, make(<presence>,
+                                            to: presence.from,
+                                            type: #"unsubscribe"));
+                          xmpp-bot.online-users := remove!(xmpp-bot.online-users,
+                                                           as(<string>, presence.from),
+                                                           test: subsequence-position);
+                        end;
+      #"unavailable" => begin
+                          format-out("%s went offline\n", as(<string>, presence.from));
+                          xmpp-bot.online-users := remove!(xmpp-bot.online-users,
+                                                           as(<string>, presence.from),
+                                                           test: \=);
+                        end;
+       otherwise => begin
+                      format-out("Didn't know what to do with type %=\n", presence.type);
+                    end;
+    end select;
+  else
+    unless (any?(method(a) a = as(<string>, presence.from) end, xmpp-bot.online-users))
+      xmpp-bot.online-users := add!(xmpp-bot.online-users, as(<string>, presence.from));
+    end;
+  end;
+end;
+
+define method broadcast-message (bot :: <xmpp-bot>, message :: <string>)
+  do(method (user)
+       send(bot.client,
+            make(<message>,
+                 type: #"chat",
+                 body: message,
+                 to: user));
+     end, bot.online-users);
+end;
+

Added: trunk/libraries/xmpp-bot/xmpp-bot.hdp
==============================================================================
--- (empty file)
+++ trunk/libraries/xmpp-bot/xmpp-bot.hdp	Thu Jun  8 02:27:35 2006
@@ -0,0 +1,13 @@
+Format-Version:   2
+Library:          xmpp-bot
+Author:           Hannes Mehnert
+Copyright:        (C) 2006,  All rights reserved.
+Major-Version:    1
+Minor-Version:    0
+Files:            library
+	module
+	xmpp-bot
+Start-Function:   main
+Compilation-Mode: tight
+Target-Type:      executable
+

Modified: trunk/libraries/xmpp/presence.dylan
==============================================================================
--- trunk/libraries/xmpp/presence.dylan	(original)
+++ trunk/libraries/xmpp/presence.dylan	Thu Jun  8 02:27:35 2006
@@ -39,7 +39,7 @@
 define method type (presence :: <presence>)
  => (res :: false-or(<symbol>));
   let type = next-method();
-  if (member?(as(<symbol>, type), $presence-types))
+  if (type & member?(as(<symbol>, type), $presence-types))
     as(<symbol>, type);
   else
     #f;



More information about the chatter mailing list