Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use POE;
- use POE::Component::IRC;
- sub CHANNEL () { "#channel" }
- my ($irc) = POE::Component::IRC->spawn();
- POE::Session->create(
- inline_states => {
- _start => \&bot_start,
- irc_001 => \&on_connect,
- irc_public => \&on_public,
- },
- );
- sub bot_start {
- $irc->yield(register => "all");
- my $nick = 'BBBot';
- $irc->yield(
- connect => {
- Nick => $nick,
- Username => 'BBBot',
- Ircname => 'POE::Component::IRC test test test',
- Server => 'irc.freenode.net',
- Port => '6667',
- }
- );
- }
- # The bot has successfully connected to a server. Join a channel.
- sub on_connect {
- $irc->yield(join => CHANNEL);
- }
- sub on_public {
- my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
- my $nick = (split /!/, $who)[0];
- my $channel = $where->[0];
- my $ts = scalar localtime;
- print " [$ts] <$nick:$channel> $msg\n";
- if (my ($rot13) = $msg =~ /^rot13 (.+)/) {
- $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
- $irc->yield(privmsg => CHANNEL, $rot13);
- }
- elsif($msg =~ /!say /)
- {
- $irc->yield(privmsg => CHANNEL, "$'"); #was a test being silly
- }
- }
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement