Changeset 54b4a87 for perl/modules/IRC/lib/BarnOwl/Module
- Timestamp:
- Dec 28, 2009, 12:24:59 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 3acab0e
- Parents:
- dc8f6e0
- git-author:
- Nelson Elhage <nelhage@mit.edu> (12/23/09 12:28:21)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (12/28/09 00:24:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
rac374fc r54b4a87 137 137 } 138 138 139 use constant OPTIONAL_CHANNEL => 1; 140 use constant REQUIRE_CHANNEL => 2; 139 =head2 mk_irc_command SUB FLAGS 140 141 Return a subroutine that can be bound as a an IRC command. The 142 subroutine will be called with arguments (COMMAND-NAME, 143 IRC-CONNECTION, [CHANNEL], ARGV...). 144 145 C<IRC-CONNECTION> and C<CHANNEL> will be inferred from arguments to 146 the command and the current message if appropriate. 147 148 The bitwise C<or> of zero or more C<FLAGS> can be passed in as a 149 second argument to alter the behavior of the returned commands: 150 151 =over 4 152 153 =item C<CHANNEL_ARG> 154 155 This command accepts the name of a channel. Pass in the C<CHANNEL> 156 argument listed above, and die if no channel argument can be found. 157 158 =item C<CHANNEL_OPTIONAL> 159 160 Pass the channel argument, but don't die if not present. Only relevant 161 with C<CHANNEL_ARG>. 162 163 =back 164 165 =cut 166 167 use constant CHANNEL_ARG => 1; 168 use constant CHANNEL_OPTIONAL => 2; 141 169 142 170 sub register_commands { … … 192 220 193 221 BarnOwl::new_command( 194 'irc-mode' => mk_irc_command( \&cmd_mode, OPTIONAL_CHANNEL),222 'irc-mode' => mk_irc_command( \&cmd_mode, CHANNEL_OPTIONAL|CHANNEL_ARG ), 195 223 { 196 224 summary => 'Change an IRC channel or user mode', … … 216 244 217 245 BarnOwl::new_command( 218 'irc-part' => mk_irc_command( \&cmd_part, REQUIRE_CHANNEL),246 'irc-part' => mk_irc_command( \&cmd_part, CHANNEL_ARG ), 219 247 { 220 248 summary => 'Leave an IRC channel', … … 241 269 242 270 BarnOwl::new_command( 243 'irc-names' => mk_irc_command( \&cmd_names, REQUIRE_CHANNEL),271 'irc-names' => mk_irc_command( \&cmd_names, CHANNEL_ARG ), 244 272 { 245 273 summary => 'View the list of users in a channel', … … 294 322 295 323 BarnOwl::new_command( 296 'irc-topic' => mk_irc_command( \&cmd_topic, REQUIRE_CHANNEL),324 'irc-topic' => mk_irc_command( \&cmd_topic, CHANNEL_ARG ), 297 325 { 298 326 summary => 'View or change the topic of an IRC channel', … … 547 575 sub mk_irc_command { 548 576 my $sub = shift; 549 my $ use_channel= shift || 0;577 my $flags = shift || 0; 550 578 return sub { 551 579 my $cmd = shift; … … 563 591 $conn = get_connection_by_alias($alias); 564 592 } 565 if($ use_channel) {593 if($flags & CHANNEL_ARG) { 566 594 $channel = $ARGV[0]; 567 595 if(defined($channel) && $channel =~ /^#/) { … … 577 605 } 578 606 579 if(!$channel && $use_channel == REQUIRE_CHANNEL) { 607 if(!$channel && 608 ($flags & CHANNEL_ARG) && 609 !($flags & CHANNEL_OPTIONAL)) { 580 610 die("Usage: $cmd <channel>\n"); 581 611 } … … 591 621 die("You must specify an IRC network using -a.\n"); 592 622 } 593 if($ use_channel) {623 if($flags & CHANNEL_ARG) { 594 624 $sub->($cmd, $conn, $channel, @ARGV); 595 625 } else {
Note: See TracChangeset
for help on using the changeset viewer.