Changeset 330c55a for perl/modules/IRC/lib
- Timestamp:
- Feb 16, 2009, 4:38:22 PM (16 years ago)
- Branches:
- master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 10d67d5
- Parents:
- 52a0f14
- Location:
- perl/modules/IRC/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r56d0189 r330c55a 93 93 } 94 94 95 use constant OPTIONAL_CHANNEL => 1; 96 use constant REQUIRE_CHANNEL => 2; 97 95 98 sub register_commands { 96 99 BarnOwl::new_command('irc-connect' => \&cmd_connect, … … 106 109 "-n <nick> Use a non-default nick" 107 110 }); 108 BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect);109 BarnOwl::new_command('irc-msg' => \&cmd_msg);110 BarnOwl::new_command('irc-join' => \&cmd_join);111 BarnOwl::new_command('irc-part' => \&cmd_part);112 BarnOwl::new_command('irc-nick' => \&cmd_nick);113 BarnOwl::new_command('irc-names' => \&cmd_names);114 BarnOwl::new_command('irc-whois' => \&cmd_whois);115 BarnOwl::new_command('irc-motd' => \&cmd_motd);111 BarnOwl::new_command('irc-disconnect' => mk_irc_command(\&cmd_disconnect)); 112 BarnOwl::new_command('irc-msg' => mk_irc_command(\&cmd_msg, OPTIONAL_CHANNEL)); 113 BarnOwl::new_command('irc-join' => mk_irc_command(\&cmd_join)); 114 BarnOwl::new_command('irc-part' => mk_irc_command(\&cmd_part, REQUIRE_CHANNEL)); 115 BarnOwl::new_command('irc-nick' => mk_irc_command(\&cmd_nick)); 116 BarnOwl::new_command('irc-names' => mk_irc_command(\&cmd_names, REQUIRE_CHANNEL)); 117 BarnOwl::new_command('irc-whois' => mk_irc_command(\&cmd_whois)); 118 BarnOwl::new_command('irc-motd' => mk_irc_command(\&cmd_motd)); 116 119 BarnOwl::new_command('irc-list' => \&cmd_list); 117 BarnOwl::new_command('irc-who' => \&cmd_who);118 BarnOwl::new_command('irc-stats' => \&cmd_stats);119 BarnOwl::new_command('irc-topic' => \&cmd_topic);120 BarnOwl::new_command('irc-who' => mk_irc_command(\&cmd_who)); 121 BarnOwl::new_command('irc-stats' => mk_irc_command(\&cmd_stats)); 122 BarnOwl::new_command('irc-topic' => mk_irc_command(\&cmd_topic, REQUIRE_CHANNEL)); 120 123 } 121 124 … … 195 198 196 199 sub cmd_msg { 197 my $cmd = shift;198 my $conn = get_connection(\@_);199 my $to = shift or die("Usage: $cmd NICK\n");200 my $cmd = shift; 201 my $conn = shift; 202 my $to = shift || shift or die("Usage: $cmd NICK\n"); 200 203 # handle multiple recipients? 201 204 if(@_) { … … 236 239 sub cmd_join { 237 240 my $cmd = shift; 238 my $conn = get_connection(\@_);241 my $conn = shift; 239 242 my $chan = shift or die("Usage: $cmd channel\n"); 240 243 $channels{$chan} ||= []; … … 245 248 sub cmd_part { 246 249 my $cmd = shift; 247 my $conn = get_connection(\@_);248 my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n");250 my $conn = shift; 251 my $chan = shift; 249 252 $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}]; 250 253 $conn->conn->part($chan); … … 253 256 sub cmd_nick { 254 257 my $cmd = shift; 255 my $conn = get_connection(\@_);258 my $conn = shift; 256 259 my $nick = shift or die("Usage: $cmd <new nick>\n"); 257 260 $conn->conn->nick($nick); … … 260 263 sub cmd_names { 261 264 my $cmd = shift; 262 my $conn = get_connection(\@_);263 my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n");265 my $conn = shift; 266 my $chan = shift; 264 267 $conn->names_tmp([]); 265 268 $conn->conn->names($chan); … … 268 271 sub cmd_whois { 269 272 my $cmd = shift; 270 my $conn = get_connection(\@_);273 my $conn = shift; 271 274 my $who = shift || die("Usage: $cmd <user>\n"); 272 275 $conn->conn->whois($who); … … 275 278 sub cmd_motd { 276 279 my $cmd = shift; 277 my $conn = get_connection(\@_);280 my $conn = shift; 278 281 $conn->conn->motd; 279 282 } … … 290 293 sub cmd_who { 291 294 my $cmd = shift; 292 my $conn = get_connection(\@_);295 my $conn = shift; 293 296 my $who = shift || die("Usage: $cmd <user>\n"); 297 BarnOwl::error("WHO $cmd $conn $who"); 294 298 $conn->conn->who($who); 295 299 } … … 297 301 sub cmd_stats { 298 302 my $cmd = shift; 299 my $conn = get_connection(\@_);303 my $conn = shift; 300 304 my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n"); 301 305 $conn->conn->stats($type, @_); … … 304 308 sub cmd_topic { 305 309 my $cmd = shift; 306 my $conn = get_connection(\@_); 307 $conn->conn->topic(@_); 310 my $conn = shift; 311 my $chan = shift; 312 $conn->conn->topic($chan, @_ ? join(" ", @_) : undef); 308 313 } 309 314 … … 312 317 ################################################################################ 313 318 314 sub get_connection { 315 my $args = shift; 316 if(scalar @$args >= 2 && $args->[0] eq '-a') { 317 shift @$args; 318 return get_connection_by_alias(shift @$args); 319 } 320 my $channel = $args->[-1]; 321 if (defined($channel) && $channel =~ /^#/ 322 and $channels{$channel} and @{$channels{$channel}} == 1) { 323 return $channels{$channel}[0]; 324 } 325 my $m = BarnOwl::getcurmsg(); 326 if($m && $m->type eq 'IRC') { 327 return get_connection_by_alias($m->network); 328 } 329 if(scalar keys %ircnets == 1) { 330 return [values(%ircnets)]->[0]; 331 } 332 die("You must specify a network with -a\n"); 333 } 334 335 sub get_channel { 336 my $args = shift; 337 if(scalar @$args) { 338 return shift @$args; 339 } 340 my $m = BarnOwl::getcurmsg(); 341 if($m && $m->type eq 'IRC') { 342 return $m->channel if !$m->is_private; 343 } 344 return undef; 319 sub mk_irc_command { 320 my $sub = shift; 321 my $use_channel = shift || 0; 322 return sub { 323 my $cmd = shift; 324 my $conn; 325 my $alias; 326 my $channel; 327 my $getopt = Getopt::Long::Parser->new; 328 my $m = BarnOwl::getcurmsg(); 329 330 local @ARGV = @_; 331 $getopt->configure(qw(pass_through permute no_getopt_compat prefix_pattern=-|--)); 332 $getopt->getoptions("alias=s" => \$alias); 333 334 if(defined($alias)) { 335 $conn = get_connection_by_alias($alias); 336 } 337 if(!$conn && $use_channel) { 338 $channel = $ARGV[-1]; 339 if(defined($channel) && $channel =~ /^#/) { 340 if($channels{$channel} && @{$channels{$channel}} == 1) { 341 pop @ARGV; 342 $conn = $channels{$channel}[0]; 343 } 344 } else { 345 if($m && $m->type eq 'IRC' && !$m->is_private) { 346 $channel = $m->channel; 347 } else { 348 undef $channel; 349 } 350 } 351 } 352 if(!$channel && $use_channel == REQUIRE_CHANNEL) { 353 die("Usage: $cmd <channel>\n"); 354 } 355 if(!$conn) { 356 if($m && $m->type eq 'IRC') { 357 $conn = get_connection_by_alias($m->network); 358 } 359 } 360 if(!$conn && scalar keys %ircnets == 1) { 361 $conn = [values(%ircnets)]->[0]; 362 } 363 if(!$conn) { 364 die("You must specify an IRC network using -a.\n"); 365 } 366 if($use_channel) { 367 $sub->($cmd, $conn, $channel, @ARGV); 368 } else { 369 $sub->($cmd, $conn, @ARGV); 370 } 371 }; 345 372 } 346 373 -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r3048f1f r330c55a 74 74 $self->conn->add_handler(endofwhois=> sub { shift; $self->on_endofwhois(@_) }); 75 75 76 # * nosuchchannel 77 # * 78 76 79 return $self; 77 80 }
Note: See TracChangeset
for help on using the changeset viewer.