Ignore:
Timestamp:
Jul 4, 2008, 11:30:19 PM (16 years ago)
Author:
Geoffrey Thomas <geofft@mit.edu>
Branches:
barnowl_perlaim
Children:
3dcccba
Parents:
403198c
Message:
Supports outgoing messages. I think this all works, but I got rate-limited near
the end so I can't promise anything.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/AIM/lib/BarnOwl/Module/AIM.pm

    r403198c r7d63a6c  
    2222    my $msg = BarnOwl::Message->new(
    2323            type => 'AIM',
     24            direction => 'in',
    2425            sender => $sender,
    25             body => $message,
     26            origbody => $message,
    2627            away => $is_away,
     28            body => zformat($message, $is_away),
     29            recipient => get_screenname($oscar),
     30            replycmd =>
     31                "aimwrite -a '" . get_screenname($oscar) . "' $sender",
     32            replysendercmd =>
     33                "aimwrite -a '" . get_screenname($oscar) . "' $sender",
    2734            );
    2835    BarnOwl::queue_message($msg);
     
    4653        my ($user, $pass) = ('...', '...');
    4754        $oscar->set_callback_im_in(\&on_im_in);
     55        $oscar->set_callback_signon_done(sub ($) {
     56                BarnOwl::admin_message('AIM',
     57                    'Logged in to AIM as ' . shift->screenname);
     58        });
    4859        $oscar->signon(
    4960                screenname => $user,
     
    5364    }
    5465}
     66
     67sub cmd_aimwrite {
     68    my ($cmd, $recipient) = @_;
     69    BarnOwl::start_edit_win(join(' ', @_), sub {
     70            my ($body) = @_;
     71            my $oscar = get_oscar();
     72            my $sender = get_screenname($oscar);
     73            $oscar->send_im($recipient, $body);
     74            BarnOwl::queue_message(BarnOwl::Message->new(
     75                    type => 'AIM',
     76                    direction => 'in',
     77                    sender => $sender,
     78                    origbody => $body,
     79                    away => 0,
     80                    body => zformat($body, 0),
     81                    recipient => $recipient,
     82                    replycmd =>
     83                        "aimwrite -a '" . get_screenname($oscar) . "' $sender",
     84                    replysendercmd =>
     85                        "aimwrite -a '" . get_screenname($oscar) . "' $sender",
     86            ));
     87    });
     88}
     89
    5590BarnOwl::new_command(aimlogin => \&cmd_aimlogin, {});
     91BarnOwl::new_command(aimwrite => \&cmd_aimwrite, {});
    5692
    57 sub main_loop {
     93sub main_loop() {
    5894    for my $oscar (@oscars) {
    5995        $oscar->do_one_loop();
     
    6298$BarnOwl::Hooks::mainLoop->add(\&main_loop);
    6399
     100### helpers ###
     101
     102sub zformat($$) {
     103    # TODO subclass HTML::Parser
     104    my ($message, $is_away) = @_;
     105    if ($is_away) {
     106        return BarnOwl::boldify('[away]') . " $message";
     107    } else {
     108        return $message;
     109    }
     110}
     111
     112sub get_oscar() {
     113    if (scalar @oscars == 0) {
     114        die "You are not logged in to AIM."
     115    } elsif (scalar @oscars == 1) {
     116        return $oscars[0];
     117    } else {
     118        my $m = BarnOwl::getcurmsg();
     119        if ($m && $m->type eq 'AIM') {
     120            for my $oscar (@oscars) {
     121                return $oscar if ($oscar->screenname eq $m->recipient);
     122            }
     123        }
     124    }
     125    die('You must specify an account with -a');
     126}
     127
     128sub get_screenname($) {
     129# TODO qualify realm
     130    return shift->screenname;
     131}
     132
    641331;
    65134
Note: See TracChangeset for help on using the changeset viewer.