Skip to content

Commit

Permalink
Fixed BotAddressed POD. Added BotTraffic plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos committed Jul 5, 2005
1 parent cb12454 commit da5c0e6
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@
Revision history for Perl extension POE::Component::IRC.

4.64 Tue Jul 05 16:25:01 BST 2005
- Fixed POD in Plugin::BotAddressed.
- Added BotTraffic.pm plugin.

4.63 Thu Jun 16 21:55:49 BST 2005
- Fixed POD in BotAddressed and Connector plugins,
thanks integral @ MagNET for spotting that one.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -2,6 +2,7 @@ Changes
lib/POE/Component/IRC/Test/Harness.pm
lib/POE/Component/IRC/Test/Plugin.pm
lib/POE/Component/IRC/Plugin/BotAddressed.pm
lib/POE/Component/IRC/Plugin/BotTraffic.pm
lib/POE/Component/IRC/Plugin/Connector.pm
lib/POE/Component/IRC/Plugin/Whois.pm
lib/POE/Component/IRC/Qnet/State.pm
Expand Down
2 changes: 2 additions & 0 deletions META.yml
Expand Up @@ -8,6 +8,8 @@ requires:
Carp: 0
Date::Format: 0
POE: 0.0607
POE::Component::Client::DNS: 0.98
POE::Component::Client::Ident: 0.7
POE::Filter::IRCD: 0
Socket: 0

Expand Down
2 changes: 1 addition & 1 deletion lib/POE/Component/IRC.pm
Expand Up @@ -26,7 +26,7 @@ use vars qw($VERSION $REVISION $GOT_SSL $GOT_CLIENT_DNS);
# Load the plugin stuff
use POE::Component::IRC::Plugin qw( :ALL );

$VERSION = '4.63';
$VERSION = '4.64';
$REVISION = do {my@r=(q$Revision: 1.4 $=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};

# BINGOS: I have bundled up all the stuff that needs changing for inherited classes
Expand Down
4 changes: 2 additions & 2 deletions lib/POE/Component/IRC/Plugin/BotAddressed.pm
Expand Up @@ -80,8 +80,8 @@ No arguments required. Returns a plugin object suitable for feeding to L<POE::Co
Has the same parameters passed as 'irc_public'. ARG2 contains the message with the addressed nickname removed, ie.
Assuming that your bot is called LameBOT, and someone says 'LameBOT: dance for me', you will actually get 'dance for me'.
=back
=head1 AUTHOR
Chris 'BinGOs' Williams E<lt>chris@bingosnet.co.uk<gt>
96 changes: 96 additions & 0 deletions lib/POE/Component/IRC/Plugin/BotTraffic.pm
@@ -0,0 +1,96 @@
package POE::Component::IRC::Plugin::BotTraffic;

use POE::Component::IRC::Plugin qw( :ALL );
use POE::Filter::IRCD;

sub new {
return bless { @_[1..$#_] }, $_[0];
}

sub PCI_register {
my ($self,$irc) = splice @_, 0, 2;

$self->{filter} = POE::Filter::IRCD->new();
$irc->plugin_register( $self, 'USER', qw(privmsg) );
return 1;
}

sub PCI_unregister {
return 1;
}

sub U_privmsg {
my ($self,$irc) = splice @_, 0, 2;
my ($output) = ${ $_[0] };

my ($lines) = $self->{filter}->get([ $output ]);

foreach my $line ( @{ $lines } ) {
my ($text) = $line->{params}->[1];
next if ( $text =~ /^\001/ ); # Skip over CTCPs
foreach my $recipient ( split(/,/,$line->{params}->[0]) ) {
my $event = 'irc_msg';
$event = 'irc_bot_public' if ( $recipient =~ /^(\x23|\x26|\x2B)/ );
$irc->_send_event( $event => [ $recipient ] => $text );
}
}
return PCI_EAT_NONE;
}

1;

__END__
=head1 NAME
POE::Component::IRC::Plugin::BotTraffic - A POE::Component::IRC plugin that generates 'irc_bot_public' and 'irc_bot_msg' events whenever your bot sends privmsgs.
=head1 SYNOPSIS
use POE::Component::IRC::Plugin::BotTraffic;
$irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
sub irc_bot_public {
my ($kernel,$heap) = @_[KERNEL,HEAP];
my ($channel) = $_[ARG0]->[0];
my ($what) = $_[ARG1];
print "I said '$what' on channel $channel\n";
}
=head1 DESCRIPTION
POE::Component::IRC::Plugin::BotTraffic is a L<POE::Component::IRC|POE::Component::IRC> plugin. It watches for when your bot sends privmsgs to the server. If your bot sends a privmsg to a channel ( ie. the recipient is prefixed with '#', '&' or '+' ) it generates an 'irc_bot_public' event, otherwise it will generate an 'irc_bot_msg' event.
These events are useful for logging what your bot says.
=head1 METHODS
=over
=item new
No arguments required. Returns a plugin object suitable for feeding to L<POE::Component::IRC|POE::Component::IRC>'s plugin_add() method.
=back
=head1 OUTPUT
These are the events generated by the plugin. Both events have ARG0 set to an arrayref of recipients and ARG1 the text that was sent.
=over
=item irc_bot_public
ARG0 will be an arrayref of recipients. ARG1 will be the text sent.
=item irc_bot_msg
ARG0 will be an arrayref of recipients. ARG1 will be the text sent.
=back
=head1 AUTHOR
Chris 'BinGOs' Williams [chris@bingosnet.co.uk]

0 comments on commit da5c0e6

Please sign in to comment.