1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::Module::Jabber; |
---|
5 | |
---|
6 | =head1 NAME |
---|
7 | |
---|
8 | BarnOwl::Module::Jabber |
---|
9 | |
---|
10 | =head1 DESCRIPTION |
---|
11 | |
---|
12 | This module implements Jabber support for BarnOwl. |
---|
13 | |
---|
14 | =cut |
---|
15 | |
---|
16 | use BarnOwl; |
---|
17 | use BarnOwl::Hooks; |
---|
18 | |
---|
19 | use utf8; |
---|
20 | |
---|
21 | our $VERSION = 0.1; |
---|
22 | |
---|
23 | our $impl_loaded; |
---|
24 | $impl_loaded = 0 unless defined($impl_loaded); |
---|
25 | |
---|
26 | sub _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 | |
---|
35 | sub 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 | |
---|
78 | sub _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 | |
---|
87 | sub 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 initalize 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 | |
---|
180 | sub register_keybindings { |
---|
181 | BarnOwl::bindkey(qw(recv j command start-command), 'jwrite '); |
---|
182 | } |
---|
183 | |
---|
184 | sub register_filters { |
---|
185 | BarnOwl::filter(qw(jabber type ^jabber$)); |
---|
186 | } |
---|
187 | |
---|
188 | sub onGetQuickstart { |
---|
189 | return <<'EOF' |
---|
190 | @b(Jabber:) |
---|
191 | Type ':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 |
---|
193 | them. Once you get a message saying you are subscribed, you can message |
---|
194 | them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'. |
---|
195 | EOF |
---|
196 | } |
---|
197 | |
---|
198 | 1; |
---|