[1135] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r1086 - in branches/barnowl_perlaim/owl: . perl/modules/AIM/lib/BarnOwl/Module

daemon@ATHENA.MIT.EDU (geofft@MIT.EDU)
Thu Oct 29 18:13:22 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
Date: Fri, 4 Jul 2008 23:30:19 -0400 (EDT)
To: dirty-owl-hackers@mit.edu
From: geofft@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU

Author: geofft
Date: 2008-07-04 23:30:19 -0400 (Fri, 04 Jul 2008)
New Revision: 1086

Modified:
   branches/barnowl_perlaim/owl/Makefile.in
   branches/barnowl_perlaim/owl/perl/modules/AIM/lib/BarnOwl/Module/AIM.pm
Log:
Supports outgoing messages. I think this all works, but I got rate-limited near
the end so I can't promise anything.



Modified: branches/barnowl_perlaim/owl/Makefile.in
===================================================================
--- branches/barnowl_perlaim/owl/Makefile.in	2008-06-24 02:57:18 UTC (rev 1085)
+++ branches/barnowl_perlaim/owl/Makefile.in	2008-07-05 03:30:19 UTC (rev 1086)
@@ -77,7 +77,7 @@
 modules: $(MODULE_DIRS)
 modules_clean:
 	for i in $(MODULE_DIRS); do \
-		cd $$i; test ! -f Makefile || make clean; \
+		(cd $$i && test ! -f Makefile || make clean) \
 	done
 
 $(MODULE_DIRS): %: %/Makefile

Modified: branches/barnowl_perlaim/owl/perl/modules/AIM/lib/BarnOwl/Module/AIM.pm
===================================================================
--- branches/barnowl_perlaim/owl/perl/modules/AIM/lib/BarnOwl/Module/AIM.pm	2008-06-24 02:57:18 UTC (rev 1085)
+++ branches/barnowl_perlaim/owl/perl/modules/AIM/lib/BarnOwl/Module/AIM.pm	2008-07-05 03:30:19 UTC (rev 1086)
@@ -21,9 +21,16 @@
     my ($oscar, $sender, $message, $is_away) = @_;
     my $msg = BarnOwl::Message->new(
             type => 'AIM',
+            direction => 'in',
             sender => $sender,
-            body => $message,
+            origbody => $message,
             away => $is_away,
+            body => zformat($message, $is_away),
+            recipient => get_screenname($oscar),
+            replycmd =>
+                "aimwrite -a '" . get_screenname($oscar) . "' $sender",
+            replysendercmd =>
+                "aimwrite -a '" . get_screenname($oscar) . "' $sender",
             );
     BarnOwl::queue_message($msg);
 }
@@ -45,6 +52,10 @@
         my $oscar = Net::OSCAR->new();
         my ($user, $pass) = ('...', '...');
         $oscar->set_callback_im_in(\&on_im_in);
+        $oscar->set_callback_signon_done(sub ($) {
+                BarnOwl::admin_message('AIM',
+                    'Logged in to AIM as ' . shift->screenname);
+        });
         $oscar->signon(
                 screenname => $user,
                 password => $pass
@@ -52,15 +63,73 @@
         push @oscars, $oscar;
     }
 }
+
+sub cmd_aimwrite {
+    my ($cmd, $recipient) = @_;
+    BarnOwl::start_edit_win(join(' ', @_), sub {
+            my ($body) = @_;
+            my $oscar = get_oscar();
+            my $sender = get_screenname($oscar);
+            $oscar->send_im($recipient, $body);
+            BarnOwl::queue_message(BarnOwl::Message->new(
+                    type => 'AIM',
+                    direction => 'in',
+                    sender => $sender,
+                    origbody => $body,
+                    away => 0,
+                    body => zformat($body, 0),
+                    recipient => $recipient,
+                    replycmd =>
+                        "aimwrite -a '" . get_screenname($oscar) . "' $sender",
+                    replysendercmd =>
+                        "aimwrite -a '" . get_screenname($oscar) . "' $sender",
+            ));
+    });
+}
+
 BarnOwl::new_command(aimlogin => \&cmd_aimlogin, {});
+BarnOwl::new_command(aimwrite => \&cmd_aimwrite, {});
 
-sub main_loop {
+sub main_loop() {
     for my $oscar (@oscars) {
         $oscar->do_one_loop();
     }
 }
 $BarnOwl::Hooks::mainLoop->add(\&main_loop);
 
+### helpers ###
+
+sub zformat($$) {
+    # TODO subclass HTML::Parser
+    my ($message, $is_away) = @_;
+    if ($is_away) {
+        return BarnOwl::boldify('[away]') . " $message";
+    } else {
+        return $message;
+    }
+}
+
+sub get_oscar() {
+    if (scalar @oscars == 0) {
+        die "You are not logged in to AIM."
+    } elsif (scalar @oscars == 1) {
+        return $oscars[0];
+    } else {
+        my $m = BarnOwl::getcurmsg();
+        if ($m && $m->type eq 'AIM') {
+            for my $oscar (@oscars) {
+                return $oscar if ($oscar->screenname eq $m->recipient);
+            }
+        }
+    }
+    die('You must specify an account with -a');
+}
+
+sub get_screenname($) {
+# TODO qualify realm
+    return shift->screenname;
+}
+
 1;
 
 # vim: set sw=4 et cin:


home help back first fref pref prev next nref lref last post