Ignore:
Timestamp:
Mar 13, 2012, 1:55:24 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
f421190
Parents:
3e34a69
git-author:
David Benjamin <davidben@mit.edu> (03/13/12 13:52:23)
git-committer:
David Benjamin <davidben@mit.edu> (03/13/12 13:55:24)
Message:
Move command registration back to the entry point

Impl is still loaded at startup, but we're almost there.
File:
1 edited

Legend:

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

    r3e34a69 rd474ee9  
    1414=cut
    1515
     16use BarnOwl;
     17use BarnOwl::Hooks;
    1618use BarnOwl::Module::Jabber::Impl;
    1719
     
    2022our $VERSION = 0.1;
    2123
     24sub onStart {
     25    if ( *BarnOwl::queue_message{CODE} ) {
     26        register_owl_commands();
     27        register_keybindings();
     28        register_filters();
     29        $BarnOwl::Hooks::getQuickstart->add("BarnOwl::Module::Jabber::onGetQuickstart");
     30
     31        BarnOwl::new_variable_bool("jabber:show_offline_buddies",
     32                                   { default => 1,
     33                                     summary => 'Show offline or pending buddies.'});
     34        BarnOwl::new_variable_bool("jabber:show_logins",
     35                                   { default => 0,
     36                                     summary => 'Show login/logout messages.'});
     37        BarnOwl::new_variable_bool("jabber:spew",
     38                                   { default => 0,
     39                                     summary => 'Display unrecognized Jabber messages.'});
     40        BarnOwl::new_variable_int("jabber:auto_away_timeout",
     41                                  { default => 5,
     42                                    summary => 'After minutes idle, auto away.',
     43                                  });
     44        BarnOwl::new_variable_int("jabber:auto_xa_timeout",
     45                                  { default => 15,
     46                                    summary => 'After minutes idle, auto extended away.'
     47                                });
     48        BarnOwl::new_variable_bool("jabber:reconnect",
     49                                  { default => 1,
     50                                    summary => 'Auto-reconnect when disconnected from servers.'
     51                                });
     52
     53        BarnOwl::Module::Jabber::Impl::onStart();
     54    } else {
     55        # Our owl doesn't support queue_message. Unfortunately, this
     56        # means it probably *also* doesn't support BarnOwl::error. So just
     57        # give up silently.
     58    }
     59}
     60
     61$BarnOwl::Hooks::startup->add("BarnOwl::Module::Jabber::onStart");
     62
     63sub _make_stub {
     64    my $func = shift;
     65    return sub {
     66        no strict 'refs';
     67        &{"BarnOwl::Module::Jabber::Impl::$func"};
     68    }
     69}
     70
     71sub register_owl_commands() {
     72    BarnOwl::new_command(
     73        jabberlogin => _make_stub("cmd_login"),
     74        {
     75            summary => "Log in to Jabber",
     76            usage   => "jabberlogin <jid> [<password>]"
     77        }
     78    );
     79    BarnOwl::new_command(
     80        jabberlogout => _make_stub("cmd_logout"),
     81        {
     82            summary => "Log out of Jabber",
     83            usage   => "jabberlogout [-A|<jid>]",
     84            description => "jabberlogout logs you out of Jabber.\n\n"
     85              . "If you are connected to one account, no further arguments are necessary.\n\n"
     86              . "-A            Log out of all accounts.\n"
     87              . "<jid>         Which account to log out of.\n"
     88        }
     89    );
     90    BarnOwl::new_command(
     91        jwrite => _make_stub("cmd_jwrite"),
     92        {
     93            summary => "Send a Jabber Message",
     94            usage   => "jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>] [-m <message>]"
     95        }
     96    );
     97    BarnOwl::new_command(
     98        jaway => _make_stub("cmd_jaway"),
     99        {
     100            summary => "Set Jabber away / presence information",
     101            usage   => "jaway [-s online|dnd|...] [<message>]"
     102        }
     103    );
     104    BarnOwl::new_command(
     105        jlist => _make_stub("cmd_jlist"),
     106        {
     107            summary => "Show your Jabber roster.",
     108            usage   => "jlist"
     109        }
     110    );
     111    BarnOwl::new_command(
     112        jmuc => _make_stub("cmd_jmuc"),
     113        {
     114            summary     => "Jabber MUC related commands.",
     115            description => "jmuc sends Jabber commands related to MUC.\n\n"
     116              . "The following commands are available\n\n"
     117              . "join <muc>[/<nick>]\n"
     118              . "            Join a MUC (with a given nickname, or otherwise your JID).\n\n"
     119              . "part <muc>  Part a MUC.\n"
     120              . "            The MUC is taken from the current message if not supplied.\n\n"
     121              . "invite <jid> [<muc>]\n"
     122              . "            Invite <jid> to <muc>.\n"
     123              . "            The MUC is taken from the current message if not supplied.\n\n"
     124              . "configure [<muc>]\n"
     125              . "            Configures a MUC.\n"
     126              . "            Necessary to initalize a new MUC.\n"
     127              . "            At present, only the default configuration is supported.\n"
     128              . "            The MUC is taken from the current message if not supplied.\n\n"
     129              . "presence [<muc>]\n"
     130              . "            Shows the roster for <muc>.\n"
     131              . "            The MUC is taken from the current message if not supplied.\n\n"
     132              . "presence -a\n"
     133              . "            Shows rosters for all MUCs you're participating in.\n\n",
     134            usage => "jmuc <command> [<args>]"
     135        }
     136    );
     137    BarnOwl::new_command(
     138        jroster => _make_stub("cmd_jroster"),
     139        {
     140            summary     => "Jabber roster related commands.",
     141            description => "jroster sends Jabber commands related to rosters.\n\n"
     142              . "The following commands are available\n\n"
     143              . "sub <jid>     Subscribe to <jid>'s presence. (implicit add)\n\n"
     144              . "add <jid>     Adds <jid> to your roster.\n\n"
     145              . "unsub <jid>   Unsubscribe from <jid>'s presence.\n\n"
     146              . "remove <jid>  Removes <jid> from your roster. (implicit unsub)\n\n"
     147              . "auth <jid>    Authorizes <jid> to subscribe to your presence.\n\n"
     148              . "deauth <jid>  De-authorizes <jid>'s subscription to your presence.\n\n"
     149              . "The following arguments are supported for all commands\n\n"
     150              . "-a <jid>      Specify which account to make the roster changes on.\n"
     151              . "              Required if you're signed into more than one account.\n\n"
     152              . "The following arguments only work with the add and sub commands.\n\n"
     153              . "-g <group>    Add <jid> to group <group>.\n"
     154              . "              May be specified more than once, will not remove <jid> from any groups.\n\n"
     155              . "-p            Purge. Removes <jid> from all groups.\n"
     156              . "              May be combined with -g.\n\n"
     157              . "-n <name>     Sets <name> as <jid>'s short name.\n\n"
     158              . "Note: Unless -n is used, you can specify multiple <jid> arguments.\n",
     159            usage       => "jroster <command> <args>"
     160        }
     161    );
     162}
     163
     164sub register_keybindings {
     165    BarnOwl::bindkey(qw(recv j command start-command), 'jwrite ');
     166}
     167
     168sub register_filters {
     169    BarnOwl::filter(qw(jabber type ^jabber$));
     170}
     171
     172sub onGetQuickstart {
     173    return <<'EOF'
     174@b(Jabber:)
     175Type ':jabberlogin @b(username@mit.edu)' to log in to Jabber. The command
     176':jroster sub @b(somebody@gmail.com)' will request that they let you message
     177them. Once you get a message saying you are subscribed, you can message
     178them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'.
     179EOF
     180}
     181
    221821;
Note: See TracChangeset for help on using the changeset viewer.