Changeset d474ee9 for perl/modules/Jabber
- Timestamp:
- Mar 13, 2012, 1:55:24 PM (12 years ago)
- 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)
- Location:
- perl/modules/Jabber/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
r3e34a69 rd474ee9 14 14 =cut 15 15 16 use BarnOwl; 17 use BarnOwl::Hooks; 16 18 use BarnOwl::Module::Jabber::Impl; 17 19 … … 20 22 our $VERSION = 0.1; 21 23 24 sub 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 63 sub _make_stub { 64 my $func = shift; 65 return sub { 66 no strict 'refs'; 67 &{"BarnOwl::Module::Jabber::Impl::$func"}; 68 } 69 } 70 71 sub 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 164 sub register_keybindings { 165 BarnOwl::bindkey(qw(recv j command start-command), 'jwrite '); 166 } 167 168 sub register_filters { 169 BarnOwl::filter(qw(jabber type ^jabber$)); 170 } 171 172 sub onGetQuickstart { 173 return <<'EOF' 174 @b(Jabber:) 175 Type ':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 177 them. Once you get a message saying you are subscribed, you can message 178 them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'. 179 EOF 180 } 181 22 182 1; -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Impl.pm
r3e34a69 rd474ee9 65 65 our %completion_jids; 66 66 67 # Called by BarnOwl::Module::Jabber. 67 68 sub onStart { 68 if ( *BarnOwl::queue_message{CODE} ) { 69 register_owl_commands(); 70 register_keybindings(); 71 register_filters(); 72 $BarnOwl::Hooks::getBuddyList->add("BarnOwl::Module::Jabber::Impl::onGetBuddyList"); 73 $BarnOwl::Hooks::getQuickstart->add("BarnOwl::Module::Jabber::Impl::onGetQuickstart"); 74 $vars{show} = ''; 75 BarnOwl::new_variable_bool("jabber:show_offline_buddies", 76 { default => 1, 77 summary => 'Show offline or pending buddies.'}); 78 BarnOwl::new_variable_bool("jabber:show_logins", 79 { default => 0, 80 summary => 'Show login/logout messages.'}); 81 BarnOwl::new_variable_bool("jabber:spew", 82 { default => 0, 83 summary => 'Display unrecognized Jabber messages.'}); 84 BarnOwl::new_variable_int("jabber:auto_away_timeout", 85 { default => 5, 86 summary => 'After minutes idle, auto away.', 87 }); 88 BarnOwl::new_variable_int("jabber:auto_xa_timeout", 89 { default => 15, 90 summary => 'After minutes idle, auto extended away.' 91 }); 92 BarnOwl::new_variable_bool("jabber:reconnect", 93 { default => 1, 94 summary => 'Auto-reconnect when disconnected from servers.' 95 }); 96 # Force these. Reload can screw them up. 97 # Taken from Net::Jabber::Protocol. 98 $Net::XMPP::Protocol::NEWOBJECT{'iq'} = "Net::Jabber::IQ"; 99 $Net::XMPP::Protocol::NEWOBJECT{'message'} = "Net::Jabber::Message"; 100 $Net::XMPP::Protocol::NEWOBJECT{'presence'} = "Net::Jabber::Presence"; 101 $Net::XMPP::Protocol::NEWOBJECT{'jid'} = "Net::Jabber::JID"; 102 } else { 103 # Our owl doesn't support queue_message. Unfortunately, this 104 # means it probably *also* doesn't support BarnOwl::error. So just 105 # give up silently. 106 } 107 } 108 109 $BarnOwl::Hooks::startup->add("BarnOwl::Module::Jabber::Impl::onStart"); 69 $BarnOwl::Hooks::getBuddyList->add("BarnOwl::Module::Jabber::Impl::onGetBuddyList"); 70 71 $vars{show} = ''; 72 73 # Force these. Reload can screw them up. 74 # Taken from Net::Jabber::Protocol. 75 $Net::XMPP::Protocol::NEWOBJECT{'iq'} = "Net::Jabber::IQ"; 76 $Net::XMPP::Protocol::NEWOBJECT{'message'} = "Net::Jabber::Message"; 77 $Net::XMPP::Protocol::NEWOBJECT{'presence'} = "Net::Jabber::Presence"; 78 $Net::XMPP::Protocol::NEWOBJECT{'jid'} = "Net::Jabber::JID"; 79 } 110 80 111 81 sub do_keep_alive_and_auto_away { … … 253 223 } 254 224 255 sub onGetQuickstart {256 return <<'EOF'257 @b(Jabber:)258 Type ':jabberlogin @b(username@mit.edu)' to log in to Jabber. The command259 ':jroster sub @b(somebody@gmail.com)' will request that they let you message260 them. Once you get a message saying you are subscribed, you can message261 them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'.262 EOF263 }264 265 225 ################################################################################ 266 226 ### Owl Commands 267 sub register_owl_commands() {268 BarnOwl::new_command(269 jabberlogin => \&cmd_login,270 {271 summary => "Log in to Jabber",272 usage => "jabberlogin <jid> [<password>]"273 }274 );275 BarnOwl::new_command(276 jabberlogout => \&cmd_logout,277 {278 summary => "Log out of Jabber",279 usage => "jabberlogout [-A|<jid>]",280 description => "jabberlogout logs you out of Jabber.\n\n"281 . "If you are connected to one account, no further arguments are necessary.\n\n"282 . "-A Log out of all accounts.\n"283 . "<jid> Which account to log out of.\n"284 }285 );286 BarnOwl::new_command(287 jwrite => \&cmd_jwrite,288 {289 summary => "Send a Jabber Message",290 usage => "jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>] [-m <message>]"291 }292 );293 BarnOwl::new_command(294 jaway => \&cmd_jaway,295 {296 summary => "Set Jabber away / presence information",297 usage => "jaway [-s online|dnd|...] [<message>]"298 }299 );300 BarnOwl::new_command(301 jlist => \&cmd_jlist,302 {303 summary => "Show your Jabber roster.",304 usage => "jlist"305 }306 );307 BarnOwl::new_command(308 jmuc => \&cmd_jmuc,309 {310 summary => "Jabber MUC related commands.",311 description => "jmuc sends Jabber commands related to MUC.\n\n"312 . "The following commands are available\n\n"313 . "join <muc>[/<nick>]\n"314 . " Join a MUC (with a given nickname, or otherwise your JID).\n\n"315 . "part <muc> Part a MUC.\n"316 . " The MUC is taken from the current message if not supplied.\n\n"317 . "invite <jid> [<muc>]\n"318 . " Invite <jid> to <muc>.\n"319 . " The MUC is taken from the current message if not supplied.\n\n"320 . "configure [<muc>]\n"321 . " Configures a MUC.\n"322 . " Necessary to initalize a new MUC.\n"323 . " At present, only the default configuration is supported.\n"324 . " The MUC is taken from the current message if not supplied.\n\n"325 . "presence [<muc>]\n"326 . " Shows the roster for <muc>.\n"327 . " The MUC is taken from the current message if not supplied.\n\n"328 . "presence -a\n"329 . " Shows rosters for all MUCs you're participating in.\n\n",330 usage => "jmuc <command> [<args>]"331 }332 );333 BarnOwl::new_command(334 jroster => \&cmd_jroster,335 {336 summary => "Jabber roster related commands.",337 description => "jroster sends Jabber commands related to rosters.\n\n"338 . "The following commands are available\n\n"339 . "sub <jid> Subscribe to <jid>'s presence. (implicit add)\n\n"340 . "add <jid> Adds <jid> to your roster.\n\n"341 . "unsub <jid> Unsubscribe from <jid>'s presence.\n\n"342 . "remove <jid> Removes <jid> from your roster. (implicit unsub)\n\n"343 . "auth <jid> Authorizes <jid> to subscribe to your presence.\n\n"344 . "deauth <jid> De-authorizes <jid>'s subscription to your presence.\n\n"345 . "The following arguments are supported for all commands\n\n"346 . "-a <jid> Specify which account to make the roster changes on.\n"347 . " Required if you're signed into more than one account.\n\n"348 . "The following arguments only work with the add and sub commands.\n\n"349 . "-g <group> Add <jid> to group <group>.\n"350 . " May be specified more than once, will not remove <jid> from any groups.\n\n"351 . "-p Purge. Removes <jid> from all groups.\n"352 . " May be combined with -g.\n\n"353 . "-n <name> Sets <name> as <jid>'s short name.\n\n"354 . "Note: Unless -n is used, you can specify multiple <jid> arguments.\n",355 usage => "jroster <command> <args>"356 }357 );358 }359 360 sub register_keybindings {361 BarnOwl::bindkey(qw(recv j command start-command), 'jwrite ');362 }363 364 sub register_filters {365 BarnOwl::filter(qw(jabber type ^jabber$));366 }367 227 368 228 sub cmd_login {
Note: See TracChangeset
for help on using the changeset viewer.