source: perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm @ 5832433

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