Permalink
Browse files

Implemented the notice() method

- Added notice() with an example in the docs
- Added a notice()-related test in the testbot code
- Updated changelog file
  • Loading branch information...
cosimo committed Nov 15, 2010
1 parent 83a8de8 commit a1f13ac0983a1cbe64c5214248d3c49867b7cf42
Showing with 58 additions and 6 deletions.
  1. +2 −0 Changes
  2. +48 −2 lib/Bot/BasicBot.pm
  3. +1 −1 t/connect.t
  4. +7 −3 t/lib/TestBot.pm
View
@@ -3,6 +3,8 @@ Revision history Bot::BasicBot
{{$NEXT}}
- Ignore empty strings returned by said()
- Adjust the method documentation a bit to avoid confusion
+ - Added the notice() method to send IRC notices.
+ Useful when implementing bots.
0.83 Fri Nov 5 12:40:00 CET 2010
- Applied patch from Mario Domgörgen to use log() for warnings (RT #51804)
View
@@ -623,12 +623,17 @@ sub say {
# I think the Text::Wrap docs lie - it doesn't do anything special
# in list context
my @bodies = split(/\n+/, $wrapped);
-
+
+ # Allows to override the default "PRIVMSG". Used by notice()
+ my $irc_command = exists $args->{irc_command}
+ ? $args->{irc_command}
+ : 'privmsg';
+
# post an event that will send the message
for my $body (@bodies) {
my ($enc_who, $enc_body) = $self->charset_encode($who, $body);
#warn "$enc_who => $enc_body\n";
- $poe_kernel->post( $self->{IRCNAME}, 'privmsg', $enc_who, $enc_body );
+ $poe_kernel->post( $self->{IRCNAME}, $irc_command, $enc_who, $enc_body );
}
return;
@@ -680,6 +685,47 @@ sub emote {
return;
}
+=head2 notice
+
+C<notice> will send a IRC notice to the channel. This is typically used by bots
+to not break the IRC conversations flow. The message will appear as:
+
+ -nick- message here
+
+It takes the same arguments as C<say>, listed above. Example:
+
+ $bot->notice(
+ channel => '#bot_basicbot_test',
+ body => 'This is a notice'
+ );
+
+=cut
+
+sub notice {
+
+ if ( !ref( $_[0] ) ) {
+ print $_[0] . "\n";
+ return 1;
+ }
+
+ my $self = shift;
+ my $args;
+ if (ref($_[0])) {
+ $args = shift;
+ } else {
+ my %args = @_;
+ $args = \%args;
+ }
+
+ # Don't modify '$args' hashref in-place, or we might
+ # make all subsequent calls into notices
+ return $self->say(
+ %{ $args },
+ irc_command => 'notice'
+ );
+
+}
+
=head2 reply
Takes two arguments, a hashref containing information about an incoming
View
@@ -15,7 +15,7 @@ my $s = IO::Socket::INET->new(
if ($s) {
close($s);
- plan tests => 3;
+ plan tests => 4;
} else {
plan skip_all => "no net connection available";
exit;
View
@@ -8,17 +8,21 @@ sub connected {
my $self = shift;
ok(1, "connected");
is( $self->nick, "basicbot_$$", "right nick" );
-
}
# ..now wait for the first tick..
sub tick {
my $self = shift;
+ my $channel = [ $self->channels ]->[0];
+
ok(1, "tick");
- $self->say( channel => [ $self->channels ]->[0], body => "Hello $$" );
+ $self->say( channel => $channel, body => "Hello $$" );
+
+ ok(1, "now use a notice from within tick");
+ $self->notice( channel => $channel, body => "This should be a notice ($$)" );
+
exit;
}
-
1;

0 comments on commit a1f13ac

Please sign in to comment.